liveBook · Manning

Number.isSafeInteger

As explained in Math for Web Design

Number.isSafeInteger is a JavaScript method that tests whether a value is a number representing an integer exactly within JavaScript's safe integer range.

Number.isSafeInteger(value) checks whether value is a JavaScript number that is an exactly representable integer between -9,007,199,254,740,991 and 9,007,199,254,740,991. Values beyond this range can look valid while becoming indistinguishable from nearby integers. section 2.2.1

Checking a boundary value

Number.isSafeInteger(42) returns true. Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1) returns false, identifying a value outside the reliable integer range. section 2.2.1

The method accepts only values of type number. When code may receive both number and bigint values, check the type first and compare bigint values with BigInt(Number.MIN_SAFE_INTEGER) and BigInt(Number.MAX_SAFE_INTEGER). section 2.8

How Math for Web Design covers it

How deep it goes
Defines the safe range, demonstrates boundary behavior, and notes the number-only limitation without examining numeric representation internals.
Examples
Uses 42, Number.MAX_SAFE_INTEGER + 1, and a custom number-or-bigint validation function.
What it assumes
Assumes familiarity with JavaScript numbers and types while teaching the safe integer boundary and number-versus-bigint distinction.
What you can do after
Diagnose/debug with it by detecting integers whose exact values JavaScript cannot reliably distinguish.
How it connects
Connects JavaScript numbers with floating-point precision, safe integer constants, and BigInt values.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.