Integer Validity (v24)

Revision 24 of this benchmark created by ManojRK on


Description

Using or operator to determine if a variable is an integer.

Will check for integers in strings

Setup

var a = 12;
    var b = 34.5;
    var c = Infinity;
    var d = '12';
    var e = '34.5';

Test runner

Ready to run.

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

Revisions

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