toString() method returns a string representing the
BigInt object. The trailing "n" is not part of the string.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
- Optional. An integer in the range 2 through 36 specifying the base to use for representing numeric values.
A string representing the specified
BigInt object overrides the
toString() method of the
Object object; it does not inherit
BigInt objects, the
toString() method returns a string representation of the object in the
toString() method parses its first argument, and attempts to return a
string representation in the specified radix (base). For radixes above 10, the letters
of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers
f are used.
radix is not specified, the preferred radix is assumed to be 10.
bigIntObj is negative, the sign is preserved. This is the case even
if the radix is 2; the string returned is the positive binary representation of the
bigIntObj preceded by a
- sign, not the two's
complement of the
17n.toString(); // '17' 66n.toString(2); // '1000010' 254n.toString(16); // 'fe' -10n.toString(2); // -1010' -0xffn.toString(2); // '-11111111'
There is no negative-zero
BigInt as there are no negative zeros in
-0.0 is an IEEE floating-point concept that only appears in the
(-0n).toString(); // '0' BigInt(-0).toString(); // '0'
The definition of 'BigInt.prototype.toString()' in that specification.
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.