Skip to content

eslint/no-self-compare Pedantic ​

What it does ​

Disallow comparisons where both sides are exactly the same

Why is this bad? ​

Comparing a variable against itself is usually an error, either a typo or refactoring error. It is confusing to the reader and may potentially introduce a runtime error.

Example ​

Examples of incorrect code for this rule:

javascript
var x = 10;
if (x === x) {
  x = 20;
}

References ​

Released under the MIT License.