let、const都是ES6中新增長的特性,都表示塊級做用域,即它們只在最近的代碼塊中生效;markdown
const NUM = 1;
NUM = 0;//報錯
//可是若是聲明的是一個對象
const OBJ_STUDENT = {name:'aaa'};
OBJ_STUDENT.name = 'bbb';//不報錯
OBJ_STUDENT = {name:'ccc'};//報錯
複製代碼
console.log(x);//undefined
var x = '全局變量';
//可是let會報錯
console.log(x);//ReferenceError: x is not defined
let x = '全局變量';
複製代碼