Re:JavaScript: The Curious Case of null >= 0
by SomeStupidPoint on Saturday September 09, 2017 @11:00AM
(#15207379)
Someone else pointed out that Java has (or had?) a similar issue with comparing boxed Ints -- equality checks for object level equality while inequality compares the values.
Without explicit casting, the equality operator casts to a more general type (or rather, doesn't cast at all) than the inequality operator (which casts to numerics).
This happens anywhere you have weird coercion rules.
Re:JavaScript: The Curious Case of null >= 0
by kbp on Saturday September 09, 2017 @01:16PM
(#15207992)
> Java has (or had?) a similar issue with comparing boxed Ints -- equality checks for object level equality while inequality compares the values.
In Java 5 and up, 'new Integer(1) < new Integer(2)' will return true, because it automatically unboxes both Integers and compares them as primitives (before Java 5 it was a compile error).
It will not unbox the Integers in 'new Integer(1) == new Integer(1)', though, because given objects, '==' is always reference equality, so it will return false because they're different instances ('!=' would still return true, though). To compare objects by value, you use equals; 'new Integer(1).equals(new Integer(1))' is true.
Re:JavaScript: The Curious Case of null >= 0
by matt2000 on Saturday September 09, 2017 @12:22PM
(#15207746)
I agree with everything you said, except for the part where you said JavaScript was "designed".
Re:JavaScript: The Curious Case of null >= 0
by quickthrower2 on Saturday September 09, 2017 @09:39PM
(#15210042)
Haskell was designed in the 90s. So don't blame the decade.
e.g. in Ruby:
and Python 3: Obviously JS (and Python 2!) get this wrong, but to be fair JS was designed in the 90s.