Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
Scope refers to the visibility and accessibility of variables, functions, and objects within a program. It determines where in the code these entities can be accessed and used.
Local scope is an area within a specific block or function where variables are defined and accessible. Variables declared inside this local scope cannot be accessed outside of it.
Global scope refers to the area outside of any blocks or functions where variables are defined. Variables declared in the global scope can be accessed from anywhere in the program.
Enclosing Scope: Enclosing scope refers to an outer scope that contains another inner scope. Inner scopes have access to variables defined in their enclosing scopes.