+ 1
Can anyone explain why the output is 5 pls
4 Antworten
+ 3
var x=5;
var y=-1;
z=x++ + ++y;
alert(z)
Thống Nguyễn not really
z = x++ + ++y is equivalent to z = 5 + 0
x is not incremented so = 5
y is incremented so = 0
+ 2
thanks alot guys i really appreciate it
+ 1
++x; //prefix
x++; //postfix
Prefix increments the value, and then proceeds with the expression.
Postfix evaluates the expression and then performs the incrementing.
So your math is:
z = x(still 5) + y(has been add 1 and now 0) = 5 + 0 =5.
then add 1 to x (x now 6)
+ 1
bahha thank you, i have mistake and i have fixed the answer!