Rewrite `=== NaN` ⇒ `isNaN`

JavaScript pattern

Convert comparisons to NaN (e.g., x == NaN) to use isNaN (e.g., isNaN(x)).

In JavaScript, NaN is a special value of Number type. It’s used to represent any of the not-a-number values represented by the double-precision 64-bit format as specified by the IEEE Standard for Binary Floating-Point Arithmetic.

NaN is unique in JavaScript by not being equal to anything, including itself, so it does not make sense to compare to it.


Apply with the Grit CLI
grit apply prefer_is_nan

Converts double equality check

BEFORE
if (foo == NaN) {
}
AFTER
if (isNaN(foo)) {
}

Converts triple equality check

BEFORE
if (foo === NaN) {
}
AFTER
if (isNaN(foo)) {
}

Converts double inequality check

BEFORE
if (foo != NaN) {
}
AFTER
if (!isNaN(foo)) {
}

Converts triple inequality check

BEFORE
if (foo !== NaN) {
}
AFTER
if (!isNaN(foo)) {
}

Doesn't convert assignments

JAVASCRIPT
var x = NaN;