+ 4
Why 0?
var x=1; for (var i = 0; i < 3; i++) { x*=i; } document.write(x)
7 Respuestas
+ 5
i = 0: x = 1 * 0;
i = 1: x = 0 * 1;
i = 2: x = 0 * 2;
i = 3: loop terminates
remember anything times 0 is 0
+ 10
1st iteration of the loop
i is 0, so x*=0 -> x is 0.
2nd iteration:
i is 1, x*=1 -> x is 0, because 0*1=0
+ 3
ok thx
+ 2
I can think when after for I need last number here it's 3
because after 3 loop break
+ 2
but here x*=i it's x =x *I
but my x =1 not 0
+ 1
yea but the first i in the for loop is 0
so x = x * i
x = 1 * 0
+ 1
oh good it's look into loop