Call → return10 / 19

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.

Call and return order

Let’s follow the changes to the top frame and the corresponding line of code.

function damage() { return 10; }function update() { return damage(); }function start() { return update(); }start();
CALL STACK · TOP AT THE TOP
scriptCurrently executing
OUTPUT—

The current script is ready to call start().

1 / 7
Key takeaway

A nested call runs before its calling function can continue.

Check the primary source ↗

ECMA-262 · Execution Contexts↗Execution contexts and their stack in the specification.