Identifiers are accessible within the scope of the function body they are created in, or within the global scope.
A scope chain is a logical list of objects associated with an execution context and which indicates the order in which target objects are bound to identifiers.
When the flow of control enters an execution context, the scope chain is created and populated with an initial set of objects. What objects these are depends on the type of code being executed. The scope chain is destroyed on exit from the execution context. This means that factors that affect the construction and ordering of a scope chain may cause it to be created differently each time a particular execution context is entered.
Calling one function from within another builds an increasingly deep scope chain containing each function's identifiers as it builds.
During execution, the scope chain of an execution context is only affected by the presence of a with code block. If a with block is entered, the scope chain has the block added to the front of it. This is because variables may be local to the block and may override earlier defined variables during the name binding process. When the with block is left, the scope chain is bumped to remove the item at the front. This happens when the code exits normally, with a break or because of a continue statement.
This scope chain behaviour is different to that you may be used to with a procedural language where the scope is block structured.
The scoping rules allow for identifiers in the global pool to be overridden by identifiers in the local context that have the same name.
ECMA 262 edition 2 - section - 10.1.1
ECMA 262 edition 2 - section - 10.1.4
ECMA 262 edition 3 - section - 10.1.4