The stack tracks execution frames and quick local access, while the heap stores dynamically allocated objects, together forming the practical memory model behind JavaScript runtime behavior.
The call stack represents active execution contexts. Each function call pushes a frame, and returning pops it.
The heap is a larger memory region for objects, arrays, and functions that need dynamic lifetime management.
Variables in stack frames may hold primitives directly or references pointing into heap objects. This relationship explains identity, mutation, and garbage collection behavior.
The two regions differ in cost. Stack allocation is close to free because the engine only moves a pointer, and cleanup is automatic when the frame pops. Heap allocation has to find free space, and cleanup depends on the garbage collector deciding an object is no longer reachable.
They also differ in size. The stack is small and fixed, usually a few hundred thousand frames deep, which is why runaway recursion throws long before the heap is anywhere near full. The heap is large and grows on demand up to an engine limit.
Primitives like numbers, strings, and booleans behave as if they live in the frame itself, so copying one copies the value. Objects, arrays, and functions live in the heap, so copying a variable copies only the reference and both names point at the same object.
Interview framing: define Heap & Stack in one sentence, then explain one concrete runtime behavior and one common pitfall with a short code example.