typescript / beginner
Snippet
Variable Type Annotations
TypeScript allows you to explicitly state the data type of a variable. This helps catch errors if you try to assign the wrong type of data later.
snippet.ts
1
2
3
let username: string = "Alice";const score: number = 100;let isActive: boolean = true;
Breakdown
1
let username: string = "Alice";
Declares a variable named 'username' that must always be a string.
2
const score: number = 100;
Declares a constant 'score' that must always be a number.
3
let isActive: boolean = true;
Declares a boolean variable that can only be true or false.