Comparing NaN directly should be avoided

  • Error
  • Medium
  • No tags

This rule applies when NaN is directly compared.

In the JavaScript, direct comparison with NaN like x == NaN is always false.

Therefore, use isNaN function to determine whether a value is NaN.

Noncompliant Code Example

View with compliant examples side by side
if (x == NaN) {
    x = 0; // COMPARE_NAN alarm

Compliant Code Example

View with noncompliant examples side by side
if (isNaN(x)) {
    x = 0;


This rule was introduced in DeepScan 1.0.0-alpha.


Was this documentation helpful?