In programming, scope is the area where variables, functions, and other name bindings can be used. Most simply:
var outerVariable = "Behold, outer scope!"
function middleFunction() {
var middlingVariable = "Behold, middling scope!"
function innerFunction() {
var innerVariable = "Behold, inner scope!"
}
}
In the above instance:
outerVariablecan be accessed from anywheremiddlingVariablecan be accessed from withinmiddleFunction()or `innerFunction()innerVariablecan be accessed only from withininnerFunction
That is to say: outerVariable has global scope, middlingVariable is scoped to middleFunction, and innerVariable is scoped to InnerFunction.
In almost all languages, a variable can be accessed by any function/class inside the function/class its currently in, but not outside/above it
For more information, see CodeCademy’s Scope Module