capypad
0 day streak
typescript / beginner
Snippet

Type Annotations

Type annotations allow us to explicitly specify the type of a variable. This helps the compiler catch errors if we try to assign a value of the wrong type.

snippet.ts
typescript
1
2
3
let count: number = 10;
let message: string = "Hello TypeScript";
let isActive: boolean = true;
Breakdown
1
let count: number = 10;
Declares a variable 'count' that must always be a number.
2
let message: string = "Hello TypeScript";
Declares a variable 'message' that must always be a string.
3
let isActive: boolean = true;
Declares a variable 'isActive' that must always be a boolean (true or false).