ReferenceError: invalid assignment left-hand side
Message
JavaScript
Copy Code
ReferenceError: invalid assignment left-hand side
Error type
What went wrong?
There was an unexpected assignment somewhere. This might be due to a mismatch of a assignment operator and a comparison operator, for example. While a single "=
" sign assigns a value to a variable, the "==
" or "===
" operators compare a value.
Examples
JavaScript
Copy Code
if (Math.PI = 3 || Math.PI = 4) { console.log('no way!'); } // ReferenceError: invalid assignment left-hand side var str = 'Hello, ' += 'is it me ' += 'you\'re looking for?'; // ReferenceError: invalid assignment left-hand side
In the if
statement, you want to use a comparison operator ("=="), and for the string concatenation, the plus ("+") operator is needed.
JavaScript
Copy Code
if (Math.PI == 3 || Math.PI == 4) { console.log('no way!'); } var str = 'Hello, ' + 'from the ' + 'other side!';
See also
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/javascript/reference/errors/invalid_assignment_left-hand_side