CKTIS / JavaScript
Numeric types: Number and BigInt
JavaScript has two primitive numeric types: Number for floating-point calculations and BigInt for integers without a fixed bit width. They differ in precision, division behavior, and conversion rules.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
const value = 42;
const fraction = 0.5;
const integer = 42n;
Number(integer);
BigInt(value);Number represents both integers and fractions using IEEE 754 binary64. Ordinary integer literals do not have a separate int type: typeof 42 returns "number". The type also includes NaN, Infinity, -Infinity, and two zeros: +0 and -0. Many decimal fractions cannot be represented exactly, so 0.1 + 0.2 === 0.3 evaluates to false.
The safe integer range of Number is -(2 ** 53 - 1) through 2 ** 53 - 1. Outside it, not every consecutive integer can be distinguished, although some integers are still represented exactly. Use Number.isSafeInteger(value) to check this property.
BigInt represents integers without a fixed bit width; practical sizes are limited by implementation resources. Literals use the n suffix, such as 42n, and typeof 42n returns "bigint". It does not support fractions, NaN, or infinities. Division truncates toward zero: 5n / 2n produces 2n, whereas 5 / 2 produces 2.5.
Do not mix these types in arithmetic: 2n + 3 throws TypeError. Convert explicitly with BigInt(value) or Number(value). Converting a non-integer Number to BigInt throws RangeError, while conversion in the other direction can lose precision. Create large integers from a BigInt literal or a string, not an already rounded Number. Comparisons differ from arithmetic: 2n === 2 is false, but 2n < 3 is true.
Examples
console.log(typeof 42);
console.log(typeof 42n);
console.log(0.1 + 0.2 === 0.3);
console.log(Number.isSafeInteger(9007199254740992));
console.log(String(9007199254740993n + 1n));
console.log(5 / 2);
console.log(String(5n / 2n));
console.log(String(2n + BigInt(3)));
try {
console.log(2n + 3);
} catch (error) {
console.log(error.name);
}Result
number bigint false false 9007199254740994 2.5 2 5 TypeError
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.