There are generally two scope models:
Lexical scope implies that the scope is defined by author time decisions of where functions are declared.
Scope lookups for identifiers/variables begin at the inner-most scope and works its way outward the scope until finds the first match.
Some mechanisms like
eval (...) and
with can be used to ‘cheat’ lexical scope in such a way that lexical scope can be modified (or even created) at code runtime instead of the ‘ideal’ author-time.
eval(...) modifies an existing lexical scope at runtime while
with can create a whole new lexical scope at runtime.