DEV Community


Posted on • Updated on

Q1. How would you check if a number is an integer?

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
Enter fullscreen mode Exit fullscreen mode

1 Of 20 Js Interview Questions๐Ÿ™‚
Any comments or examples would be appreciated๐Ÿ™ƒ

Top comments (0)