Interview Question

Primitive vs non-primitive data types?

Primitives compare by value; objects have identity and mutable properties.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

Primitive values are direct language values; objects are collections of properties with identity. • Primitives are immutable values. • Objects can usually have properties changed after creation. • Two separate objects are not strictly equal even if their properties look the same.

Example

Code
console.log('a' === 'a');
console.log({ value: 1 } === { value: 1 });
Output
true
false

Quick Revision

Primitives compare by value; objects have identity and mutable properties.