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 ...
Get React: Building Modern Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.