为什么javascript const关键字无法在数组中工作? [英] why javascript const keyword is not working in array?
本文介绍了为什么javascript const关键字无法在数组中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function home() {
const list = ['john', 'adele', 'hary']; list.push('tiger');
return list;
}
home() //["john", "adele", "hary", "tiger"]
push方法可用,并且list [0] ="abc"可用
push method is available and also, list[0] = "abc" is available
在JS中,const关键字不同于Java或CPP?
In JS, const keyword is different to Java or CPP??
推荐答案
文档指出:
- 常量不能通过重新分配来更改
- 常量不能重新声明
您没有重新分配价值,也没有重新声明,因此是合法的.
You are not reassign value and not redeclare, therefore it's legal.
这篇关于为什么javascript const关键字无法在数组中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文