Chapter XII · Execution Context

Function Execution Context

A Function Execution Context (FEC) is created dynamically every time a function is invoked, establishing a local environment for its variables.

01 How It Works

Think of opening an isolated private meeting room whenever a specific task group convenes.

Each function call instantiates a new unique FEC containing its arguments, local variables, parameters, and parent lexical reference link.

example.js
function calculate(x) {
  let factor = 2;
  return x * factor;
}
calculate(10);
  1. 1. Function is invoked via parentheses.

  2. 2. New Function Execution Context is created and pushed onto the call stack.

  3. 3. Local parameters and variables are initialized during creation phase.

02 Practical Example

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

practical.js
function multiply(a, b) {
  const result = a * b; // Managed inside local FEC
  return result;
}
multiply(3, 4);

Key Takeaway

Every function call gets its own distinct execution context to manage local state.

Related Concepts