V7013. Suspicious assignment in the condition. A comparison may have been intended.
The analyzer has detected an assignment in a condition. The comparison operator was most likely intended instead of assignment.
The example:
function foo() {
let mode = ....;
if (mode = 1) { // <=
return;
}
....
}
The code contains a typo: instead of comparing the mode variable to one, a value is assigned. As a result, the condition is always true, and the code does not work as originally intended.
The fixed code:
if (mode == 1) {
....
}
In some cases, using an assignment inside a condition can shorten the code:
let result = ....;
while (result = exec()) {
....
}
Note. This approach is highly inadvisable because determining whether it is a typo or an attempt to shorten the code takes more time.
If the assignment is still required, it can be enclosed in parentheses:
while ((result = exec()))
....
The analyzer and many compilers/interpreters treat such code as safe. It also informs developers that the code is error-free.