DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

saiarlen
saiarlen

Posted 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)

🌚 Life is too short to browse without dark mode