Answers for "how to check if variable is integer in js"

12

integer check in javascript

var a=Number.isInteger(5); //True
var b= Number.isInteger(01); //True
var c=Number.isInteger("10"); //False

console.log(a,b,c);  //true true false
Posted by: Guest on July-17-2020
9

javascript check if variable is number

function isNumber(n) {
  return !isNaN(parseFloat(n)) && !isNaN(n - 0);
}
Posted by: Guest on May-22-2020
1

how would you check if a number is an integer in javascript

function isInt(num) {
  return num % 1 === 0;
}
console.log(isInt(4)); // true
console.log(isInt(12.2)); // false
console.log(isInt(0.3)); // false
Posted by: Guest on March-06-2022

Code answers related to "how to check if variable is integer in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language