Why are two identical objects not equal to each other?

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 true if you compare the same exact object.

That is, given var a = {}, b = a, c = {};, a == a, a == b, but a != 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.

Leave a Comment