ReferenceError: invalid assignment left-hand side
Message
ReferenceError: invalid assignment left-hand side
Error type
What went wrong?
Examples
js
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
在 if
语句中,你要使用比较运算符 ("=="),而在字符串连接中,使用加号运算符 ("+")。
js
if (Math.PI == 3 || Math.PI == 4) {
console.log("no way!");
}
var str = "Hello, " + "from the " + "other side!";