Primitives are the simplest, most fundamental data types in TypeScript. They are immutable (cannot be changed) and passed by value in memory. **The 7 Primitive Types:** • string - Textual data ("hello", 'world', `template`) • number - All numeric values (integers, floats, Infinity, NaN) • boolean - true or false • null - Intentional absence of value • undefined - Variable declared but not assigned • symbol - Unique identifier (advanced) • bigint - Large integers beyond Number.MAX_SAFE_INTEGER **Key Characteristics:** ✓ Stored directly in the stack (fast access) ✓ Immutable - operations create new values ✓ Compared by value, not reference ✓ Cannot have properties (unlike objects) Prefer using strict null checks so null/undefined are explicit in your types.
let variableName: type = value;// ===== STRING =====
let username: string = "Alice";
let templateStr: string = `User: ${username}`;
// ===== NUMBER =====
let age: number = 25;
let hex: number = 0xFF;
// ===== BOOLEAN =====
let isActive: boolean = true;
// ===== NULL & UNDEFINED =====
let data: null = null; // Intentional empty
let value: undefined = undefined; // Not yet assigned
// ===== TYPE INFERENCE =====
let auto = "I'm a string!"; // inferred string
// ===== THE 'ANY' TRAP (AVOID) =====
let dangerous: any = "text";
dangerous = 42; // No error, defeats TS!
dangerous.nonExistent(); // Compiles, crashes at runtime
// ===== SAFER UNION =====
let safe: string | null = null;
let correct: number = Number.parseInt("42");Understanding Primitives & Basic Types is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.