What exactly is Call Stack in javascript?

Table of contents

No heading

No headings in the article.

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.