You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// for 循环的基本操作, 打印 0 1
for(var i = 0; i < 2; i++) {
console.log(i) // 0 1
}
Question 2
// 在 for 循环中 只有一个 i, 由于异步, 所以先 for 循环 ok, 再打印 2 2
for(var i = 0; i < 2; i++) {
setTimeout(() => {
console.log(i) // 2 2
})
}
Question 3
for(let i = 0; i < 2; i++) {
setTimeout(() => {
console.log(i) // 0 1
})
}
/**
* ES6 中的 let 使 for 循环几次有几个 i
* 进入循环 复制变量 let = i ==> let i = _i 相当于一个快照
* for( let i = 0; let i = _i; i < 2; i++), 在括号中完成了变量 i
*/
Question 4
// 2333 后打印 0
for(
// 单独的作用域, 只代表 i 的初始值
let i = (setTimeout( ()=> console.log(i), 2333), 0); // 0
// 第二部分 声明 一个新的 i
i < 2;
i++
) {
console.log(i) // 0 1
}
The text was updated successfully, but these errors were encountered:
Question 1
Question 2
Question 3
Question 4
The text was updated successfully, but these errors were encountered: