What Is the Call Stack in JavaScript?
The call stack is how JS tracks function calls. Here is what it does, how it overflows, and why it matters.
What Is the Call Stack in JavaScript?
The call stack is a LIFO data structure that the JavaScript engine uses to track active function calls. It is the core mechanism that makes code execution possible.
How It Works
- When a function is called, a stack frame is pushed onto the top of the stack.
- The frame holds the function's arguments, local variables, and the address to return to.
- When the function returns, the frame is popped.
- Only the frame on top is active. JS executes one function at a time.
A Walkthrough
function multiply(a, b) { return a * b; } function square(n) { return multiply(n, n); } function printSquare(n) { const result = square(n); console.log(result); } printSquare(5);
Stack at each step:
- GEC sits at the bottom.
printSquare(5)called, frame pushed.- Inside it,
square(5)called, frame pushed on top. - Inside it,
multiply(5, 5)called, frame pushed on top. multiplyreturns 25, frame popped.squarereturns 25, frame popped.printSquarelogs 25 and returns, frame popped.- Only GEC remains.
Stack Overflow
The stack has a finite size. If you recurse without a base case, frames pile up:
function infinite() { infinite(); } infinite(); // RangeError: Maximum call stack size exceeded
Why the Call Stack Matters
- It explains stack traces in errors (the trace is the stack at the time of the error).
- A blocking function (long loop) holds the stack, freezing the UI.
- The event loop can only push queued callbacks when the stack is empty.
The Takeaway
The call stack is a LIFO stack of function frames. Each call pushes a frame, each return pops one. One function runs at a time. Infinite recursion causes stack overflow. The stack must be empty for the event loop to schedule async callbacks.
A LIFO stack that tracks active function calls. Each call pushes a frame holding arguments, local variables, and the return address. Each return pops the frame. Only one function runs at a time.
Through infinite or very deep recursion. Each recursive call adds a frame without popping one until the engine's stack limit is exceeded, producing a RangeError.
No. JS is single-threaded with one call stack, so only the top frame executes. Other calls must wait for the current one to return.
A snapshot of the call stack at the moment the error was thrown. It shows the chain of function calls from the global context down to the failing line.
Because the event loop only moves callbacks from the queue onto the stack when the stack is empty. If a synchronous function is still running, queued callbacks wait.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

