Why JavaScript Call Stack Comes into picture?

Why JavaScript Call Stack Comes into picture?

#javascriptdevelopers

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++.

#javascriptframework #opentowork #learningtechnologies

Kunal Jain

Gen AI Engineer | Software Engineer | Open Source Contributor ?? | Full Stack Developer ??| JavaScript developer ??| SQL ?? | React | Redux | NodeJS | MongoDB | TypeScript | Python

4 年

If anyone has any suggestions, you are welcome and if you have any opening let me know.

回复

要查看或添加评论,请登录

Kunal Jain的更多文章

  • JavaScript News

    JavaScript News

    JavaScript News & updates

  • Hoisting in JavaScript

    Hoisting in JavaScript

    Hoisting in #javascript It is the default behavior of JavaScript in the JavaScript compiler. var x = 7; function…

社区洞察

其他会员也浏览了