×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

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

Example

Input: 10
Output: true

Input: 10.23
Output: false

Input: "Hello"
Output: False

Example - Use of Number isInteger() Method

<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

JavaScript Number Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.