Ans. A very simple way to check if a number is a decimal or integer is to see if there is a remainder left when you divide by 1.
function isInt(num) {
return num % 1 === 0;
}
console.log(isInt(6)); // true
console.log(isInt(11.5)); // false
console.log(isInt(0.6)); // false
1 Of 20 Js Interview Questions๐
Any comments or examples would be appreciated๐
Latest comments (0)