Number.isInteger(value)
//returns a Boolean
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
const int = 10;
const float = 10.5;
console.log(Number.isInteger(int)); // true
console.log(Number.isInteger(float)); // false
// Explanation
// The Number.isInteger() method returns true
// if a value is an integer of the datatype Number.
// Otherwise it returns false
// Source: https://www.w3schools.com/jsref/jsref_isinteger.asp
console.log(Number.isInteger(9.5)) // false
function isInt(num) {
return num % 1 === 0;
}
console.log(isInt(4)); // true
console.log(isInt(12.2)); // false
console.log(isInt(0.3)); // false