Categories
JavaScript Answers

How to Fix the ‘SyntaxError: test for equality (==) mistyped as assignment (=)? ‘ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘SyntaxError: test for equality (==) mistyped as assignment (=)?’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘SyntaxError: test for equality (==) mistyped as assignment (=)?’ when we’re developing JavaScript apps.

Fix the ‘SyntaxError: test for equality (==) mistyped as assignment (=)?’ When Developing JavaScript Apps

To fix the ‘SyntaxError: test for equality (==) mistyped as assignment (=)?’ when we’re developing JavaScript apps, we should make sure that we’re assigning variable values accidentally in the head of the if statement.

For instance, the following code will throw the error:

if (x = y) {
  // ...
}

since we have = instead of == or ===.

To fix this, we write:

if (x == y) {
  // ...
}

or

if (x === y) {
  // ...
}

Conclusion

To fix the ‘SyntaxError: test for equality (==) mistyped as assignment (=)?’ when we’re developing JavaScript apps, we should make sure that we’re assigning variable values accidentally in the head of the if statement.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *