JavaScript BigInt toString() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Instance method

Definition

toString() turns a BigInt into a string of digits. By default it writes the number in base 10, our everyday digits. Pass a radix (the number base) from 2 to 36 to get binary (2), hexadecimal (16), or even base 36, which uses the digits 0-9 and the letters a-z. The string has no trailing n: (10n).toString() is "10". Because a BigInt holds every digit exactly, even a 30-digit number comes out exactly right.

Remember
(255n).toString();        // "255"
(255n).toString(2);       // "11111111"
(255n).toString(16);      // "ff"
(-255n).toString(16);     // "-ff"
String(10n);              // "10" (no trailing n)
(10n).toString(37);       // RangeError (radix must be 2 to 36)

Syntax

Call it on a BigInt value. The radix is optional and defaults to 10.

JavaScript
bigint.toString()
bigint.toString(radix)
CallWhat it does
big.toString()Writes the value in base 10: (2n ** 64n).toString() is "18446744073709551616".
big.toString(2)Binary: only the digits 0 and 1. Handy for looking at bits and flags.
big.toString(16)Hexadecimal with lowercase letters, as used for hashes, colors, and memory addresses.
big.toString(36)Base 36 uses 0-9 and a-z, which makes short IDs out of big numbers.
String(big)Gives the same text as big.toString(), and also works for null and undefined without throwing.

Part of BigInt since ES2020. JavaScript calls toString() for you when you join a BigInt with a string ("id: " + 5n is "id: 5") or put it in a template literal. 5n.toString() is valid syntax; with a plain number, 5.toString() is a syntax error because the dot is read as a decimal point.

Library declarations
JavaScript
bigint.toString(radix)   // returns a string

// radix: a whole number from 2 to 36 (optional, default 10)
//        anything else throws a RangeError
// The result never ends with "n"; negative values start with "-".

Parameters

ParameterDescription
radixOptional. The base to write the number in, from 2 to 36. Leave it out for base 10. A radix such as 1 or 37 throws a RangeError. Letters for digits above 9 are lowercase.

Return Value

Return ValueDescription
StringThe digits of the BigInt in the chosen base, with a leading - for negative values and no trailing n. To read it back, pass a base-10 string to BigInt(), or add a prefix such as "0x" for hex: BigInt("0xff") is 255n.

JavaScript Examples

Example 1 — One BigInt in Four Number Bases

The radix argument picks the number base. Print 255 in four bases, then a negative value, then try an invalid radix.

JavaScript
const n = 255n;

console.log(n.toString());          // 255
console.log(n.toString(2));         // 11111111
console.log(n.toString(16));        // ff
console.log(n.toString(36));        // 73
console.log((-255n).toString(16));  // -ff

try {
  n.toString(37);
} catch (e) {
  console.log(e.name);              // RangeError
}
Try It Yourself

How It Works

  1. No radix means base 10. n.toString() returns "255", the plain digits without the BigInt n.
  2. Other bases rewrite the same value. 255 is eight 1-bits in binary, ff in hex, and 73 in base 36 (7 × 36 + 3). A negative BigInt keeps its minus sign: -ff.
  3. The radix has limits. Only 2 to 36 are allowed, because there are just 10 digits plus 26 letters. toString(37) throws a RangeError.

Example 2 — Print 25! and 2100 Exactly

A factorial grows very fast. With BigInt, toString() prints every digit of 25! and of 2100 in hex, and padStart() makes fixed-width binary.

JavaScript
let factorial = 1n;
for (let i = 1n; i <= 25n; i++) factorial *= i;

const digits = factorial.toString();
console.log(digits);                               // 15511210043330985984000000
console.log(digits.length + " digits");            // 26 digits
console.log((2n ** 100n).toString(16));            // 10000000000000000000000000
console.log((5n).toString(2).padStart(8, "0"));    // 00000101
Try It Yourself

How It Works

  1. Multiply 1n through 25n. The loop counter is a BigInt too (1n, 25n), because BigInts and Numbers cannot be mixed in *=.
  2. The string is exact and measurable. toString() gives all 26 digits of 25!. A Number would print 1.5511210043330986e+25 and lose the rest. Since the result is a string, .length counts the digits.
  3. Hex and padded binary. 2100 in base 16 is a 1 followed by 25 zeros. For bit flags, padStart(8, "0") pads the binary text of 5 to a full byte: 00000101.

Example 3 — Join With Text and Send a BigInt as JSON

Large IDs often travel as JSON. JSON.stringify() refuses BigInts, so convert them to strings with toString() first.

JavaScript
const id = 1234567890123456789n;

console.log(id.toString());                  // 1234567890123456789
console.log(String(id) === id.toString());   // true
console.log("id: " + id);                    // id: 1234567890123456789

try {
  JSON.stringify({ id: id });
} catch (e) {
  console.log(e.name);                       // TypeError
}

const json = JSON.stringify({ id: id.toString() });
console.log(json);                           // {"id":"1234567890123456789"}
console.log(BigInt(JSON.parse(json).id) === id);   // true
Try It Yourself

How It Works

  1. Three ways give the same text. id.toString(), String(id), and joining with a string all produce the digits without an n.
  2. JSON throws on a raw BigInt. JSON has no BigInt type, so JSON.stringify({ id: id }) throws a TypeError (Node.js and Chrome say Do not know how to serialize a BigInt).
  3. Send a string, read it back. Storing id.toString() makes valid JSON. After JSON.parse(), BigInt() turns the string back into the identical BigInt, so the round trip prints true.

Browser & Runtime Support

BigInt.prototype.toString() arrived in ES2020 with the BigInt type. The radix rules match Number.prototype.toString().

✓ Baseline · ES2020

BigInt.prototype.toString()

Works in all modern browsers and in Node.js 10.4 and later, Deno, and Bun. Results are identical everywhere, because the digits are fully defined by the language.

96% Modern browser support
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Modern versions · Chromium
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Internet Explorer No BigInt type
Not supported
Node.js Node 10.4 and later · checked on Node 24
Supported
Deno All releases
Supported
Bun All releases
Supported
BigInt.prototype.toString() Excellent

Bottom line: Safe to use anywhere BigInt exists. Only the error messages (for example for a bad radix or for JSON) are worded differently between browsers, so check e.name rather than the message.

Frequently Asked Questions

Call big.toString() or String(big). Both return the digits without the trailing n, so (10n).toString() is "10".
The n only marks a BigInt in source code and in the developer console. The string form of the value is just the digits, which is what toString(), String(), and string joining return.
Pass a radix: big.toString(16) gives lowercase hexadecimal and big.toString(2) gives binary. Use padStart() if you need a fixed width, for example (5n).toString(2).padStart(8, "0").
Convert it to a string first, for example JSON.stringify({ id: id.toString() }). A raw BigInt makes JSON.stringify throw a TypeError. After JSON.parse, turn the string back with BigInt().
Whole numbers from 2 to 36. The default is 10. Anything outside that range, such as 1 or 37, throws a RangeError.

Next: valueOf()

Learn when JavaScript calls valueOf() for you, and how to unwrap a BigInt object.

valueOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful