ES6里变量规范
- 默认const
- 需要重新赋值时用let
- 尽量避免var
let
- 局部变量
- 可重新赋值
var name='let' //window.name的值会改变
//---------------------------
let name='let' //window.name不受影响
{
let a=1
console.log(a)
}
console.log(a);//Uncaught ReferenceError: a is not defined
const
const b=1
b=2;// Uncaught TypeError: Assignment to constant variable
const obj={a:1,b:2};
//obj={a:3,b:4} //Assignment to constant variable
//可修改属性
obj.a=111
obj.c=3;
//freeze后下面的修改不起作用
Object.freeze(obj)
obj.a=123
obj.d=444