Please someone should help me explain the code below cos I don't understand how the result is 9 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please someone should help me explain the code below cos I don't understand how the result is 9

var X=3 X=++X+X++ alert(X); And the Answer is 9

18th Oct 2017, 3:06 PM
Patrick Idungafa
Patrick Idungafa - avatar
2 Answers
+ 7
x = 3 x=++x (x was 3, x is now 4) + x++ (x was 4, x is now 5) 4+5=9 note: the ++x/x++ operation changes the variable it's not the same as x+1
18th Oct 2017, 3:11 PM
Kamil
Kamil - avatar
+ 1
Thanks
18th Oct 2017, 3:14 PM
Patrick Idungafa
Patrick Idungafa - avatar