1. 程式人生 > 其它 >ES6語法(一)-2.const常量

ES6語法(一)-2.const常量

const表示定義常量

常量的特性:

1.const賦值後不能被改變

2.const宣告時,需要賦值

3.const賦值的是物件,物件不能再被賦新值,但是物件內部的屬性可以改變

so,const的實質其實對應常量儲存的記憶體地址是否讓改變,const對應的常量則不允許改變記憶體地址

 1 <!--
 2 @author:invoker
 3 @project:project_lianxi
 4 @file: 02-const的使用.html
 5 @contact:invoker2021@126.com
 6 @descript:
 7 @Date:2021/7/1 10:42
 8 @version: html5
9 --> 10 11 <!DOCTYPE html> 12 <html lang="en"> 13 <head> 14 <meta charset="UTF-8"> 15 <title>02-const的使用</title> 16 </head> 17 <body> 18 <script> 19 // 1.const賦值後不能改變,相當於常量 20 const name = 'invoker' 21 name='kaer' 22 // 2.const在宣告時必須賦值 23
const nick 24 // 3.常量指向的物件不能改變,但是物件內部的屬性可以改變 25 const obj = { 26 name:'invoker', 27 skillCount:10, 28 age:1000 29 } 30 console.log(obj); 31 obj = {} 32 obj.name='虛空' 33 obj.age = 2000 34 obj.skill = 4 35 console.log(obj); 36 37 // const的實質其實變數儲存的記憶體地址是否讓改變,const則不允許改變 38 </script> 39
</body> 40 </html>