Chapter XII · Execution Context

Creation Phase

The creation phase is the setup stage of an execution context before code execution begins, during which hoisting and memory allocation occur.

01 How It Works

Think of setting up desks, labeling name tags, and preparing attendance sheets before a meeting starts.

The engine scans the code for variable and function declarations, allocating memory space (setting var to undefined, and storing function declarations fully).

example.js
console.log(name); // undefined (due to creation phase hoisting)
var name = "Alice";
  1. 1. Engine initializes the scope chain and 'this' binding.

  2. 2. Function declarations are stored completely in memory.

  3. 3. Variables declared with var are initialized to undefined (let/const remain uninitialized in temporal dead zone).

02 Practical Example

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

practical.js
foo(); // Runs successfully because function declaration is stored in creation phase
function foo() {
  console.log("Hoisted successfully");
}

Key Takeaway

Hoisting is a direct result of the memory allocation steps performed during the execution context creation phase.

Related Concepts