Stack vs Heap
Your program has two memory regions.
The Stack is fast, ordered, and small. It stores primitives (number, string, boolean, null, undefined, symbol, bigint). Their size is fixed, so the engine reserves the slot instantly.
The Heap is large and unordered. It stores objects, arrays, functions — anything whose size can grow. The Stack only keeps a small address (reference) pointing into the Heap.
// Primitives: copied by VALUE
let x = 10;
let y = x;
y = 20;
console.log(x); // 10 — x is untouched
// Objects: copied by REFERENCE (address)
const a = { n: 0 };
const b = a; // b gets a copy of the *address*, not the object
b.n = 5;
console.log(a.n); // 5 — same object in the HeapThis distinction is why React requires immutability: React compares addresses, not object contents.