JavaScript Interview Question #73
What is the JavaScript call stack?
DOM, Events & Event Loop Fundamentals Mid-Level Intermediate
Quick Interview Answer
The call stack tracks active execution contexts for functions currently being executed. When a function is called, a frame is pushed onto the stack; when it returns, that frame is removed.
Detailed Explanation
The call stack tracks active execution contexts for functions currently being executed. When a function is called, a frame is pushed onto the stack; when it returns, that frame is removed.
JavaScript executes stack frames in last-in, first-out order. Deep uncontrolled recursion can exceed the available stack and cause a stack overflow.
Code Example
function first() {
second();
}
function second() {
console.log("Inside second");
}
first();
// first calls second; second returns, then first returns.