typeof number vs unary plus

Benchmark created by Jarrod Overson on


Description

Typeof check when looking for number, vs unary +

Setup

var toCheck = 42;
    var a = 0;
    
    var numString = 'number';

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
if (typeof toCheck === 'number') {
 a++;
}
ready
typeof cached comparison
if (typeof toCheck === numString) {
 a++;
}
ready
unary +
if (toCheck === +toCheck) {
 a++;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.