Chapter XII · Execution Context

Execution Context

An execution context is an abstract environment wrapper that tracks the evaluation and execution of JavaScript code.

01 How It Works

Think of an isolated sandbox room containing all tools, documents, and rules required for a specific task.

Every execution context contains three core properties: Lexical Environment, Variable Environment, and the 'this' binding value.

example.js
let globalVar = "Global";
function run() {
  let localVar = "Local";
  console.log(globalVar, localVar);
}
run();
  1. 1. Code evaluation triggers context creation.

  2. 2. Variable and function bindings are registered during creation phase.

  3. 3. Code statements are evaluated during execution phase.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
const obj = {
  id: 101,
  showContext() { console.log(this.id); }
};
obj.showContext();

Key Takeaway

Execution contexts manage variable accessibility, scope chains, and 'this' keyword references.

Related Concepts