Integer Validity (v32)

Revision 32 of this benchmark created by Elliot Waite on


Setup

var a = 12;
    var b = 34.5;
    var c = Infinity;

Test runner

Ready to run.

Testing in
TestOps/sec
Typeof and modulus operator
(typeof a === 'number' && a % 1 === 0);
(typeof b === 'number' && b % 1 === 0);
(typeof c === 'number' && c % 1 === 0);
ready
Using parseInt
(a == parseInt(a));
(b == parseInt(b));
(c == parseInt(c));
ready
Using Number
(Number(a) === a && a % 1 === 0);
(Number(b) === b && b % 1 === 0);
(Number(c) === c && c % 1 === 0);
ready

Revisions

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