What's special about the “name” variable in JavaScript? [duplicate]

安稳与你 提交于 2021-02-18 21:10:32

问题


In the Chrome Developer Tools window, I typed in:

> name = ["a", "b", "c"]
["a", "b", "c"]

However, name became a string:

> typeof name
"string"
> name
"a,b,c"
> name[1]
","

This obviously isn't true for other variable names!

> foo = ["a", "b", "c"]
["a", "b", "c"]
> typeof foo
"object"
> foo[1]
"b"

And name is defined as the empty string on page load (and, as far as I can tell, cannot become anything other than a string).

So, what's up with name?


回答1:


When you type name you are implicitly referencing window.name, which according to MDN:

Gets/sets the name of the window.

https://developer.mozilla.org/en-US/docs/Web/API/window.name



来源:https://stackoverflow.com/questions/19008645/whats-special-about-the-name-variable-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!