Aju*_*ohn -1 javascript operators operator-precedence post-increment
我对输出有些困惑。用Java尝试
var x = 1;
x = x++;
console.log(x); //Its output is 1
Run Code Online (Sandbox Code Playgroud)
我当时认为应该是2.,因为我要在后期增加后进行打印。有什么看法吗?
这是正确的。分配首先进行,然后递增。比较:
var x = 1
var y = 1
x = x++
y = ++y
console.log(x, y)Run Code Online (Sandbox Code Playgroud)