0

Arithmetic Operation

Explain the difference between a++ & ++a, b++ & --b x = 1; y = x + x++; Alert(y) //Outputs 2 Why not 3???

11th Jan 2021, 4:22 AM
CHANDAN ROY
CHANDAN ROY - avatar
1 Answer
+ 6
x++ means Value of *x* will be incremented after using it. So y = x+x++; Can be considered similar to y = x + x; x = x + 1; Thus answer is 2 and not 3. for more information about pre and post increment, you can use the search bar.
11th Jan 2021, 4:25 AM
Arsenic
Arsenic - avatar