var a = []; for(var i = 0;i<10;i++){ a[i] = function(){ alert(i); } } var func = a[7]; func();
var a = []; for(let i = 0;i<10;i++){ a[i] = function(){ alert(i); } } var func = a[7]; func();
var arr= [1,2,3,4,5]; for(var i=0; i < arr.length;i++){ //something to do... } alert(i); //如果使用let,会报引用错误
console.log(str); var str = "111" //undefined // let str = "111"; //str is not defined
var tmp = 123; if(true){ tmp = "abc"; //tmp is not defined let tmp; //将声明的变量绑定到这个区域,不再受外部影响 }