Scope

Scope:
is a place where we are look for things

Couple question

  1. What are we looking for

Couple question

2. Which scope belongs to?

Execution context

Types of exuction

  • Global
  • Function
  • Eval

Execution stack

Creation phase

Lexical Environment

Lexical Components

  1. Environment Record

  2. Reference to the outer environment

Types of Lexical Environment

  1. Global

  2. Functional

Types of Environment Record

  1. Declarative

  2. Object

Variable Environment

Hoisting

Solution

  • Regular expression
  • Parser
Closure

 

closure?

What is

closure is able to access its lexical scope

function can reference variables outside of itself

Types of scope
var:
  function scoped
  undefined when accessing a variable before it's declared

let:
  block scoped
  ReferenceError when accessing a variable before it's declared

const:
  block scoped
  ReferenceError when accessing a variable before it's declared
  can't be reassigned
Tasks

Scope/Closure

By Khrystyna Landvytovych