To understand how JavaScript executes code, handles hoisting, resolves scopes, and maintains asynchronous call stacks, one must understand the internal mechanics of the Execution Context.
An Execution Context (EC) is an abstract environment created by the JavaScript engine to evaluate and execute code. There are three types:
window (browser) or global (Node.js) and this.eval() (rarely used).Every Execution Context is created in two distinct phases:
During the Creation Phase, declarations are registered in memory before code executes:
var: Hoisted and initialized with undefined.let and const: Hoisted but uninitialized. They enter the Temporal Dead Zone (TDZ) from the start of the block until their declaration line is executed.The Call Stack is the data structure that manages execution contexts during runtime:
If functions call each other recursively without a termination condition, the Call Stack exceeds its memory allocation limit, triggering a RangeError: Maximum call stack size exceeded:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Memoization & Pure Functions | Scope Chain & Lexical Environment |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.