const

 const声明常量,只读、值不能改变。

const PI = 3.1415;
 PI = 3;
// Uncaught TypeError: Assignment to constant variable.

 声明必须赋值 

 const PI
 //Uncaught SyntaxError: Missing initializer in const declaration

 有块级作用域

if (true) {
    const PI = 5;
}
PI // Uncaught ReferenceError: PI is not defined

 没有变量提升

if (true) {
  console.log(PI); //Uncaught ReferenceError: Cannot access 'PI' before initialization
  const PI = 3;
}

 不可重复声明

const a = 1;
const a = 2; // Uncaught SyntaxError: Identifier 'a' has already been declared

 

posted @ 2020-03-18 14:03  banzhuxiang  阅读(121)  评论(0)    收藏  举报