const 用于声明 常量
1.一定要赋初始值
const A
会报 Missing initializer in const declaration(常量声明中缺少初始值设定项) 错误
2.一般常量使用大写(潜规则),小写也不会报错
const A = 100 const b = 200
3.常量的值不能修改
const A = 100 A = 200
会报 Assignment to constant variable.(Assignment to constant variable.赋值给常数变量) 的错误
4.块级作用域
{ const PLAYER = 'UZI' } console.log(PLAYER);
5.对于数组和对象的元素修改,不算做对常量的修改,不会报错
const TEAM = ['Lan','Kai','Jing'] TEAM.push('Yao')