What are the primitive data types in JavaScript, and how do primitives differ from objects (reference types) when you copy or compare them?
Show the explanation
Model answer. There are seven primitives: string, number, bigint, boolean, undefined, null and symbol. Everything else (plain objects, arrays, functions, dates, maps) is an object.
- Primitives are immutable and copied by value.
let b = acopies the value, so changingbnever affectsa. - Objects are copied by reference. The variable holds a reference, so two variables can point at the same object:
const a = { score: 1 };
const b = a;
b.score = 2;
console.log(a.score); // 2: same object- Comparison: primitives compare by value (
'hi' === 'hi'istrue); objects compare by identity ({} === {}isfalse, because they are two different objects).
This matters when passing values to functions: a function can mutate an object you pass in, but it can never change a primitive argument as the caller sees it.
Original UniCircle question. Last reviewed 22 Oct 2026.
