O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

If a function is nested way down many layers, how does the environment work then?

A:

A: We used a simplistic way of showing the environment to explain it, but you can think of each nested function as having its own little environment with its own variables. Then, what we do is create a chain of the environments of all the nested functions, from inner to outer.

So, when it comes to finding a variable in the environment, you start at the closest one...

From

Cover of Head First JavaScript Programming

Note

How nested functions look for the variables in their environment?