Comparisons that always evaluate to true or to false, logical expressions that either always or never short-circuit and comparisons to a newly constructed object should not be used.

Why is this an issue?

An expression that always produces the same result, regardless of the inputs, is unnecessary and likely indicates a programmer’s error. This can come from

This can also happen when you put an assignment in a logical sub-expression. While not strictly a bug, this practice is confusing and should be avoided.

How to fix it

Review the code around the issue to find out why the expression always produces the same result. Pay attention to the operator precedence, comparing objects of different types, and comparing objects by reference (not by value!).

Code examples

Noncompliant code example

!foo == null;
a + b ?? c;
x === [];
(foo=0) && bar;

Compliant solution

foo != null;
a + (b ?? c);
x.length === 0;