Scope

determines the accessibility of identifiers and values in a particular section of your code

Scope

In

other
words...

Scope determines what your program has access to!

Example

/* GLOBAL SCOPE */

var city = 'Chicago';

function logCity () {
  /* Local Scope */

  var city = 'New York';

  console.log(city);
}

logCity();

Types of Scope

  • Global Scope
    • refers to the Global Object in the Global Execution context
  • Local Scope
    • It is created within a function's execution context and consists of:

    • All variables defined "locally". These variables are attached to the function's execution context's "Variable Object".

    • a reference to a `parent-scope`

Global Execution Context

Function Execution Context

Scope

By Scott D'Alessandro

Scope

  • 653