BeCuriouzBeCuriouz

Learn something new every day

🔷 TypeScript
🧱

The Seven Primitives: TypeScript's Building Blocks

💡 TypeScript has seven primitive types — string, number, boolean, null, undefined, symbol, and bigint — and their names are always written in lowercase.

In the last card you saw how TypeScript adds types on top of JavaScript. Now let's meet the smallest, most fundamental types you'll use every day: the primitives. A primitive is a simple, immutable value that isn't an object — TypeScript has seven of them: string, number, boolean, null, undefined, symbol, and bigint.

The three you'll reach for constantly are string (text like "hello"), number (any numeric value — 42, 3.14, even -0.5, all one type, no separate int/float), and boolean (true or false). Note the type names are lowercase: write string, not String. The capitalized versions refer to wrapper objects and are almost always a mistake.

ts
let name: string = "Ada";
let score: number = 99.5;
let isActive: boolean = true;

The other four are more specialized. null represents an intentional "no value," while undefined means a value was never assigned. bigint handles whole numbers too large for number (created with an n suffix, like 9007199254740993n), and symbol produces globally unique identifiers via Symbol(). You'll lean on the first three heavily and meet the rest as you go.

ts
let nothing: null = null;
let missing: undefined = undefined;
let huge: bigint = 100n;
let id: symbol = Symbol("id");
🧱 The Seven Primitives: TypeScript's Building Blocks — BeCuriouz