Comparing NaN directly should be avoided

  • COMPARE_NAN
  • 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

var x = undefined + 0;
if (x == NaN) {
    x = 0; // COMPARE_NAN alarm
}

Compliant Code Example

var x = undefined + 0;
if (isNaN(x)) {
    x = 0;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See