TypeScript Types
Describe values before runtime.
TypeScript
function greet(name: string): string {
return `Hello, ${name}`;
}
console.log(greet("Ada"));Output
Hello, Ada
Explanation
Type annotations let the compiler check how values are used. TypeScript erases annotations when generating JavaScript.
Explore the dry run
Guided walkthroughReady
1
function greet(name: string): string {2
return `Hello, ${name}`;3
}4
console.log(greet("Ada"));Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| The type annotations are checked and removed during compilation. | — | — | |
| Call greet with Ada. | name = "Ada" | — | |
| Build and return the greeting string. | return = "Hello, Ada" | — | |
| Write the result. | return = "Hello, Ada" | Hello, Ada |