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
smallbore, suyulong15000971151, kisekiremi and Seauningsuyulong15000971151 and Slodezzmsuyulong15000971151suyulong15000971151suyulong15000971151suyulong15000971151suyulong15000971151suyulong15000971151 and wangmeijian
Activity
Genzhen commentedon Jun 22, 2020
答案
0 1 2
解析
使用
let
关键字声明变量i
:使用let
(和const
)关键字声明的变量是具有块作用域的(块是{}
之间的任何东西)。 在每次迭代期间,i
将被创建为一个新值,并且每个值都会存在于循环内的块级作用域。sweetliquid commentedon Nov 4, 2020
意义不大
Genzhen commentedon Nov 5, 2020
理论的储备还是需要的,不一定每个人都知道这点知识,像在没有 let 之前 这个for 循环还是经常出现在面试题中的
shiaofang commentedon Dec 30, 2020
学到了~谢谢
webyangpei commentedon Mar 3, 2021
for(var i = 0; i < 3; i++) { setTimeout(console.log(i)) } 这个结果是 0 1 2
EaVanCN commentedon May 24, 2021
也可以用IIFE创建一个新的作用域
for (var i = 0; i < 3; i++) {
(function(){
var j = i;
setTimeout(() => console.log(j), 1);
})()
}
//0 , 1 , 2
SnailOwO commentedon Nov 17, 2021
感觉这题应该改成,有几种方式让i 在这题的基础上输出0,1,2。这样会更好