Call Stack and how Javascript code executed?
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.
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.
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.