BigInt is a relatively new JavaScript data type introduced in 2020.
JavaScript's original Number primitive can only represent numbers up to 253 - 1.
We can log this maximum value with Number.MAX_SAFE_INTEGER
:
console.log(Number.MAX_SAFE_INTEGER)
// 9007199254740991
BigInts can be bigger than this number. We can construct a BigInt using the n
suffix:
const bigFella = 10000000000000000000n
console.log(bigFella)
// 10000000000000000000n
We can also construct a BigInt with the BigInt()
constructor:
const anotherBigFella = BigInt(10000000000000000000)
console.log(anotherBigFella)
// 10000000000000000000n
Logging the BigInt won't magically turn it into a Number, and at no point will the BigInt be transformed into a Number. It's a different data type, and it will always retain the n
suffix.