In mathmetics a relation is said to be
if it holds true that if a is related to b, then b must also be related to a.
For the equals operator this means that if
a == b evaluates to
b == a must also evaluate to
In most languages equals is expected to be symmetric, transitive and reflexive:
a, for equals to be reflexive, it must hold true that
a == a.
band asserting that
a == b, for equals to be symmetric it must also hold true that
b == a.
cand asserting that
a == b && b == c, for equals to be transitive it must also hold true that
c == a.
I am limiting the scope above to objects to explicitly exclude things
NaN (Not a Number),
because these are somewhat 'magical' values.
Is the equals operator symmetric in your browser?
The test is performed by comparing the values of
in a function that was assigned to the global (
window) object from within
an anonymous function. For some reason in Internet Explorer 8 (maybe other versions as
well), in that context
this == window yields
window == this yields
true (correct) and it can
be clearly seen in the debugger that
window are in
fact the same object.