Your First Program
Write and run a small typed program that prints output.
Syntax
console.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: stringsays this variable holds text.- Template literals with backticks let us insert values.
console.logsends output to the panel.
Example
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.
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.
npx tsc index.ts
node index.jsRun TS directly with ts-node
Uses ts-node to execute TypeScript without a manual compile step, ideal for quick scripts and REPL exploration.
npx ts-node index.ts
Discussion