Scope determines where and how identifiers (variable, function, class) are stored.
See also, same as : Language - Namespace (Scoping rule for name)
A scope can be nested inside another scope. If one scope is nested inside another, code inside the innermost scope can access variables from either scope.
Lexical scope rules say that code in one scope can access variables of either that scope or any scope outside of it.
- Lexical Scope - The most common
- Dynamic Scope (such as Bash scripting, some modes in Perl, etc.)
As the scope is generally dependent of the parse tree, scope are nested.
- global variables: are available everywhere
- member variables: are only available to members of a certain class
- instance variables: are only available to particular instances of a class