Scope (Definition)

The part of the script within which an identifier is reachable.

An identifier is scoped to be globally available everywhere or locally available only within a function block.

However, JavaScript allows identifier names in local contexts to override those in the global context.

This means that an identifier name can be reused within a function and the local value will be used in place of the global value. Other global variables not overridden will be accessed from the global pool.

Example code:

   // Declare a global value
   var myVariable = "Global Value";
   // Declare a local value inside a function body
   function local_scope()
   var myVariable = "Local Value";
   // Demonstrate the scope override local replacing global

See also:__parent__, Scope chain, Variable


Wrox Instant JavaScript - page - 27