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
View with compliant examples side by sideif (x == NaN) {
x = 0; // COMPARE_NAN alarm
}
Compliant Code Example
View with noncompliant examples side by sideif (isNaN(x)) {
x = 0;
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.