Brian Chandler Brian Chandler - 3 months ago 10x
Javascript Question

Javascript: Comparing two identical object literals

I'm pretty sure I figured this out before, but can't remember why this resolves to false. Can someone explain why?

if ({foo: 'bar'} === {foo: 'bar'}) {
console.log("Strictly Equal");
} else {
console.log("Not Equal");

I also tried == but it still has the two object literals as not equal.



== and === don't perform deep comparisons. They'll perform value comparisons for value types. But, objects are compared as references -- and those aren't the same object, they simply happen to be identical.