SyntaxStudy
Sign Up
Home TypeScript Reference string / number / boolean

string / number / boolean

class TypeScript 1.0

TypeScript's three basic primitive types. Type annotations are optional when the value is obvious (type inference).

Syntax

let name: string = "Alice";

Example

javascript
let name: string    = 'Alice';
let age: number     = 28;
let active: boolean = true;
let nothing: null   = null;
let undef: undefined = undefined;

// Type inference (no annotation needed)
let city = 'London';   // inferred: string
let score = 95;        // inferred: number
let passed = true;     // inferred: boolean