MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Execution Context & Call Stack Deep Dive0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
HomeTutorialsJavaScript for AdvancedExecution Context & Call Stack Deep Dive
Scope Chain & Lexical Environment

Execution Context & Call Stack Deep Dive

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

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.


1. What is an Execution Context?

An Execution Context (EC) is an abstract environment created by the JavaScript engine to evaluate and execute code. There are three types:

  1. 1
    Global Execution Context (GEC): Created once when the script loads. Sets up window (browser) or global (Node.js) and this.
  2. 2
    Function Execution Context (FEC): Created anew whenever a function is invoked.
  3. 3
    Eval Execution Context: Created by code evaluated inside eval() (rarely used).

2. The Two Phases of Execution Context

Every Execution Context is created in two distinct phases:

1 ┌──────────────────────────────────────────────┐
2 │ EXECUTION CONTEXT LIFECYCLE │
3 ├──────────────────────────────────────────────┤
4 │ 1. CREATION PHASE (Memory Allocation) │
5 │ • Hoisting: allocate variables/functions │
6 │ • var initialized as undefined │
7 │ • let/const registered in TDZ │
8 │ • Scope chain & 'this' determined │
9 ├──────────────────────────────────────────────┤
10 │ 2. EXECUTION PHASE (Line-by-Line Run) │
11 │ • Code executed sequentially │
12 │ • Values assigned to variables │
13 │ • Functions invoked (pushes new FEC) │
14 └──────────────────────────────────────────────┘

3. Hoisting & The Temporal Dead Zone (TDZ)

During the Creation Phase, declarations are registered in memory before code executes:

  • Function Declarations: Fully hoisted into memory. Can be called before their definition!
  • 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.
1console.log(myVar); // undefined (var is hoisted and initialized)
2// console.log(myLet); // ReferenceError: Cannot access 'myLet' before initialization (TDZ!)
3 
4var myVar = 10;
5let myLet = 20; // TDZ ends here for myLet!

4. The Call Stack (LIFO: Last In, First Out)

The Call Stack is the data structure that manages execution contexts during runtime:

1function alpha() {
2 beta();
3 console.log('alpha completed');
4}
5 
6function beta() {
7 gamma();
8 console.log('beta completed');
9}
10 
11function gamma() {
12 console.log('gamma executed');
13}
14 
15alpha();

5. Stack Overflow

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:

1function infiniteCrash() {
2 infiniteCrash(); // No base case!
3}
4infiniteCrash(); // Crash! Stack Overflow

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What are the two distinct phases every Execution Context undergoes?
Question 2
Why does calling a function declaration before its line of definition work in JavaScript?
Question 3
What is the "Temporal Dead Zone" (TDZ)?
Question 4
What data structure order does the JavaScript Call Stack follow?
Question 5
What error is thrown when recursive function calls exceed the Call Stack capacity?
Next Lesson

Scope Chain & Lexical Environment

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Memoization & Pure FunctionsScope Chain & Lexical Environment

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext