isNaN vs n !== n

JavaScript performance comparison

Test case created by Florian Cargoët

Preparation code

<script>
  var iAmNotANumber = 0 / 0;
  var iAmANumber = 1;
 
  var myIsNaN = function(n) {
   return n !== n;
  }
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
isNaN
isNaN(iAmNotANumber);
isNaN(iAmANumber);
pending…
n !== n
iAmNotANumber !== iAmNotANumber;
iAmANumber !== iAmANumber;
pending…
myIsNaN
myIsNaN(iAmNotANumber);
myIsNaN(iAmANumber);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment