JavaScript Execution Context Simplified

🚀 How JavaScript Executes Your Code (Simply Explained) Ever wondered what really happens when JavaScript runs your code? Here’s a clean mental model that helped me connect Execution Context, Hoisting, Closures, and this 👇 🧠 JavaScript uses Execution Contexts to run code When a JS program starts: 1️⃣ Global Execution Context (GEC) is created Global memory is allocated this is initialized (window in browser) 2️⃣ Two phases happen in every execution context: 🔹 Memory Creation Phase var → undefined let / const → hoisted but uninitialized (TDZ) Function declarations → fully stored 👉 This explains Hoisting 🔹 Execution Phase Values are assigned Code runs line by line 3️⃣ Function calls create new Function Execution Contexts Each function gets its own execution environment Managed using the Call Stack (LIFO) 🔗 How concepts connect: Hoisting → Happens due to memory creation phase Closures → Inner functions remember their lexical execution context even after the outer function finishes this keyword → Decided when execution context is created Arrow functions → Don’t have their own this; they inherit it from lexical scope ✨ Key takeaway Execution Context is the foundation. Hoisting, Closures, and this are just outcomes of how it works. Currently diving deep into JavaScript fundamentals and loving how everything connects 🔥 Would love to hear how you explain this or if I missed anything! #JavaScript #WebDevelopment #Frontend #LearningInPublic #ExecutionContext #Closures #Hoisting #ThisKeyword #MERN

  • diagram

To view or add a comment, sign in

Explore content categories