Call Stack and how Javascript code executed?

Sanjana Human In Tech
2 min readOct 24, 2023

--

When we run the javascript code that is a lot of happening behind the javascript engine.
Javascript code runs in execution context.

What happens when the javascript code runs?

var number = 5; 
function add (number) {
var total = number + number;
return total;
}

var addNumber = add(number);
var addAnotherNumber= add(20);

Here, there are addNumber and addAnotherNumber invoking the add function.

Code execution

Here, the function invocation is done, and in memory, the variables and functions are initialized with undefined which is showcased in phase 1 and later when code execution happens the actual code output which is showcased in phase 2 will happen.

whole the global execution is done it is deleted.

Call Stack :

Call stack is like everytime global execution is created and added in call stack and and once the code execution done the global execution is pop-out.

Call Stack

every line of function invocation with argument execution happens execution push in the call stack and once the argument execution done it will be pop out. so at the end of the code whole call stack will be empty.

Thank you for reading this article! Don’t forget to clap 👏 .

If you have any queries related to ReactNative, I’m always happy to help you. You can reach me on LinkedIn and gmail.

Happy Learning🚀 Happy Coding💻.

--

--

Sanjana Human In Tech
Sanjana Human In Tech

Written by Sanjana Human In Tech

A React Native front-end enthusiast and dedicated development engineer, eager to expand knowledge on development techniques and collaborate with others.

No responses yet