
JavaScript Execution Context: What Actually Happens When You Hit "Run"?
If you’ve ever been baffled by hoisting , confused by this , or haunted by closures , you’re actually just missing one piece of the puzzle: The Execution Context (EC) . Stop thinking of your code as a flat list of instructions. Instead, think of it as a Series of Environments . 🏗️ 1. The "Big Picture": What is it? The Execution Context is the environment in which your code is evaluated and executed. Think of it as a "Container" that the JS Engine creates to store everything your code needs at that specific moment. It holds: Variables & Functions (Memory) The Scope Chain (Who are my neighbors?) The this Keyword (Who called me?) ⚡ 2. The Secret Lifecycle (The Two-Phase Rule) This is the most important part for beginners to grasp. The JS engine doesn't just "run" code; it pre-scans it first. Phase A: The Creation Phase (The "Setup") Before executing a single line, the engine: Allocates Memory: It finds var and function declarations. Hoisting: It sets var to undefined and stores the full f
Continue reading on Dev.to JavaScript
Opens in a new tab



