Call Stack
The call stack is the engine's list of function frames that are currently running. The top frame is the function executing now; when it returns, the frame below resumes.
Detailed Explanation
JavaScript runs one piece of your code at a time on an agent. The call stack is how it keeps track of nested calls. Calling f() pushes a frame: locals, parameters, the return address. f calling g pushes another. g returning pops. When the stack is empty, the current task is done and the event loop can drain microtasks and take the next task.
A stack frame holds that function's bindings, not the heap objects those bindings point at. Those objects live on the heap and can outlive the frame (that is a closure). The frame itself is gone after return or throw that leaves the function.
throw unwinds the stack until a catch handles the error. Each frame can have a finally. The stack trace you see on an Error is a snapshot of the frames at throw time (plus async traces in some engines). Deep recursion prints a long trace and then RangeError: Maximum call stack size exceeded when the engine refuses another push. That limit is in the thousands of frames, implementation-defined.
The stack is not the task queue. setTimeout(fn, 0) does not push fn now. It schedules a task. fn will get its own empty-stack turn later. await pops the async function's frame from the current stack and resumes later as a microtask with a fresh stack that does not include the original caller (the caller already got a promise).
DevTools "call stack" panel is this structure. "Pause on exceptions" stops before unwind. Tail-call elimination, which would reuse a frame, is not something you can depend on in JavaScript engines.
What it costs you: depth. A recursive walk of a 50k-node chain overflows. An accidental infinite recursion (function f() { f(); }) overflows in milliseconds and freezes the tab until the engine throws. Long synchronous frames also block the event loop: a 200 ms stack that never returns means no paint and no click handlers.
Reach for this model when you read a stack trace, when you convert recursion to a loop, and when you explain why await "breaks" the stack. Reach for a heap-allocated explicit stack when depth is data-dependent and large.
Code Examples
function inner() {
throw new Error("boom");
}
function outer() {
inner();
}
try {
outer();
} catch (err) {
console.log(err.stack.split("\n").slice(0, 3).join("\n"));
// Error: boom
// at inner ...
// at outer ...
}function tooDeep(n) {
return tooDeep(n + 1);
}
try {
tooDeep(0);
} catch (err) {
console.log(err.name); // => RangeError
}function a() {
return b();
}
function b() {
return 1;
}
console.log(a()); // => 1 (stack: a, then a+b, then a, then empty)Common Gotchas
Infinite or huge recursion overflows the stack
the throw is `RangeError`, not a hang, but the tab is stuck until it throws.
`await` does not keep the caller on the stack
the async function continues later; `try/catch` around the original call already finished unless you `await`ed it.
Locals die with the frame; objects they referenced may not
a returned closure keeps the environment, not the frame.
One long frame blocks the event loop
there is no preemption inside a running function.