How to check if a variable is an integer in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To check if a variable is an integer, check the value using parseInt() and check with === operator.

Example

You can try to run the following code to check the existence of an integer −

Live Demo

<html>
   <head>
      <script>
         var a = 10;
         if (a === parseInt(a, 10))
            alert("Integer!")
         else
           alert("Not an integer!")
      </script>
   </head>
   <body>
   </body>
</html> 
raja
Published on 03-Feb-2018 10:26:53
Advertisements