Javascript Call Stack

Notes:

JavaScript Call Stack :

Stack: Stack is a part of memory used to keep track of function calls.

when we call a function, that function is going to be pushed on top of the stack &
local variables of that function are created in the local scope

when a control exits a function it is going to be popped out of the stack &
the created local variables of that function are deleted from the local scope

Ex:
function h()
{
document.write(“h”,”<br/>”);
}
function g()
{
document.write(“g”,”<br/>”);
}
function f()
{
document.write(“f”,”<br/>”);
}
f();
g();
h();
Output:
f
g
h

Ex:
function square(x)
{
return x * x;
}
var rValue = square(3);
document.write(rValue);

Interview Questions: