Check if Number Is Integer JavaScript|Number.isInteger

JavaScript check if number is integer; In this tutorial, you will learn how to check if number is integer in javaScript.

When you work with javascript. Most times you check that value is string, number, integer number, decimal number, etc. So In this tutorial, you will learn how you can check value is a number or not in javascript using the number.isInteger() method.

Check if Number Is Integer JavaScript|Number.isInteger

You can easily check if a number is an integer or not in javascript using the number.isInteger() function.

JavaScript Number.isInteger() Method

In JavaScript Number.isInteger() method works with numbers, it will check whether a value an integer. This method returns true if the value is of the type Number and an integer. Otherwise, it will return false.

If the target value is an integer, return true, otherwise, return false. If the value is NaN or Infinity, return false. The method will also return true for floating-point numbers that can be represented as an integer.

Syntax

The syntax of number.isInterger() method is:

Number.isInteger(value)

Parameters

This method accept only one parameter.

Example of the Number.isInterger()

You can use this below source code to check a given number is an integer or not in javascript.

We will use javascript number method, The Number() the method converts a string to a number.

<!DOCTYPE html>
<html>
<title>Check if Number Is Integer JavaScript | Number.isInteger</title>
<head></head>
<body>
<h2>How to Check if Number Is Integer or Not In JavaScript</h2>
<br/>
<input type="text" id="is_interger" value="" placeholder="Please enter here.....">
<br/><br/>
<button onclick="checkIntergerJavaScript()">Click & See Result</button>
<br/>
<script type="text/javascript">
    function checkIntergerJavaScript() {

      var num = document.getElementById("is_interger").value;
      if(Number.isInteger(Number(num))){
        alert(num + " is a integer number");
       }else{
        alert(num + " is not an integer number");
       }
  }

</script>

</body>
</html>

Demo

Check if Number Is Integer JavaScript | Number.isInteger
How to Check if Number Is Integer or Not In JavaScript




Conclusion

In this javascript tutorial of the Number.isInteger() method, you have learned how you can check a number is an integer or not in javascript using the is Number.isInteger() method. In javaScript Number.isInteger() function to check whether the value passed to it is an integer or not. It returns true if the passed value is an integer, otherwise, it will return false.

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *