Hint
Creation phase (hoisting, this binding) then execution phase β pushed onto the call stack
An Execution Context (EC) is the environment in which JavaScript code evaluates and executes. Every function call creates a new EC pushed onto the call stack.
Phase 1 β Creation Phase:
var declarations β hoisted and set to undefinedlet/const β hoisted but placed in Temporal Dead ZonethisPhase 2 β Execution Phase: runs code line by line, assigns actual values.
function example() {
// Creation phase saw: var a β undefined, fn fully hoisted
console.log(a); // undefined (var hoisted)
console.log(fn()); // 'works!' (function declaration hoisted)
var a = 1;
function fn() { return 'works!'; }
console.log(a); // 1 (now assigned)
}
Types of EC: Global EC (one per program), Function EC (one per call), Eval EC (avoid).