EXECUTION CONTEXT AND SCOPE
The concept of execution context, referred to as context for simplicity, is of the utmost importance in JavaScript. The execution context of a variable or function defines what other data it has access to, as well as how it should behave. Each execution context has an associated variable object upon which all of its defined variables and functions exist. This object is not accessible by code but is used behind the scenes to handle data.
The global execution context is the outermost one. Depending on the host environment for an ECMAScript implementation, the object representing this context may differ. In web browsers, the global context is said to be that of the window
object (discussed in the Browser Object Model chapter), so all global variables and functions defined with var
are created as properties and methods on the window
object. Declarations using let
and const
at the top level are not defined in the global context, but they are resolved identically...