Skip to content

isNaNComparisons

Reports comparisons with NaN, which should use Number.isNaN() instead.

✅ This rule is included in the ts logical and logicalStrict presets.

In JavaScript, NaN (Not-a-Number) has a unique property: it is not equal to anything, including itself. This means that comparisons like x === NaN or x !== NaN always produce unexpected results - the equality check always returns false, and the inequality check always returns true.

To reliably check if a value is NaN, use Number.isNaN() instead.

AE53 (valuAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0N53)< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dvalue is N1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEconsB0isNotANumbAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53resuAE !=<= sp ansty="le--0:#82AAFF;--1:#3B61">B0N5<3;d ivclassNa="meco">AE53 (valuAsp ansty="le--0:#D6DEEB;--1:#403F">5sp><3 sp ansty="le--0:#82AAFF;--1:#3B61">B0N53)< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dcomparison resu1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
443F53 (Nu4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0i3F53(value<)) {divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dvalue is< NaN spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">3<);><}di vdivclass="Nameexpressive-">44AEco61B0isNotANu44AE< = ! spans="tyle--0:#D6DEEB;--1:#40">3F53Nu4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0i3F53(resu

This rule is not configurable.

There is no legitimate reason to compare directly with NaN. This rule should always be enabled to prevent subtle bugs.