Skip to content

Creation Phase

The Creation Phase (also called Memory Allocation Phase) is the first of two phases in every execution context. During this phase, JavaScript sets up memory space for variables and functions before any code is executed.

  1. Create the LexicalEnvironment (scope)
  2. Create the VariableEnvironment
  3. Set up the this binding
  4. Allocate memory for variables (initialized to undefined)
  5. Store function declarations (fully hoisted)
// What you write:
console.log(myVar); // undefined
var myVar = 10;
// Behind the scenes (creation phase):
// var myVar; → allocated, initialized to undefined
// Then execution phase runs:
// console.log(myVar); → undefined
// myVar = 10; → assigned
// During creation phase:
var a; // allocated, set to undefined
function greet() {} // fully stored in memory
let b; // allocated, NOT initialized (TDZ)
const c; // allocated, NOT initialized (TDZ)
// Global context: this = global object
console.log(this); // window (browser)
// Function context: this depends on how the function is called
function showThis() {
console.log(this);
}
  • Creation phase runs before any code executes
  • Variables with var are initialized to undefined
  • Function declarations are fully hoisted
  • let and const are allocated but not initialized
  • this binding is set up