Skip to main content

Command Palette

Search for a command to run...

How JavaScript Works(part 3):

Core Fundamentals (part 3):

Updated
1 min readView as Markdown
I

I am Front-end Developer working in JavaScript. I am using the framework React. I am new to blogging and writing articles. I want to share my knowledge in the easiest possible way.

Handling Execution Context (Call Stack)

It is very difficult for JS to manage execution context but it manages it very beautifully. It manages the execution context creation/deletion, and control through call stack.

Note: If you don't know what execution context is, I really suggest you to read my previous blogs about it.

How JavaScript Works(Part 1):

How JavaScript Works(Part 2)

Now back to our topic:

The call stack is sometimes known as runtime stack, control stack, and execution context stack. So call stack maintains the order of execution of the execution context.

Let's see how this is done through the diagram.

image.png Whenever a JS program is run its call stack is populated with Global Execution Context (GEC). Every time at the bottom of the call stack, we have GEC.

image.png

Now whenever a new function is invoked or a new execution context is created, that execution context is pushed into the stack.

image.png After the work of this execution context is done, this execution context from the call stack is popped out and control goes back to the Global execution context.

image.png

image.png

After the whole program is done, the Global execution context also pops out from call stack and the call stack again becomes empty.

image.png

More from this blog

Its Ismat Ullah's Blog

4 posts

I am a Front-end developer, currently practicing JavaScript and React. I am also working on React Native project. I want to share knowledge that I have learned in the easiest possible way.