Number.isInteger() function in JavaScript


The isInteger() function of the Number object accepts a number and determines if it is finite number. If the given number is finite it returns true else, it returns false.

Syntax

Its Syntax is as follows

Number.isInteger(100/0);

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = Number.isFinite(100/0);
      if(result) {
         document.write("Given number is finite");
      }else {
         document.write("Given number is infinite");
      }
   </script>
</body>
</html>

Output

Given number is infinite

Example

In addition to equation you can also pass positive number, negative number, zero and an equation as a parameter to this function.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = Number.isFinite(45);
      document.write(result1);
      document.write("<br>");
      var result2 = Number.isFinite(-38);
      document.write(result2);
      document.write("<br>");
      var result3 = Number.isFinite(0);
      document.write(result3);
      document.write("<br>");
      var result4 = Number.isFinite("Tutorialspoint");
      document.write(result4);
   </script>
</body>
</html>

Output

true
true
true
false

Updated on: 25-Jun-2020

31 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements