
How JavaScript Works (Part 2) – Execution Context & Call Stack Explained in Simple Words
In Part 1, we explored how JavaScript runs under the hood and discussed the JavaScript engine and runtime environment. In this part, we’re going deeper. We will understand: What is Execution Context? What are the different phases and types of an Execution Context? What is the Call Stack? How functions are executed internally? And most importantly we’ll visualise everything with a simple code example. Let’s begin. What is an Execution Context in JavaScript? Whenever JavaScript runs your code, it creates a special environment called an Execution Context . Think of it as a container where JavaScript keeps everything needed to execute your code. Phases of Execution Context Each execution context goes through two phases: 1. Creation Phase (Memory Allocation Phase) Before executing your code, JavaScript: Scans the code Allocates memory for variables Stores function definitions in memory Important behavior: Variables declared with var are initialized with undefined Functions are stored entire
Continue reading on Dev.to Webdev
Opens in a new tab


