+ 1

var x=1; for(var i=0;i<3;i++){ x*=i; } alert(x); //output= 0 //do u have any explanation?

17th Jun 2017, 1:58 AM
islam moheb
islam moheb - avatar
3 Antworten
+ 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
17th Jun 2017, 2:14 AM
LordHill
LordHill - avatar
+ 3
ya he is correct
17th Jun 2017, 2:37 AM
Nanda Balakrishnan