What happens when you run javascript code?
First of all execution context is created.
It allocates memory to variable and it's value as undefined in the first phase and then any function if available it's entire code and then function calls as values of undefined .
Now in second phase comes the code execution. one by one the code will be executed.
now variables real values are assigned instead of undefined .
now it runs next code . and now if any function call is present it will now run them.
and again new execution context will be created for the function in the global execution context(the outer and first execution ) and same process with be done.
after completion execution context will be deleted.
call stack-:
the global execution context is pushed inside the call stack. now next ec will go to call stack and once this is done will be popped out. and control goes again gec and next ec will be pushed.
call stack maintains the order of execution of execution contexts .
Comments
Post a Comment