JavaScript Execution Context

The Execution Context is the environment in which JavaScript code runs. It determines how code is interpreted and what data (variables, functions) it has access to at any point.

Two Phases of Execution Context

Phase 1: Memory Creation Phase Phase 2: Code Execution Phase

Types of Execution Context

Example Code

Use browser developer tools (F12) to step through the execution using the debugger.

                    
debugger;

fun1();

var userName = "Hey";
var age = 20;

function fun1() {
    const a = 20;
    const b = 30;
    const result = fun2(a, b);
    console.log("Result from fun2:", result);
}

function fun2(a, b) {
    return a + b;
}