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

Mark S. Miller erights at google.com
Thu Jun 14 15:25:27 PDT 2012


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.

-- 
    Cheers,
    --MarkM


More information about the es-discuss mailing list