for example,
var name = [1,2,3] // name === "1,2,3"
name = {"a":"b"} // name === "[object Object]"
I don't understand this situation.
what is the identity of 'name' or 'window.name' on javascript?
ADD:
I used Chrome's Dev Tools
for example,
var name = [1,2,3] // name === "1,2,3"
name = {"a":"b"} // name === "[object Object]"
I don't understand this situation.
what is the identity of 'name' or 'window.name' on javascript?
ADD:
I used Chrome's Dev Tools
When you declare
name = {"a":"b"}
you are creating an object and the string representation of an object is [object Object]
, that is, when you try to convert an object to a string (which is probably the case here) you get that result.
Note that name === "[object Object]"
is not true.
alert( name === "[object Object]" ); // alerts "false"
alert( name.toString() === "[object Object]" ); // alerts "true"
The same holds true for the array. 1,2,3
is just a string representation of array [1,2,3]
.
As for window.name
, it has the name of the current window so changing it to a non-string might lead to unexpected behavior: https://developer.mozilla.org/en/DOM/window.name