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.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
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