Very simple question that struggles my mind. Here I have a function that calls another function
function fn2() {
console.log(myName);
}
function fn1() {
var myName = "John";
fn2();
return 15;
}
fn1();
From what I know so far, JavaScript creates a new execution context for each function invocation. So the order should be global execution context -> fn1 -> fn2. And when fn2 tries to access a variable that is not defines in its scope, it look in the scope chain to see if it is defined there. Since fn2 doesnt have local variable 'myName', it should check to see if it is defined it its outer scope, which is fn1 and the variable is indeed defined there. However when i run this code i receive an error that myName is not defined. Why is that the case.