Null and Undefined
Null and Undefined
π¨βπΌ You've handled missing data safely! This is a crucial skill in real-world
applications.
π¦ The key insight:
null and undefined represent two different kinds of
"missing" values:undefined- The value hasn't been set (default for uninitialized variables)null- The value was intentionally set to "nothing"
When you log them, both will display their values. Later, when we learn about
conditionals, you'll be able to check for these values and handle them
appropriately.
In practice, many developers prefer
null for intentional absence (like "user
hasn't set this yet") and let undefined represent truly missing values.