/

The isInteger() Method in JavaScript

The isInteger() Method in JavaScript

Learn all about the Number object’s isInteger() method in JavaScript.

The isInteger() method determines whether a given value is an integer. It returns true if the value is an integer and false for any other data type, including booleans, strings, objects, and arrays.

Here are some examples:

1
2
3
4
5
6
7
8
9
Number.isInteger(1); // true
Number.isInteger(-237); // true
Number.isInteger(0); // true

Number.isInteger(0.2); // false
Number.isInteger('Flavio'); // false
Number.isInteger(true); // false
Number.isInteger({}); // false
Number.isInteger([1, 2, 3]); // false

By using the isInteger() method, you can easily check whether a value is an integer or not in your JavaScript code.

Tags: JavaScript, Number object, isInteger() method