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

: By lexical scope we mean that JavaScript’s rules for scoping are based purely on the structure of your code (not on some dynamic runtime properties). This means you can determine where a variable is defined by simply examining your code’s structure. Also remember that in JavaScript only functions introduce new scope. So, given a reference to a variable, look for where that variable is defined in a function from the most nested (where it’s used) to the least nested until you find it. And if you can’t find it in a function, then it must be global, or undefined.


Cover of Head First JavaScript Programming


How do you determine the scope of functions of variables?