+ 1
var x=1; for(var i=0;i<3;i++){ x*=i; } alert(x); //output= 0 //do u have any explanation?
3 Answers
+ 3
x is 1 but the first run multiplies x by 0 because the first run of the loop has i with a value of 0.. so x becomes 0.. then each time it runs it multiplys by x which is 0 so it remains 0. Anything * 0 = 0
+ 3
ya he is correct