请问有人可以解释一下这个奇怪的JavaScript行为吗?
+
// Rightfully gets a syntax error, because there are no operands
+ +
// Same as above
+ + ''
// Interpreted as 0
typeof(+ + '')
// Interpreted as "number"
+ + '' === 0
// Interpreted as true
换句话说,(+ + '')计算结果为零。1)这在语法上是如何允许的?2)为什么会得出零的结果?
+
是一元加运算符,将某个值转换为数字。+""
等同于Number("")
,其结果为0
。 - Ian