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

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


On Jun 14, 2012, at 4:30 PM, Michael Haufe wrote:

> The opposite seems to be true:
> 
> <https://gist.github.com/gists/search?q=%22case+NaN%22&x=0&y=0>

this only has
  case "NaN":
not
   case NaN:



> <https://github.com/search?q=%22case+NaN%22&type=Everything&repo=&langOverride=&start_value=1>

And the above isn't only looking at JS code.  If you limit the search to javascript code the only result that actually matches "case NaN:" is what appears to be a SpiderMonkey test case that is replicated several places

// No test case, just make sure this doesn't assert.
function testNegZero2() {
    var z = 0;
    for (let j = 0; j < 5; ++j) { ({p: (-z)}); }
}
testNegZero2();

function testConstSwitch() {
    var x;
    for (var j=0;j<5;++j) { switch(1.1) { case NaN: case 2: } x = 2; }
    return x;
}
assertEq(testConstSwitch(), 2);

Allen



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120614/9c12b617/attachment.html>


More information about the es-discuss mailing list