typeof number vs unary plus

JavaScript performance comparison

Revision 3 of this test case created

Info

Typeof check when looking for number, vs unary +

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var toCheck = 42;
    var a = 0;
   
    var numString = 'number';
};
</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
typeof
if (typeof numString === 'number') {
 a++;
}
pending…
typeof cached comparison
if (typeof numString === numString) {
 a++;
}
pending…
unary +
if (numString === +numString) {
 a++;
}
pending…
|0
if(numString === numString|0) {
  a++;
}
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