I am reading “JavaScript: The Definitive Guide, 6th edition”, and in section “3.10.3 The Scope Chain” (page 55) it states –
“If we think of local variables as properties of some kind of
implementation-defined object, then there is another way to think about variable scope.”
Can someone explain what is meant by “implementation-defined object“?
Think of an abstract object that is not exposed to us. It’s defined by the implementation, and available to the implementation only – “implementation” meaning the JavaScript engine which will be running your code.
For example, consider the following function:
The variables and arguments defined within that function’s scope could be represented as an object that would look like this:
The values of the object’s properties can change during the execution of the function. If you call the function with
f(1,2), for example, the object will look like this as soon as the function execution starts:After
foois assigned5, it will look like this:Consider this object as if it was declared inside the function. So, you can access the values of
a,bandfooinside the function, but not outside it.