CodeQL documentation

Comparison with NaN

ID: js/comparison-with-nan
Kind: problem
Severity: error
Precision: very-high
   - reliability
   - correctness
   - external/cwe/cwe-570
   - external/cwe/cwe-571
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

Arithmetic comparisons with the special not-a-number value NaN are useless: nothing is considered to be equal to NaN, not even NaN itself, and similarly nothing is considered greater or less than NaN.


Use the isNaN function from the standard library to determine whether a given value is NaN.


Instead of x === NaN, use isNaN(x).