JavaScript Execution Context: Global and Function Contexts Explained

🧠 Ever wondered how JavaScript actually runs your code? Behind the scenes, JavaScript executes everything inside something called an Execution Context. Think of it as the environment where your code runs. 🔹 Types of Execution Context JavaScript mainly has two types: 1️⃣ Global Execution Context (GEC) Created when the JavaScript program starts. It: - Creates the global object - Sets the value of this - Stores global variables and functions - There is only one Global Execution Context. 2️⃣ Function Execution Context (FEC) Every time a function is called, JavaScript creates a new execution context. It handles: - Function parameters - Local variables - Inner functions Each function call gets its own context. 🔹 Two Phases of Execution Every execution context runs in two phases: 1️⃣ Memory Creation Phase JavaScript allocates memory for: - Variables - Functions (This is where hoisting happens) 2️⃣ Code Execution Phase Now JavaScript runs the code line by line and assigns values. 💡 Why This Matters Understanding execution context helps you understand: - Hoisting - Scope - Closures - Call Stack - Async JavaScript It’s one of the most important concepts in JavaScript. More deep JavaScript concepts coming soon 🚀 #JavaScript #ExecutionContext #Frontend #WebDevelopment #LearnJS #Programming #LearningInPublic

  • diagram

To view or add a comment, sign in

Explore content categories