What is the difference between primitive and reference types?
Quick answer
Primitives are copied by value and compared by value; objects are copied and compared by reference.
In detail
The 7 primitives (string, number, boolean, null, undefined, bigint, symbol) hold their value directly — assigning makes an independent copy. Objects (including arrays and functions) are held by reference, so two variables can point at the same object and equality compares identity, not contents.
let a = 1, b = a; b++; // a=1, b=2 (independent)
const o1 = {}, o2 = o1; // same reference
o2.x = 5; o1.x; // 5
({}) === ({}); // false — different referencesWhy interviewers ask this: Reference vs value is the root cause of countless real bugs.
Common follow-up questions
- →How do you compare two objects by value?
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299