typescript / beginner
Snippet
Basic Type Annotations
Type annotations allow you to explicitly state what type of data a variable should hold, helping catch errors during development.
snippet.ts
1
2
3
let username: string = "Alice";let age: number = 30;let isActive: boolean = true;
Breakdown
1
let username: string = "Alice";
Declares a variable 'username' that must always be a string.
2
let age: number = 30;
Declares a variable 'age' that must always be a number.
3
let isActive: boolean = true;
Declares a variable 'isActive' that must always be a true/false value.