Reading the book You-Don't-Know-JS and trying to understand the concept of this
.
this is actually a binding that is made when a function is invoked, and what it references is determined entirely by the call-site where the function is called.
And I came across the below code:
function a() {
function b() {
console.log(this.myVar);
}
var myVar = 2;
b();
}
var myVar = 1;
a();
The end result of the above code logged 1
which makes me wondering what is the call-site for the above code because clearly saw function b was being called inside function a and so I thought the expected value should be 2 instead of 1.