Strict Relational Operators
felix8a at gmail.com
Thu Apr 13 04:56:17 UTC 2017
On Wed, Apr 12, 2017 at 7:23 PM, Darien Valentine <valentinium at gmail.com> wrote:
>> One common JS problem is NaNs ending up in unexpected places, and it's
>> often difficult to trace back where they came from. Getting a type error
>> instead of a NaN would be nice.
> I’m not sure this would help with that. NaN may be the product of coercion,
> but NaN itself is a numeric value, and it can be produced without any type
> coercion, e.g. `Infinity/Infinity`, `(-1) ** 0.5`, etc. And the `===`
> operator is a strict, non-coercive comparison, but that doesn’t mean it
> throws type errors.
Mysterious NaNs in js are usually due to implicit conversion of random
objects to numbers, not normal numeric computation.
It's reasonable for non-coercing === to work on different types, but
what would a non-coercing + do with different types? It has to throw
Non-coercing < might throw an error or use some arbitrary ordering of
types. I don't have strong feelings about that.
More information about the es-discuss