JavaScript Execution: Creation & Execution Phases Explained

🚀 Understanding How JavaScript Actually Runs Behind the Scenes Today in college, I learned something that completely changed how I look at JavaScript execution. We often write code like this: var x = 10, y = 20; function add(x, y) { var res = x + y; return res; } console.log(add(x, y)); But what actually happens inside the JavaScript Engine? Here’s the simplified breakdown: 🧠 Step 1: Creation Phase (Memory Phase) JS scans the entire code first Variables are allocated memory and initialized with undefined Functions are stored in memory with their complete body ⚙️ Step 2: Execution Phase (Code Phase) Code runs line by line Variables get actual values Function is invoked A new execution context is created The Call Stack manages everything Understanding: Execution Context Memory Creation Code Execution Call Stack …makes JavaScript feel much more logical instead of “magic”. The output is simple: 30 But the process behind it is powerful. 📚 Currently diving deeper into JavaScript fundamentals as part of my B.Tech journey. #JavaScript #WebDevelopment #Programming #LearningInPublic #ComputerScience #FrontendDevelopment

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories