React: Building Modern Web Applications
by Jonathan Hayward, Artemij Fedosejev, Narayan Prusty, Adam Horton, Ryan Vice, Ethan Holmes, Tom Bray
A note on values and NaN
All values can be used in Boolean context and tested for truthiness. The values undefined, null, '', 0, [], false, and NaN (Not a Number) are falsy and all the other values are truthy.
NaN in particular is a special case and it does not behave like other real numeric values. NaN is toxic; any calculation that includes NaN will give a result of NaN. Furthermore, although NaN is falsy, it does not equal anything, including NaN itself. The usual way of checking for NaN is via the isNaN() function. If you find NaN lurking somewhere unexpected, you might give debugging log statements for code, leading to where you detected NaN; there may be some distance between where NaN was first generated and where you observed it corrupting ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access