liveBook · Manning

Execution context stack

As explained in Secrets of the JavaScript Ninja, Second Edition

A stack-like runtime structure that records active execution contexts for nested calls and returns.

When JavaScript calls a function, it pauses the current execution context and puts a new one on the execution context stack, also called the call stack. When the function finishes, its context is removed and the caller resumes. The stack begins with the global execution context; only one piece of code executes at a time. section 5.3 section 5.7

Listing 5.5. The creation of execution contexts
  function skulk(ninja) {           #A
    report(ninja + " skulking");    #A
  }                                 #A

  function report(message) {        #B
    console.log(message);           #B
  }                                 #B

  skulk("Kuma");                    #C
  skulk("Yoshi");                   #C

Follow how skulk calls report, then how separate calls to skulk create their own execution contexts. section 5.3

How Secrets of the JavaScript Ninja, Second Edition covers it

How deep it goes
Defines stack behavior and traces nested calls through returns without detailing execution-context internals.
Examples
Traces skulk calling report, followed by separate skulk calls with Kuma and Yoshi.
What you can do after
Understand which execution context is active as function calls nest and return.
How it connects
Connects execution contexts with function calls, global code, and single-threaded execution.

Also explained in

Compare how 8 books explain execution context stack →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Second Edition. The section links point to the parts of the book it draws on.