Technology Quote by Eric Freeman
““If you assign a new variable without using the var keyword, that variable will be global, even if you are first assigning it in a function.””
About This Quote
Source Book: Head First Java, 2003
Declaring a variable without a keyword makes it global, even when done inside a function.
In simple terms: Missing var makes a variable global.
Always declare variables with var/let/const.
Themes
Mood
Type
When to use this quote
- function definitions
- module scripts
- debugging
- code reviews
Key Concepts
Questions to Reflect On
- Do you always declare variables explicitly?
- How could a global variable affect other parts of your code?
Using globals can cause unexpected side effects and harder maintenance.