Learn JavaScript
❯ types.numbers

Numbers & BigInt in JavaScript

$concept

JavaScript has one number type: 64-bit IEEE 754 double — integers exact only to 2^53 - 1 (Number.MAX_SAFE_INTEGER), with 0.1 + 0.2 famously equaling 0.30000000000000004. Special values Infinity, -Infinity, and NaN (the only value not equal to itself) cover overflow, division edge cases, and failed math.

BigInt (123n suffix or BigInt()) holds arbitrary-precision integers for IDs, timestamps, and crypto — but never mixes with Number in arithmetic (1n + 1 throws; convert explicitly). Money code uses integer cents or decimal libraries, never raw floats.

$how it works
1

One float type

Every number is a double — integers, decimals, all of it. Safe integers end at 2^53 - 1.

2

0.1 + 0.2 !== 0.3

Binary fractions can't represent most decimals exactly — compare with epsilon (Math.abs(a - b) < 1e-10), never ==.

3

NaN means failed math

0/0, parse failures, and bad operations yield NaN — detected only via Number.isNaN(), since NaN !== NaN.

4

BigInt for huge integers

123n suffix or BigInt("...") for exact big integers — but 1n + 1 throws TypeError; convert deliberately.

$example
console.log(0.1 + 0.2 === 0.3);
console.log(Number.isSafeInteger(2 ** 53));
console.log(10n + 20n);
Output
false
false
30n
10.1 + 0.2 accumulates binary rounding dust, so strict equality with 0.3 is false.
22^53 sits outside the safe range — integer math there silently loses precision.
3BigInt arithmetic stays exact at any size, printing with its n suffix.
$use cases
Epsilon comparisons for every floating-point equality test
Integer cents (or decimal libraries) for all money math
BigInt IDs and timestamps beyond 2^53
Number.isNaN/isFinite guards on parsed and computed values

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.