> x === y
true
> 1/x > 1/y
true
Show answer
> x === y
true
> 1/x > 1/y
true
Show answer
+0 and -0 are the only two values that are not the same, but are still considered strictly equal [1]. They can only be distinguished indirectly, by applying a mathematical operation to them that produces distinguishable results. Dividing 1 by zero is one of several operations that does so:
> 1/-0
-Infinity
> 1/+0
Infinity
The infinities are distinguishable:
> -Infinity === Infinity
false
Further reading:
2 comments:
x=0, y=-0
That's nice!
I had two answers, the one with the 0s, and another playing with the valueOf:
x = y = { count: 1, valueOf: function () { return this.count++; }};
x === y; // obviously as there is no coercion
1/x > 1/y; // because valueOf is called once for each coercion, so 1/x is 1/1 and 1/y is 1/2
Post a Comment