Movatterモバイル変換


[0]ホーム

URL:


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 alwaysfalse for different types, so this comparison is not likely to be a programmer's intent.

Noncompliant Code ExampleCompliant Code Example
1const x = 10 / 3;1const x = 10 / 3;
2const b = x.toFixed(1) === 3.3; // COMPARE_INCOMPATIBLE_TYPE_STRICTLY alarm because 'toFixed' function returns string type.2const b = x.toFixed(1) === "3.3";

Noncompliant Code Example

View with compliant examples side by side
const x = 10 / 3;const b = 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
const x = 10 / 3;const b = x.toFixed(1) === "3.3";

Version

This rule was introduced in DeepScan 1.0.0-alpha.

Was this documentation helpful?

Last updated on April 29, 2025

[8]ページ先頭

©2009-2025 Movatter.jp