There is code:
function search(list, q){
var result = {};
for(let id in list)(
(!q.id || (id == q.id)) &&
(!q.name || (list[id].name.search(q.name) > -1)) &&
result[id] = list[id]
);
return result;
}
I get this error:
Uncaught ReferenceError: Invalid left-hand side in assignment script.js:4
Why "&&" is wrong?
A single “=” sign instead of “==” or “===” is an Invalid assignment. Cause of the error: There may be a misunderstanding between the assignment operator and a comparison operator.
The "Assignment to constant variable" error occurs when trying to reassign or redeclare a variable declared using the const keyword. When a variable is declared using const , it can't be reassigned or redeclared.
The problem is that the assignment operator, =
, is a low-precedence operator, so it's being interpreted in a way you don't expect. If you put that last expression in parentheses, it works:
for(let id in list)(
(!q.id || (id == q.id)) &&
(!q.name || (list[id].name.search(q.name) > -1)) &&
(result[id] = list[id])
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With