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.