0
Why is the variable b incremented?
It’s javascript var a = 2 var b = 3 var z = ++b alert(b)
2 odpowiedzi
+ 2
because your're first incrementing the value of b, and then setting it to z.
so, both b and z will be 4.
if you want b unchanged, do
var z = b + 1
0
Or use post incrementation instead of pre incrementation to slighlty modify the behaviour:
var b = 3;
var z = b++;
alert(b); // 4
alert(z); // 3