Strict equality should not be used for two values with different types
This rule applies when two values with different types are compared with strict equality.
Strict equality is alwaysfalse
for different types, so this comparison is not likely to be a programmer's intent.
Noncompliant Code Example | Compliant Code Example | ||
---|---|---|---|
1 | const x = 10 / 3; | 1 | const x = 10 / 3; |
2 | const b = x.toFixed(1) === 3.3; // COMPARE_INCOMPATIBLE_TYPE_STRICTLY alarm because 'toFixed' function returns string type. | 2 | const b = x.toFixed(1) === "3.3"; |
const x = 10 / 3;const b = x.toFixed(1) === 3.3; // COMPARE_INCOMPATIBLE_TYPE_STRICTLY alarm because 'toFixed' function returns string type.
const x = 10 / 3;const b = x.toFixed(1) === "3.3";
This rule was introduced in DeepScan 1.0.0-alpha.