Skip to main content

Command Palette

Search for a command to run...

What exactly is Call Stack in javascript?

Published
1 min read
A

B-Tech final year student. Frontend developer and a coding enthusiast. Trying to make some place for me in this Tech world.

So basically, Call stack is a mechanism used in javascript to keep the track of multiple function call. Call Stack uses STACK which means Last In First Out which means the element last inserted into the stack will be removed or pop out first. For example - A stack of trays in a cupboard.

stack example.jpg

Now inside javascript whenever a code is executed an execution context is created along with a call stack.

Screenshot (102).png

Screenshot (104).png Along this a Call Stack is created.# Screenshot (108) (1).png

Now, after this inside the call stack an element is inserted that is (GEC) Global Execution Context .

Screenshot (105) (1).png

The javascript engine will start executing the code one by one. And whenever a function is invoked a new local execution context is created. Screenshot (103).png

And the function is then added to the Call stack. Screenshot (107) (1).png

After the function execution is completed the local execution context will get deleted and the function be popped out from the stack. Once the complete code is executed the Global context gets deleted and it will also get popped out from the stack.

More from this blog

Alok Ranjan Singh's blog

7 posts