Example 1 — Zero Is an Integer
0 has no fractional part.
Number.isInteger(0); // true How It Works
0 is a number and an integer, so the result is true. The same holds for 1, 2, and so on.
Number.isInteger() is a static method on Number (same API as MDN Number.isInteger). Call Number.isInteger(value) — not on a number instance. It returns true only for integer number values. This tutorial covers syntax, floats vs integers, precision quirks, five examples, and try-it labs.
Number only
boolean
Integer number
Floats / Inf / NaN
None
Everywhere
Counts, indexes, and page sizes are usually whole numbers. Number.isInteger() tells you whether a value is an integer — a number with no fractional part.
Like other static Number checks, it does not coerce strings: Number.isInteger("10") is false. Parse first when the input is text.
Static methods belong to Number itself. Always write Number.isInteger(x). There is no (5).isInteger() on Number.prototype.
This page is part of JavaScript Number Methods. Related static checks include Number.isFinite() and Number.isNaN().
isInteger() MethodPass any value to Number.isInteger(value). You get true only when both of these are true:
"number".0).Infinity, -Infinity, NaN, floats like 0.1, and non-numbers all return false. Values written with .0 (such as 5.0) still count as integers.
General form of the static method Number.isInteger:
Number.isInteger(value) A boolean:
| Value | Returns |
|---|---|
Integer (e.g. 0, 1, -100000, 5.0) | true |
Non-integer number (e.g. 0.1, Math.PI) | false |
Infinity / NaN | false |
Non-number (e.g. "10", true) | false |
false.Number.isInteger(0); // true
Number.isInteger(-100000); // true
Number.isInteger(0.1); // false
Number.isInteger("10"); // false
Number.isInteger(5.0); // true
Number.isInteger(10 / 5); // true | Goal | Code |
|---|---|
| Integer check | Number.isInteger(x) |
| Accept text input | Number.isInteger(Number(s)) |
| Reject floats | Number.isInteger(0.1) → false |
| Allow 5.0 | Number.isInteger(5.0) → true |
| Finite but not integer? | Number.isFinite(x) && !Number.isInteger(x) |
| Division fits evenly | Number.isInteger(y / x) |
Four facts to remember about Number.isInteger().
staticCall on Number, not instances
booleantrue only for integer numbers
noneStrings and objects fail
BaselineES2015+ everywhere modern
Number.isInteger() vs Number.isFinite()Number.isInteger(x) | Number.isFinite(x) | |
|---|---|---|
1 | true | true |
1.5 | false | true |
Infinity | false | false |
"10" | false | false |
| Best for | Whole-number validation | Any finite numeric value |
Examples follow MDN patterns. Use View Output or Try It Yourself for each case.
Positive, zero, and negative integers.
0 has no fractional part.
Number.isInteger(0); // true 0 is a number and an integer, so the result is true. The same holds for 1, 2, and so on.
Negative whole numbers count as integers too.
Number.isInteger(-100000); // true The sign does not matter — only whether a fractional part exists.
Floats, non-numbers, and even division checks.
Any stored fractional part fails the check.
Number.isInteger(0.1); // false 0.1 is finite but not an integer. Number.isInteger(Math.PI) is also false.
Numeric-looking strings are rejected.
Number.isInteger("10"); // false The argument is a string, so the result is false. Use Number.isInteger(Number("10")) when text input should count.
An MDN-style check: does y divide evenly by x?
Number.isInteger(10 / 5); // true 10 / 5 is 2, an integer. Try Number.isInteger(11 / 5) — that is false because the quotient is 2.2.
Number.isInteger(y / x) for “fits evenly” checks.Number.isInteger() DecidesAny JavaScript value can be passed in.
Must be typeof number — no coercion.
Reject floats, Infinity, and NaN.
true only for integer numbers.
Number.isInteger(x) only.Number.isInteger(5.0) is true — 5.0 is the same value as 5.Number.isInteger(5.000000000000001) is false, but an even tinier difference may round to 5 and return true.Number.isInteger() is Baseline Widely available — part of ES2015 and supported in every modern browser and Node.js.
Safe for production everywhere. Prefer it for whole-number validation without coercion.
Bottom line: Use Number.isInteger for new code. Parse strings yourself before checking if text input must be accepted.
Number.isInteger() is the modern, static way to ask whether a value is a whole number — without coercing strings or treating floats as integers.
Continue with Number.isNaN() for NaN detection, Number.isFinite() for any finite value, or return to the Number methods hub.
Number.isInteger(x) on the constructorNumber(s) before checkingNumber.isFinite when you also need float support5.0 is still an integer(5).isInteger() — that is not a Number method"10" pass the checkNumber.isInteger()Static, strict, boolean check for whole numbers.
static
APIboolean
Resultfloats
Filternone
StrictBaseline
SupportSome literals look fractional but encode as integers because of floating-point limits. MDN notes Number.isInteger(5.0000000000000001) can be true because that tiny difference cannot be represented separately from 5.
Return to the hub for instance and static Number tutorials.
8 people found this page helpful