Beginner JavaScript Interview QuestionsBeginnerComparison
JavaScript · Question 3
What is the difference between primitive values and objects in JavaScript?
Direct answer
Primitive values are immutable values copied by value, while objects are mutable structures whose variables hold references to the same underlying object.
The phrase “passed by reference” is often used loosely in interviews. A more precise explanation is that JavaScript always passes values. For objects, the value being copied is a reference to the object.
let a = 10; let b = a; b = 20; leaves a unchanged because the number value was copied. With const a = { count: 1 }; const b = a; b.count = 2;, both variables point to the same object, so reading a.count gives 2.