We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Message

ReferenceError: invalid assignment left-hand side

Error type

ReferenceError.

What went wrong?

有时会出现不可预料的赋值情况。这可能是因为赋值运算符比较运算符不匹配的缘故。正确的是,使用“=”号将值赋给一个变量,使用“==”或者“===”来比较一个值。

Examples

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 语句中,你要使用比较运算符("=="),而在字符串连接中,使用加号运算符("+")。

if (Math.PI == 3 || Math.PI == 4) { 
  console.log('no way!'); 
}

var str = 'Hello, ' 
+ 'from the ' 
+ 'other side!';

See also

文档标签和贡献者

此页面的贡献者: Ende93
最后编辑者: Ende93,