Home » JavaScript

Number isInteger() Method with Example in JavaScript

JavaScript Number isInteger() Method: Here, we are going to learn about the isInteger() method in JavaScript with example.
Submitted by IncludeHelp, on February 07, 2019

Number isInteger() Method

isInteger() is a Number Method, it is used to check whether a given number is an integer or not.

It returns true if given number is an integer, if given number is not an integer – it returns false.

Syntax:

    Number.isInteger(number);

Examples:

    Input: 10
    Output: true

    Input: 10.23
    Output: false

    Input: "Hello"
    Output: False

Code:

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
	document.write("10: " + Number.isInteger(10) + "<br>");
	document.write("10.23: " + Number.isInteger(10.23) + "<br>");
	document.write("Hello: " + Number.isInteger("Hello") + "<br>");
	
	//checking with variables
	var a = 10;
	var b = 10.23;
	var c = "Hello";
	
	if(Number.isInteger(a)==true)
		document.write(a + " is an integer value" + "<br>");
	else
		document.write(a + " is not an integer value" + "<br>");

	if(Number.isInteger(b)==true)
		document.write(b + " is an integer value" + "<br>");
	else
		document.write(b + " is not an integer value" + "<br>");

	if(Number.isInteger(c)==true)
		document.write(c + " is an integer value" + "<br>");
	else
		document.write(c + " is not an integer value" + "<br>");
</script>
</body>
</html>

Output

10: true
10.23: false
Hello: false
10 is an integer value
10.23 is not an integer value
Hello is not an integer value





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.