Parsing something that isn't a number results in NaN. isNaN helps to detect those cases:
- parseInt("hello", 10) // NaN
- isNaN(parseInt("hello", 10)) // true
Division through zero results in Infinity:
- 1 / 0 // Infinity
Both NaN and Infinity are of type "number":
- typeof NaN // "number"
- typeof Infinity // "number"
Note that NaN compares in a strange way:
- NaN == NaN // false (!)
But:
- Infinity == Infinity // true