Scopes
This lesson briefs about the local variables and scope of a variable and their scope.
Spheres of visibility, like rooms in a house
When we talked about the variables we mentioned that the most common type of
variables is the "local variable"
, without explaining any further why they are
local. Local to what? Where? We’re finally ready to explain that more.
Since we have now talked about methods, we can also discuss another important concept: scopes.
According to Wikipedia…
Wikipedia says: "In programming, the scope of a name is the part of a program where the name is valid: where the name can be used to refer to something else." (slightly modified to match our own terminology)
💡
Names are known (or defined) in a certain scope, and unknown (or undefined) outside of this scope.
Every time there is a method call, and the flow of execution enters the method’s body, it enters a new scope, or “room”. Things that are “local” to this method’s scope (i.e. things that are “inside” of the ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy