js 中const 定义的值是否能更改
const定义的基本类型不能改变,但是定义的对象是可以通过修改对象属性等方法来改变的。
1.
const aa=true
aa=false
console.log(aa)
VM1089:2 Uncaught TypeError: Assignment to constant variable.
2.
const aaa=3
aaa=5
console.log(aaa)
VM1152:2 Uncaught TypeError: Assignment to constant variable.
3.
const aaaa='ss'
aaaa='dd'
console.log(aaaa)
VM1194:2 Uncaught TypeError: Assignment to constant variable.
4.
const aaaaa={aa:'dd'}
aaaaa={aa:'bb'}
console.log(aaaaa)
VM1257:2 Uncaught TypeError: Assignment to constant variable.
5.
const aaaaaa={aa:'dd'}
aaaaaa.aa='bb'
console.log(aaaaaa)
{aa: "bb"}