10

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?

kris
  • 23,024
  • 10
  • 70
  • 79
  • it looks like name already exists prior to assigning it to an array. It's value by default is `""`. I suspect it's a built-in/prototype that is part of the language proper. Specifics notwithstanding. – Justin Carroll Sep 25 '13 at 15:15
  • Another thing I noticed, the variable stays set even if you reload the page, which is not normal behavior. – dajavax Sep 25 '13 at 15:15
  • well, you can have a function called "name" or an object and it will return `function` or `object` from calling `typeof name` – AvL Sep 25 '13 at 15:20

1 Answers1

9

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

Alex W
  • 37,233
  • 13
  • 109
  • 109