Seems like the following code should return a true, but it returns false.
var a = {};
var b = {};
console.log(a==b); //returns false
console.log(a===b); //returns false
How does this make sense?
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.
The only difference between regular (
==) and strict (===) equality is that the strict equality operator disables type conversion. Since you’re already comparing two variables of the same type, the kind of equality operator you use doesn’t matter.Regardless of whether you use regular or strict equality, object comparisons only evaluate to
trueif you compare the same exact object.That is, given
var a = {}, b = a, c = {};,a == a,a == b, buta != c.Two different objects (even if they both have zero or the same exact properties) will never compare equally. If you need to compare the equality of two object’s properties, this question has very helpful answers.