1.变量声明let与const(注意与var的区别) /** * 声明变量let和const */ //let声明的变量不存在预解析 //报错 flag is not defined console.log(flag); let flag = 123; //let声明的变量不允许重复(在同一个作用域内) //报错Identifier 'flag' has already been declared let flag = 123; let flag = 456; console.log(flag)
let与var用法区别 //var var a = []; for (var i = 0; i < 10; i++) { a[i] = function () { console.log(i); }; } a[6](); // 10 ------------------------------ //let var a = []; for (let i = 0; i < 10; i++) { a[i] = function () { console.log(i); }; } a[6](); //
//var var a = []; for (var i = 0; i < 10; i++) { a[i] = function () { console.log(i); }; } a[6](); // 10 ------------------------------ //let var a = []; for (let i = 0; i < 10; i++) { a[i] = function () { console.log(i); }; } a[6](); // 6 ---------