Why does “a + + b” work, but “a++b” doesn't?

后端 未结 7 944
感情败类
感情败类 2020-12-24 05:35

I was fiddling around with different things, like this

var a = 1, b = 2;
alert(a + - + - + - + - + - + - + - + b); //alerts -1

and I could

相关标签:
7条回答
  • 2020-12-24 06:29

    The answer is that ++ is an operator as well as +, and that + + is two + operators, not a ++ operator.

    Although it's not Javascript, C++ has similar fun with + and ++ operators. This was investigated in one of the Gurus of the Week from way back when.

    0 讨论(0)
提交回复
热议问题