(draft) JavaScript: essentials

by ilyavf

Lexical scope

Lexical scope of a function is statically defined by the function’s physical placement within the written source code. The outer lexical scope of any given function is defined by its ancestors in the lexical hierarchy.


Accessing variables outside of the immediate lexical scope creates a closure.


The global object has an associated execution context. Additionally every invocation of a function establishes and enters a new execution context. The execution context is the dynamic counterpart to the static lexical scope. Each execution context defines a VariableEnvironment which is a repository for variables declared by that context. (ES5 10.4, 10.5)

When a given execution context encounters a function definition in the code, a new function object is created with an internal property named [[scope]] (as in lexical scope) which references the current VariableEnvironment. (ES5 13.0-2)