Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Function

Number.isInteger

Number.isInteger() tests whether a value is a Number representing an integer. It does not coerce non-number values and returns false for NaN and infinities.

How it works

Call Number.isInteger(value) to test whether value is a Number representing an integer. It returns true for integral numeric values, including values such as 5.0, and false for non-numbers, non-integral numbers, NaN, and infinities; due to floating-point precision, some imprecise large values can still be classified as integers.

Syntax

Number.isInteger(value)

Parameters

NameTypeDescription
valueanyThe value to be tested for being an integer.

Returns

A boolean: true if the given value is an integer; otherwise false.

Key points

  • Number.isInteger is a static Number method for classifying a supplied value as an integer or not.
  • Its call accepts one value argument.
  • The value parameter is the item whose integer status is checked.
  • The result is true when the value is an integer.
  • A Number such as 5.0 passes because its represented numeric value is integral.

Common mistakes

  • Numeric-looking strings, booleans, arrays, and other non-number values are rejected rather than converted.
  • NaN and positive or negative infinity are never accepted.
  • Floating-point representation can make a literal that appears fractional behave as an integer.
  • Do not use this test alone when exact representation of large integers matters; consider Number.isSafeInteger().

Example: Testing integer values

const values = [5, 5.1, "5", NaN, 2 ** 53];

for (const value of values) {
  console.log(value, Number.isInteger(value));
}

Checks numbers without coercing strings or other non-number values.

When to use it

Input validation

Validate numeric input before performing operations that require whole-number values.

Runtime contracts

Reject fractional, string, boolean, NaN, or infinite values in API parameters.

Conversion guards

Check whether a value can be treated as an integer before converting it to BigInt.

  • Number.isSafeInteger()
  • Number.isFinite()
  • Number.isNaN()
  • Number.MAX_SAFE_INTEGER

Source: Number.isInteger() - JavaScript - MDN Web Docs. Checked 2026-10-15.