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?
代言2017-06-12 09:32:58
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.