JavaScript: Variable scope

Lexical scoping: in JavaScript, the scope of a variable is defined by its location within the source code (it is apparent lexically) and nested functions have access to variables declared in their outer scope.

http://www.w3schools.com/js/js_function_closures.asp says:

  • All functions have access to the global scope.
  • In fact, in JavaScript, all functions have access to the scope “above” them.
  • JavaScript supports nested functions. Nested functions have access to the scope “above” them.

Remember, a variable declared anywhere without the var keyword is global