isNaN

isNaN(x)

Try it yourself:


isNaN(): detect invalid numeric results

isNaN(x) tests whether x is the special “not a number” value. NaN often results from undefined arithmetic, failed conversion, or invalid numerical input.

Use it as a guard

Check a result before continuing a calculation or rendering a chart. NaN tends to propagate through arithmetic, so early detection is clearer than debugging a later sum() or mean().

Related tests

isFinite() also rejects infinities. isNumeric() checks whether a value is numeric in the first place, and isInteger() narrows the accepted domain further. Use isZero() before division where zero is the issue.

Do not compare directly

NaN is not reliably identified with ordinary equality. Use this predicate rather than comparing a value to NaN.

All functions