Assuming Array was not overwritten, why the following comparisons output false?
[] === new Array()
> false
[] === []
> false
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.
Whether using the equality
==operator or the strict equality===operator, if the operands are objects the result will be true only if both operands refer to the same object.Your code creates two distinct arrays, both empty, so intuitively they might seem equal but that is not how the equals operators work.
Similarly something like
[1,2,3] === [1,2,3]will be false. Again it is easy to think they should be equal, but the comparison is testing whether the arrays are the same array, not whether all of the elements in the array are equal.On the other hand
x === ywill be true if bothxandyrefer to the same array.For more information: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Comparison_Operators