Strict equality should not be used for two values with different types

  • COMPARE_INCOMPATIBLE_TYPE_STRICTLY
  • Error
  • Medium
  • No tags

This rule applies when two values with different types are compared with strict equality.

Strict equality is always false for different types, so this comparison is not likely to be a programmer's intent.

Noncompliant Code Example

View with compliant examples side by side
var x = 10 / 3;
x.toFixed(1) === 3.3; // COMPARE_INCOMPATIBLE_TYPE_STRICTLY alarm because 'toFixed' function returns string type.

Compliant Code Example

View with noncompliant examples side by side
var x = 10 / 3;
x.toFixed(1) === "3.3";

Version

This rule was introduced in DeepScan 1.0.0-alpha.