JSFiddle - React, Tailwind, and code Playground

by jyrkim

JavaScript

function isInteger(n) {
    return (typeof n == 'number' && /^[-]?[0-9]+$/.test(n+''));
}

var n = 1;

var n2 = -5;

var n3 = 1234567890;

var n4 = 1.2;

var n5 = -1.2;

console.log( "1 " + isInteger(n));

console.log( "-5 " + isInteger(n2));

console.log( "1234567890 " +  isInteger(n3));

console.log("1.2 " +  isInteger(n4));

console.log( "-1.2 " + isInteger(n5));