JavaScript 修改常数
示例
声明变量const只能防止其值被新值替换。const对对象的内部状态没有任何限制。下例显示,const可以更改对象的属性值,甚至可以添加新的属性,因为分配给对象的对象person是修改的,但不能替换。
const person = {
name: "John"
};
console.log('The name of the person is', person.name);
person.name = "Steve";
console.log('The name of the person is', person.name);
person.surname = "Fox";
console.log('The name of the person is', person.name, 'and the surname is', person.surname);结果:
The name of the person is John The name of the person is Steve The name of the person is Steve and the surname is Fox
在此示例中,我们创建了名为的常量对象,person并重新分配了person.name属性并创建了新person.surname属性。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语