Skip to content

use-isnan

Reports a comparison with NaN (NaN or Number.NaN on either side of ==, !=, ===, !==, <, >…), and NaN as the switch discriminant or as a case test. isNaN(a) and Number.isNaN(a) are not reported.

NaN is not equal to any value, itself included, so a === NaN is always false and a !== NaN is always true; a switch on NaN never matches a case, because it compares with ===. The check never does what it reads like.

To fix, use Number.isNaN(a), which is true only for NaN; the global isNaN first converts its argument to a number.

Reported
if (a === NaN || NaN != a || a < Number.NaN || a === NaN2) {}
switch (NaN) { case NaN: break; case 1: }
...
js:
lint:
rules:
use-isnan: error # off, warn, error (default)

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line use-isnan in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint use-isnan partial the enforceForIndexOf option is not supported; a local NaN is not told from the global