Javascript Number isInteger()

Introduction

The Javascript Number.isInteger() method checks whether the passed value is an integer.

Number.isInteger(value)
Parameter Optional Meaning
value Required The value to be tested for being an integer.

It returns a boolean value indicating whether or not the given value is an integer.

If the target value is an integer, return true, otherwise return false.

If the value is NaN or Infinity, return false.

For floating point numbers that can be represented as integer, return true.

In ES6, Number.isInteger() method can check if a number value is stored as an integer or not.

console.log(Number.isInteger(1));     // true 
console.log(Number.isInteger(1.00));  // true 
console.log(Number.isInteger(1.01));  // false 
let a = Number.isInteger(0);         // true
console.log(a);//from  www  .jav  a 2  s.c  o m
a = Number.isInteger(1);         // true
console.log(a);
a = Number.isInteger(-100000);   // true
console.log(a);
a = Number.isInteger(99999999999999999999999); // true
console.log(a);
a = Number.isInteger(0.1);       // false
console.log(a);
a = Number.isInteger('10');      // false
console.log(a);
a = Number.isInteger(true);      // false
console.log(a);
a = Number.isInteger(false);     // false
console.log(a);
a = Number.isInteger([1]);       // false
console.log(a);
a = Number.isInteger(5.0);       // true
console.log(a);
a = Number.isInteger(5.000000000000001); // false
console.log(a);
a = Number.isInteger(Math.PI);   // false
console.log(a);
a = Number.isInteger(NaN);       // false
console.log(a);
a = Number.isInteger(Infinity);  // false
console.log(a);
a = Number.isInteger(-Infinity); // false
console.log(a);



PreviousNext

Related