TypeScript builds on JavaScript’s let
and const
keywords, adding optional static typing for variables.
let
for reassignable variables and const
for values that shouldn’t change.
: string
— for text values: number
— for numbers: boolean
— for true/false values: any
— disables type checking (use cautiously)If no explicit type is given, TypeScript infers it from the assigned value:
let city = "New York"; // inferred as string let score = 100; // inferred as number