0

var x=1; for(; x<10;x++){ x+=x;} document.write(x) Can someone explain how thisnequals 15, i'm super confused

Can someone explain how this comea to 15

8th Apr 2019, 6:51 AM
Matthew Stein
Matthew Stein - avatar
2 Antworten
+ 4
X = 1 Then, x = x + x = 2 X++... X will be 3. Similarly 3 + 3 = 6 X++ = 7 7 +7 = 14 X++ = 15 Now condition becomes false and hence the loop terminates !!!
8th Apr 2019, 7:13 AM
Arushi Singhania
Arushi Singhania - avatar
0
Thanks so much i get it now, i thought the var was seperate but wach rotation can change the variable
9th Apr 2019, 9:20 PM
Matthew Stein
Matthew Stein - avatar