问题
In Firefox web console, why can I change the type of name2
var name2=12
undefined
typeof name2
"number"
name2="hello"
"hello"
typeof name2
"string"
and not for name
typeof name
"string"
name=12
12
typeof name
"string"
?
回答1:
It's explicitly being cast to a string by JavaScript, since it's a readonly property of the global object (thanks Pointy).
来源:https://stackoverflow.com/questions/56086438/why-cant-i-change-the-type-of-name-in-firefox-web-console