A numeric ID or timestamp from a backend can exceed JavaScript’s safe integer range. At that point, ordinary number values may no longer represent every integer precisely. BigInt is a separate JavaScript numeric type for integer calculations beyond those limits; it is not a replacement for number in everyday UI calculations. section 2.4 section 2.4.1
Count past the safe limit
Number.MAX_SAFE_INTEGER is 9007199254740991. Convert that safe value with BigInt(Number.MAX_SAFE_INTEGER), then add 1n and 2n: the results are 9007199254740992 and 9007199254740993. You can also create a BigInt by appending n to an integer literal or by passing a decimal string to BigInt(). section 2.4.1
Keep the integer-only rules in mind:
- Use BigInt values on both sides of arithmetic: 5n + 1 throws a TypeError, while 5n + 1n works. Comparisons may mix number and bigint. section 2.4.2
- Division discards any fractional part. Most basic arithmetic operators work, but unary + does not. section 2.4.2
- Keep BigInt behind the scenes when possible: Math methods and JSON.stringify() do not accept it directly, and DOM APIs and CSS expect regular numbers. Ordinary numbers remain the practical choice for layout, styles, and animations. section 2.4.3 section 2.4.4
function isSafeInt(value) {
if (typeof value === "number") { #1
return Number.isSafeInteger(value); #2
}
if (typeof value === "bigint") { #3
return value >= BigInt(Number.MIN_SAFE_INTEGER) && #4
value <= BigInt(Number.MAX_SAFE_INTEGER); #4
}
return false; #5
}
This safe-integer check handles both numeric types. It uses Number.isSafeInteger() for number values, but compares bigint values against bounds converted to BigInt. section 2.8
Use BigInt when precise, potentially out-of-range integers matter. If the values stay within the safe range—or must drive a visual property—stick with number. section 2.4.4



