BartlomiejSkwira
4/25/2013 - 6:37 PM

Check if value is integer in Javascript

Check if value is integer in Javascript

//check a remainder when dividing by 1:

function isInt(n) {
   return n % 1 === 0;
}
//If you don't know that the argument is a number-

function isInt(n) {
   return !isNaN(n) && n % 1 == 0;
}