what is Scope

  • Scope is the code block where you can access the particular variable/function.

Lexical environment

  • Lexical environment of a execution context is it’s local memory + lexical environment of it’s parent.
Execution Context with lexical environment

what is Scope chain ?

  • when an execution context is created, a lexical environment is also created for this context.
  • when an identifier is not found in lexical environment, it tries to find it in it’s parent’s lexical environment.
  • it keeps finding until it either finds that identifier or it reaches global execution context’s lexical environment (which points to null)
  • this is known as scope chain.