Code highlights logo

Learn

Scope

Scope

Think of scope in programming like the rules about who can see or use something in a game. Imagine you have a special toy that only you and your friends at your table can play with. That's like a variable with a "local scope" in programming — it can only be used in a small, specific part of the program.

Now, think about the playground rules at school. These are for everyone and no matter where you are at school, you know them. That's like a variable with a "global scope" in programming. These can be used by the whole program, just like the playground rules are for all kids at school.

As we learn more, we'll see why sometimes it's better to share your toys with just your table (local scope) or with everyone (global scope), and how to choose when programming.

Sign up to start coding

Already have an account?

Sign In

Course content