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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you declare
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.The same holds true for the array.
1,2,3is 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