Why JavaScript Call Stack Comes into picture?

Forgetforget
2 min readMar 25, 2022

Everything is happening in #javascripts inside the global execution context, and when the JavaScript code compiler complies into two phase Memory Creation phase and Code Complication Phase.

1. Memory Creation Phase

Firstly JavaScript engine reserve the memory for different variable and function also. But the value of different variable is undefined at time of Memory Creation phase.

2. Code complication phase

Second phase code complication start then it assigned the value to the earlier created variable. and this how JavaScript executes the code. And value is changed from undefined to value assign in the code Section of JavaScript.

And if a variable invokes a function then an execution context is again created for that function just like global execution context but different is that for short memory time and memory.

And if the variable contains the function of the function then JavaScript, again and again, created execution context and this continues till the code complication is not completed.

And the big question arises how JavaScript maintains these multiple execution contexts for different variables or functions.

Now call stack comes into the picture which maintains the records of all the execution context. and if new execution is created then JavaScript complier push into a stack and if function execution is completed then JavaScript pop out of the stack.

Once all the code is completed global execution context also pops out from the stack or is deleted from the memory.

Other names of call stack are program stack, runtime stack, execution stack.

Different browsers using different JavaScript compiler like chrome uses v8 which is written in C++.

--

--