logo

Execution Phase

Explain creation and execution phases of the execution context and variable instantiation.

Short explanation

Execution has two phases: the creation (where declarations are registered) and the execution (where code runs and assignments happen). This model explains hoisting and TDZ behaviors.

Example

function f() {
  console.log(x); // undefined (var hoisted during creation)
  var x = 10;
}
f();

How JS handles it internally

During creation, engine sets up lexical bindings; during execution, it assigns and runs statements. Special behaviors for let/const are enforced in the creation phase with uninitialized bindings.

FAQ

Q: Is creation phase visible to developers?

A: Not directly, but its effects (hoisting and TDZ) are important for predicting runtime behavior.