首页 > 其他 > 详细

const

时间:2020-03-18 15:16:56      阅读:53      评论:0      收藏:0      [点我收藏+]

 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

 

const

原文:https://www.cnblogs.com/blogZhao/p/12517073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!