JavaScript

JavaScript

Made by DeepSource

Comparisons found where both the sides are exactly the same JS-0089

Anti-pattern
Major

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. The only time you would compare a variable against itself is when you are testing for NaN. However, it is far more appropriate to use typeof x === 'number' && isNaN(x) or the Number.isNaN ES2015 function for that use case rather than leaving the reader to determine the intent of self comparison.

Bad Practice

const x = 10;
if (x === x) {
    x = 20;
}

Recommended

if (x == y) {
    x = y + 10
}