+ 2
x=1 y=x + x++ alert(y);
Why the result is 2 ??
6 Answers
+ 9
When you do (x++), the value of x is returned before x is incremented. As a result, y = 2, x is incremented by 1, and then the value of y is printed.
+ 8
@Demi yeah if x++ then you can say that y=x+x;
for more information go through this post it will help you
https://www.sololearn.com/Discuss/407846/?ref=app
+ 7
x=1
y=x+x++ //let's break this line
y=1+1 //because x++ uses the value first then increments later. so...
y=1+1
y=2
+ 3
x is post incremented. That means it first use the current value and then it is incremented. Here y=1+1=2.
so alert(y) //outputs 2
Try alert(x) // outputs 2
Try alert(x+y) //output will be 4.
+ 1
so we can say that y=x+x++ is the same as y=x+x because the result in the end is the 2 in both
+ 1
ok thank you all