Why is this an issue?

In JavaScript, there are two types of comparison operators: strict and non-strict.

It’s generally recommended to use strict operators in JavaScript to avoid unexpected results due to JavaScript’s type coercion. This is because non-strict operators can lead to some counter-intuitive results. For example, 0 == false would return true, which might not be the expected outcome.

function checkEqual(a, b) {
  if (a == b) { // Noncompliant: using non-strict equality '=='
    return "Equal";
  } else {
    return "Not equal";
  }
}

console.log(checkEqual(0, false)); // Output: "Equal"

You should use the strict equality and inequality operators to prevent type coercion, avoid unexpected outcomes when comparing values of different types, and provide more predictable results.

function checkEqual(a, b) {
  if (a === b) {
    return "Equal";
  } else {
    return "Not equal";
  }
}

console.log(checkEqual(0, false)); // Output: "Not equal

Exceptions

The rule does not report on these cases:

Resources

Documentation