为什么全局变量'name'更改为字符串? [英] Why global variable 'name' changes to string?
本文介绍了为什么全局变量'name'更改为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我创建名为name的数组对象时,键入自动更改为String,而不是Array。为什么?
When I make array object named "name", type automatically changes to "String", not "Array". Why?
<body>
<script>
console.log('---------------------------------');
var name1 = ['abc', 'def'];
console.log(name1);
console.log(typeof name1);
console.log('---------------------------------');
var name = ['ghi', 'jkl'];
console.log(name);
console.log(typeof name);
</script>
</body>
Chrome(Mac)中的结果:
Result in Chrome(Mac):
---------------------------------
["abc", "def"]
object
---------------------------------
ghi,jkl
string // <- Why?
推荐答案
https://developer.mozilla.org/en-US/docs/Web/API/Window.name
这是一个字符串,因为 window.name
有一个目的。您正在设置窗口的名称。
It is a string, because window.name
has a purpose. You are setting the name of the window.
这篇关于为什么全局变量'name'更改为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文