What are JavaScript's primitive data types and how do they differ from objects?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
There are seven primitives — string, number, bigint, boolean, undefined, symbol, and null. Primitives are immutable and compared by value; objects are mutable and compared by reference.
Detailed explanation
typeof reveals most of them: 'string', 'number', 'bigint', 'boolean', 'undefined', 'symbol', 'object', plus 'function'. Two famous quirks live here: typeof null returns 'object' (a bug kept forever for backwards compatibility), and numbers follow the IEEE-754 double standard, so 0.1 + 0.2 !== 0.3. Primitives are immutable — every 'modification' creates a new value — and variables holding them store the value directly, so copies are independent. Objects (plain objects, arrays, dates, functions…) store a reference: assigning one variable to another copies the pointer, so mutations through either name affect the same underlying data. This value-vs-reference distinction explains most 'why did my array change?' bugs and drives techniques like spreading to clone before mutating state.
Example
typeof null; // 'object' (historical bug)
typeof function(){}; // 'function'
0.1 + 0.2; // 0.30000000000000004
let a = { n: 1 };
let b = a;
b.n = 2;
console.log(a.n); // 2 — same object, copied referenceInterview tip
List all seven primitives without pausing, then volunteer the typeof-null bug and floating-point quirk unprompted. Interviewers use this question to calibrate attention to detail.
Common mistakes
- Counting arrays or functions as separate primitive types — they are objects.
- Not knowing typeof null === 'object'.