Module 7 · Functions, Scope and Storage Classes
Scope: Where a Name Lives
Free with an accountReading
Amara and David are writing Kenji's new game together. Amara's function counts the bonus levels, and David's counts the star levels. Both named their counter count.
Checking what this lesson needs for you…
What is inside Scope: Where a Name Lives
- Two functions, one name, no clash
- Block scope: a name lives inside its braces
- Lifetime: a local starts fresh on every call
- Shadowing: an inner name hides an outer one
- Global variables: visible everywhere, and that is the problem
- The honest global: a const