Number.isInteger(value)
//returns a Boolean
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
let testString="5";
if(Number.isInteger(parseFloat(testString))){
console.log("we are a int of some sort");
}
function isInt(num) {
return num % 1 === 0;
}
console.log(isInt(4)); // true
console.log(isInt(12.2)); // false
console.log(isInt(0.3)); // false
// The === operator is used for checking
// the value and the type of a variable
var data = 1;
if (data === parseInt(data, 10))
alert("data is integer")
else
alert("data is not an integer")