Hi I am having a little trouble understanding the execution context concept in javascript.
I have this simple code:
func a(){
b();
var c;
}
func b(){
var d;
}
a();
var d;
So first the global execution context will be put on the execution stack. In the creation phase of this context func a, func b, and var d will be put in memory. But var d will be set to undefined. Then it will get to the execution phase in this global execution context and invoke function a, which is the line a().
At a's creation phase it will put var c in mem and set its value to undefined and then a is run line by line until hits the line b().
Then b creates a new context on the execution stack and in its creation phase it will put var d in mem and set its value to undefined. Then when b is done running its line of code (var d) it will go back to finishing a because when the func b finishes its execution context will be popped of the stack so now current context is a.
Then var c was already created in memory in function a so now the execution context for func a will be popped off the stack and it will come to the last line, var d, but that was already declared in the execution phase in the global execution context.
The problem I have is that in the global execution context will the very last line (var d) be reached in the creation phase for this context or will it never reach since var d is after the function invocation a.
I am very sorry if this is confusing but it would be great help if anyone can help me! Thank you!
dand a localdin the functionb. Both of them will be reached and create two different variables.dinsidebhas nothing to do with thedthat's a global (other than that it shadows it withinb).