+ 1

Can anyone explain why the output is 5 pls

https://code.sololearn.com/WQs80qte0ehM/?ref=app

10th Sep 2019, 12:20 PM
sayed mohamed
4 RĂ©ponses
+ 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
10th Sep 2019, 12:44 PM
Bahha┣
Bahha┣ - avatar
+ 2
thanks alot guys i really appreciate it
10th Sep 2019, 1:11 PM
sayed mohamed
+ 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)
10th Sep 2019, 12:35 PM
Thống Nguyễn
Thống Nguyễn - avatar
+ 1
bahha thank you, i have mistake and i have fixed the answer!
10th Sep 2019, 12:47 PM
Thống Nguyễn
Thống Nguyễn - avatar