Scope

Scope Overview

  • Scope is the set of variables you have access to

  • As we learned in the beginning of this class, JavaScript reads from top to bottom

  • Sometimes, however, we declare variables inside functions (just like arguments), which aren’t accessible in other parts of our code; this is the concept of scope.

Types of Scope

  • A variables scope is determined primarily based on where is was declared

  • Variables declared inside a function are in local scope

  • Variables defined outside of a function are in the global scope

  • Each function when invoked creates a new scope

Details