Naming is one of the hard problems in programming
When we define a variable, we're giving a value a name. That name gives us enormous leverage. We can refer to that value later by name. We can refer to it multiple times. And the name itself gives meaning to our code. The number 36 is no longer just a figure. The String "Eric" is no longer just a sequence of characters. Because we can say:
(def age 36) (def first-name "Eric")
And we give lots of meaning to our code.
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 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.
Want this course?
Love it or leave it guarantee
If you don't learn as much from this course as you thought, just ask for a refund within 30 days and I'll give you your money back.
1. Global Scope
We explore global scope, also known as namespace scope, and how variables are defined.