Nullability
JavaScript has two different values used to represent "nothing": null and undefined.
Undefined
The value undefined roughly means "this value doesn't exist". Here are a few common places where you'll see it:
- A variable that isn't assigned a value
- The default return value of a function
- When accessing an unknown key of an object
Null
The value null is used for object non-existence. It roughly means, "there is no object here".
Conceptually, it's similar to the empty string for strings, or 0 for numbers.
In practice,
undefinedis often used for this same purpose.