What is the call stack?
Short answer
The call stack tracks which function is currently executing and what called it, growing with each function call and shrinking as functions return — a 'stack overflow' happens when it grows too deep, usually from unbounded recursion.
Advertisement
AModel answer
The call stack tracks which function is currently executing and what called it, growing with each function call and shrinking as functions return — a 'stack overflow' happens when it grows too deep, usually from unbounded recursion.
function a() { b(); }
function b() { c(); }
function c() { console.log('deepest'); }
a(); // stack: a -> b -> c, then unwindsReal-world example
Reading a stack trace in an error to see the exact chain of function calls that led to a crash.
Likely follow-ups
- What causes a 'Maximum call stack size exceeded' error?
Related topics