0
Using ; after for loop changes the output, why?
var x=1; for(var i=0; i<6; i++); { x+=i; } console.log(x); Output: 7 Otherwise the output is 16
3 Réponses
+ 1
Because when you use semicolon the content in the curly brackets is skipped => the loop runs, when i becomes 6 then the loop ends. The value of i which is printed is 6 + 1 = 7.
0
Cause x+=i Is not part of for loop
0
var x=1;
for(var i=0;i<6;i++);//here ends for loop last value of i is 6
x+=i;//x+=6. x=7