es6种for循环中let和var区别
Dora Doris 人气:0let和var区别:
1 for(var i=0;i<5;i++){ 2 setTimeout(()=>{ 3 console.log(i);//5个5 4 },100) 5 } 6 console.log(i);//5 7 console.log('=============') 8 9 for(let j=0;j<5;j++){ 10 setTimeout(()=>{ 11 console.log(j);//0,1,2,3,4 12 },100) 13 } 14 console.log(j);//报错 j is not defined;
加载全部内容