BigInt

As of ES11, there exists the 7th type of JavaScript primitive – BigInt.

BigInt is a built-in object that provides a way to represent whole numbers larger than 253 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant. BigInt can be used for arbitrarily large integers.

A BigInt is created by appending n to the end of an integer literal — 10n — or by calling the function BigInt().


RESETRUNFULL
<!DOCTYPE html><html><body><script>

const theBiggestInt = 9007199254740991nconst alsoHuge = BigInt(9007199254740991)const hugeString = BigInt("9007199254740991")const hugeHex = BigInt("0x1fffffffffffff")const hugeBin = BigInt( "0b11111111111111111111111111111111111111111111111111111")console.log(theBiggestInt * theBiggestInt);                         // 81129638414606663681390495662081nconsole.log(typeof theBiggestInt);  // bigintconsole.log(1n === 1);  // falseconsole.log(1n == 1);  // true

</script></body><html>

Static methods Static methods Static methods

BigInt.asIntN()

Wraps a BigInt value to a signed integer between -2width-1 and 2width-1 - 1.

BigInt.asUintN()

Wraps a BigInt value to an unsigned integer between 0 and 2width - 1.

Prototype Methods Prototype Methods Prototype Methods

BigInt.prototype.toLocaleString()

Returns a string with a language-sensitive representation of this number. Overrides the Object.prototype.toLocaleString() method.

BigInt.prototype.toString()

Returns a string representing the specified object in the specified radix (base). Overrides the Object.prototype.toString() method.

BigInt.prototype.valueOf()

Returns the primitive value of the specified object. Overrides the Object.prototype.valueOf() method.