Scopes

Let's learn about local variables and the scope of a variable.

Spheres of visibility

When we discussed variables, we mentioned that the most common type is the local variable. Now, we’ll explore these in detail.

Because we’ve discussed methods, we can look at another important concept: scopes.

According to Wikipedia, in programming, the scope of a name (such as a variable) is the part of a program where the name is valid: where the name can be used to refer to something else. (We’ve slightly modified this to match our own terminology.)

Remember: Names are known (defined) in a certain scope, and unknown (undefined) outside of this scope.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy