How to check if the given value is an integer or not in JavaScript

by Sai gowtham  1 Min read

There is a Number.isInteger() method in JavaScript which helps us to check the whether a given value is an integer or not.

Number.isInteger() method returns true whether a given value is number otherwise it returns false.

function isNumeric(value){

   return Number.isInteger(value);
}

isNumeric(1222); // true

isNumeric('1222'); // false

isNumeric('booo'); // false

If the given value is Infinity or not a number returns false.

isNumeric(Infinity) //  false

isNumeric(-Infinity) //  false

isNumeric(0) // true

Happy coding…