Call Stack: which function is running
Pushing and popping stack frames in the correct order.
When start() calls update(), execution of start() waits for the return. When update() calls damage(), the active function becomes damage(). On return, control moves back in the opposite order.
function damage() { return 10; }
function update() { return damage(); }
function start() { return update(); }
start();
This is the LIFO: last in, first out principle. The stack records where execution should continue after a nested call. The ECMA-262 specification defines a stack of execution contexts; V8’s actual machine-level frames may differ because of inlining and other optimizations.
In the simulation script represents the base of the running script in this diagram. The “Next action” button traces changes to the top frame. The diagram shows the logical order of calls, rather than a native stack dump.
If a synchronous call takes a long time to return, another JavaScript callback on the same thread cannot interrupt it on its own.