Skip to content

eslint/no-cond-assign Correctness

This rule is turned on by default.

What it does

Disallow assignment operators in conditional expressions

Why is this bad?

In conditional statements, it is very easy to mistype a comparison operator (such as ==) as an assignment operator (such as =).

There are valid reasons to use assignment operators in conditional statements. However, it can be difficult to tell whether a specific assignment was intentional.

Example

js
// Check the user's job title
if ((user.jobTitle = "manager")) {
  // user.jobTitle is now incorrect
}

References

Released under the MIT License.