blog,blog,blog
blog,blog,blog有趣的javascript for代码
Q1
for(var i = 0 ; i < 2; i++ ){
console.log(i);
}
Q2
for(var i = 0; i < 2; i++ ){
setTimeout(() => console.log(i));
}
Q3
for(let i = 0; i < 2; i++ ){
setTimeout(() => console.log(i));
}
Q4
for(let i = 0; i < 2; i++ ){
setTimeout(() => console.log(i));
i++;
}
Q5
for(
let i = (setTimeout(()=>console.log(i)),0);
i < 2;
i++
){
i++;
}
A1:
0
1
A2:
2
2
A3:
0
1
A4:
1
A5:
0