I have been fiddling around with some piece of Javascript and I find console logs 1 for below code, However I was expecting 2, as it is 'a' which created b.
function b(){      
   c();
    function c(){            
        d();
        function d(){
             console.log(myVar);
        }
    }
}
function a(){
    var myVar=2;
    b();
}
var myVar=1;
a();
But again I see b sits in lexical environment of window so it is getting the value from there. So how does scope chain work?Does it take value from caller/ creator or lexical scope?
