[NaN].indexOf(NaN) === -1 VS Object.is(NaN, NaN)

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Jun 14 16:34:26 PDT 2012

On Jun 14, 2012, at 3:25 PM, Mark S. Miller wrote:

> On Thu, Jun 14, 2012 at 7:59 PM, Andrea Giammarchi
> <andrea.giammarchi at gmail.com> wrote:
>> This is basically what I am doing except I find Array#indexOf as it is
>> pointless ... or better, something that should be fixed in the next version
>> of ECMAScript.
> I agree. I argued that it should be fixed as of ES5, but lost the
> argument on compatibility grounds. No one had measurements either way,
> so in the absence of evidence we properly made the conservative
> choice. The other place where this occurs, and IMO is an even worse
> problem is switch:
>    function sw(x) {
>      switch (x) {
>        case NaN: return 'match';
>        default: return 'default';
>      }
>    }
>    sw(NaN);    // returns: 'default'
> It's too late for ES6. In order to fix these for ES7, someone would
> need to gather evidence that the web corpus does not depend on the
> current broken behavior.

I disagree about the too lateness. Specification-wise this would be a minor change and the absolute cut-off date is about a year away. If we actually had evidence that it was a safe breaking change we could do it.  Of course, getting that evidence is not a trivial matter.

Regarding switch statements.  We could make
     case NaN:
be an early error.  It wouldn't take care of computed NaN case expression values but it would take care of the obviously buggy literal cases like your example.

We would probably still need some evidence that an early error on case NaN wouldn't be disruptive.


> -- 
>     Cheers,
>     --MarkM
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

More information about the es-discuss mailing list