Javascript - Number isInteger() Method

The Number.isInteger() method determines whether a value an integer.

Description

The Number.isInteger() method determines whether a value an integer.

This method returns true if the value is of the type Number, and a whole number. Otherwise it returns false.

Syntax

Number.isInteger(value)

Parameter Values

Parameter Require Description
value Required. The value to be tested

Return

A Boolean. Returns true if the value is an integer Number, otherwise it returns false

Example

Check whether a value is an integer:

Demo

var res = "";
res = res + Number.isInteger(123) + ": 123\n";
res = res + Number.isInteger(-123) + ": -123\n";
res = res + Number.isInteger(5-2) + ": 5-2\n";
res = res + Number.isFinite(0) + ": 0\n";
res = res + Number.isInteger(0.5) + ": 0.5\n";
res = res + Number.isInteger('123') + ": '123'\n";
res = res + Number.isInteger(false) + ": false\n";
res = res + Number.isInteger(Infinity) + ": Infinity\n";
res = res + Number.isInteger(-Infinity) + ": -Infinity\n";
res = res + Number.isInteger(0 / 0) + ": 0 / 0\n";

console.log(res);/*w  w w  . j a  v  a  2 s.c o  m*/

Result