What is lexical scope?
id:56
Lexical scope is the definition area of an expression. ie the place in which the item was created. The place an item gets invoked, or called, is not necessarily the items lexical scope. Instead an items definition space is its lexical scope.
Lexical scope refers to setting the scope, or range of functionality, of a variable.
Lexical scope means that in a nested group of functions, the inner functions have access to the variables and other resources of their parent scope. This means that the child functions are lexically bound to the execution context of their parents. Every time the javascript engine creates an execution context to execute the function, or global code, it also creates a new lexical environment to store the variables defined in that function during the execution of that function.
In lexical scope a child can access its parent scope and global scope, but a parent cannot access the child scope.
CODE>>BLOCK>>FUNCTION>>GLOBAL
Lexical scope does not care where the function is invoked.