Scope
PronunciationSKOHP
Definition
The part of the code where a variable can be seen and used. A variable declared inside a function is usually invisible outside it.
Where you hear it
Debugging "x is not defined" errors and explaining how closures work.
Examples
The variable is out of scope after the loop ends.
Keep the scope as small as possible.
The helper variable is in scope only inside the if block.
Common mistake
Confusing it with "scope" in project management (scope creep). Same word, different meaning: context decides.
Don't confuse with
Scope is often confused with context; while scope refers to the visibility and accessibility of variables in code, context refers to the object that a function is currently executing within.
Say it at work
- In a meeting or chat
I'm getting a reference error because that variable is out of scope inside this callback function.
- In an email or ticket
Please ensure that we limit the scope of these temporary variables to the block where they are actually needed.
Keep exploring
More in Programming Fundamentals