+ 2

Could someone explain me how this code works line to line? Thanks.

var x=1; for(x;x<10;x++){} x+=x+100; document.write(x);

26th May 2018, 3:58 PM
Rastislav Romanec
Rastislav Romanec - avatar
1 Answer
+ 3
The for loop will increase the value of x by 1 each iteration of the loop exiting the loop when x<10 is false. So, when x is equal to 10 the condition will be false, meaning the value of x will be 10 when the loop ends. x+=x+100 is the same as x = x + (x + 100) x = 10 + (10 + 100)
26th May 2018, 4:12 PM
ChaoticDawg
ChaoticDawg - avatar