if (typeof a !== "object" && typeof b !== "object") {
return a == b;
}
... // check pairwise equality of object a & b using `for in`
Is it the same as
if (typeof a !== "object") {
return a == b;
}
Is there any b
with typeof b === "object"
which would change the semantics?
Are there any horrible edge cases I should be aware of? Comparisons between an object
and a native type
which have a non-intuitive boolean equality or disequality? Including any bugs in browser (I mean you IE6!)
The second check is not quite the same as the first, no, simply because JavaScript is weakly typed so at the very least consider the "
.toString()
effect", as well as others. For example these would fail the first check, but pass in the second:Or, a bit simpler (showing a case you may want to consider...but this passes both checks):
One fix would be to do a value and type check with
===
which is a strict comparison operator, you get type checking as well...but I'm not entirely sure that's what you're after, since the current check is explicitly "not an object".