javascript - js for loop
怪我咯
怪我咯 2017-06-12 09:30:58
0
1
520

for (var i = 0;i<10;i ){

function aa(){
    console.log(i)
}

}
aa()//10

Why is 10 printed here?

for (var i = 0;i<10;i ){

console.log(i)

}
What will be printed out is 9?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
代言

First case: After the loop ends, the value of i is 10, aa()outputs the value of i, so print 10. For example:

for (var j = 0; j < 10; j++) {}
console.log(j);         // print 10

Second case: i is printed in the loop, so in order to make the judgment condition successful, print 0 to 9.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template