Variables and scope

We use a lot of variables in code and a lot of names. We need rules for how they work—especially when they conflict. We want those rules to make our lives easier. We don't want to accidentally refer to the wrong variable or to unexpectedly have it change the meaning.

That's what the scoping rules are all about. They tell us what each variable in our code refers to, even when there are duplicate names. If we master these rules, we can be confident that our code will do what we mean. And we can make the choices that are right for our new code.