Your First Program

Write and run a small typed program that prints output.

Syntaxconsole.log(`Hello, ${name}!`);

Let's write a tiny program. We declare a typed variable, build a greeting, and print it. Notice how the code looks like JavaScript — the only new part is the type annotation after the colon.

Reading the code

  • name: string says this variable holds text.
  • Template literals with backticks let us insert values.
  • console.log sends output to the panel.

Example

Try it yourself
Loading editor…
Press Run to execute the code.

When to use it

  • A bootcamp student writes their first typed function to see how TypeScript errors appear in their editor.
  • A JavaScript developer migrates a small utility script to TypeScript as a low-risk first step.
  • A workshop instructor uses a hello-world program to introduce the compilation workflow before covering advanced types.

More examples

Typed hello-world function

A minimal typed function that takes a string parameter and returns a string, demonstrating basic annotation syntax.

Example · ts
function greet(name: string): string {
  return `Hello, ${name}!`;
}

console.log(greet('TypeScript'));

Compile and run the program

Shows the two-step workflow: compile the .ts file to JavaScript, then run it with Node.

Example · bash
npx tsc index.ts
node index.js

Run TS directly with ts-node

Uses ts-node to execute TypeScript without a manual compile step, ideal for quick scripts and REPL exploration.

Example · bash
npx ts-node index.ts

Discussion

  • Be the first to comment on this lesson.