1.const声明一个只读常量,一旦声明,常量的值就不能改变

1 const PI=3.1415;
2 console.log(PI);//3.1415
3 
4 PI=3;//Uncaught TypeError: Assignment to constant variable.

2.const一旦声明常量,就必须立即初始化,不能留到以后赋值

1 const WIDTH;//Uncaught SyntaxError: Missing initializer in const declaration

3.const声明的常量只在当前作用域内有效

1 if(true){
2   const NAME='XG'
3 }
4 
5 console.log(NAME);//Uncaught ReferenceError: NAME is not defined

4.const声明的常量不存在“声明提前”,只能先声明后使用

1 if(true){
2   console.log(NAME);//Uncaught ReferenceError: NAME is not defined
3   const NAME='XG';
4 }

5.const不可重复声明

6.const声明的常量如果保存的是引用类型的数据,只会保证该数据的地址不变,并不能保证该数据不变

感兴趣的朋友可以相互交流

转载自:http://www.cnblogs.com/xgblogs/p/6142792.html

1.const声明一个只读常量,一旦声明,常量的值就不能改变

1 const PI=3.1415;
2 console.log(PI);//3.1415
3 
4 PI=3;//Uncaught TypeError: Assignment to constant variable.

2.const一旦声明常量,就必须立即初始化,不能留到以后赋值

1 const WIDTH;//Uncaught SyntaxError: Missing initializer in const declaration

3.const声明的常量只在当前作用域内有效

1 if(true){
2   const NAME='XG'
3 }
4 
5 console.log(NAME);//Uncaught ReferenceError: NAME is not defined

4.const声明的常量不存在“声明提前”,只能先声明后使用

1 if(true){
2   console.log(NAME);//Uncaught ReferenceError: NAME is not defined
3   const NAME='XG';
4 }

5.const不可重复声明

6.const声明的常量如果保存的是引用类型的数据,只会保证该数据的地址不变,并不能保证该数据不变

感兴趣的朋友可以相互交流

转载自:http://www.cnblogs.com/xgblogs/p/6142792.html

1 const PI=3.1415;
2 console.log(PI);//3.1415
3 
4 PI=3;//Uncaught TypeError: Assignment to constant variable.

2.const一旦声明常量,就必须立即初始化,不能留到以后赋值

1 const WIDTH;//Uncaught SyntaxError: Missing initializer in const declaration

3.const声明的常量只在当前作用域内有效

1 if(true){
2   const NAME='XG'
3 }
4 
5 console.log(NAME);//Uncaught ReferenceError: NAME is not defined

4.const声明的常量不存在“声明提前”,只能先声明后使用

1 if(true){
2   console.log(NAME);//Uncaught ReferenceError: NAME is not defined
3   const NAME='XG';
4 }

5.const不可重复声明

6.const声明的常量如果保存的是引用类型的数据,只会保证该数据的地址不变,并不能保证该数据不变

感兴趣的朋友可以相互交流

转载自:http://www.cnblogs.com/xgblogs/p/6142792.html

相关文章:

  • 2021-07-26
  • 2022-12-23
  • 2021-09-14
  • 2021-08-19
  • 2022-12-23
  • 2021-09-05
  • 2021-09-19
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
相关资源
相似解决方案