The Call Stack
See how function calls are tracked.
What Is the Call Stack?
The call stack is how JavaScript tracks which function is currently running and what to return to. Every function call is pushed on top; when it finishes, it is popped off.
It is a LIFO structure: Last In, First Out.
Pushing and Popping
When you call a function, a stack frame is pushed. When it returns, the frame is popped. Watch the order of logs as calls nest.
function first() {
console.log('first start');
second();
console.log('first end');
}
function second() {
console.log('second');
}
first();