JavaScript Number toString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

number.toString(radix) returns a string for the number. Omit radix for base 10. Pass a radix from 2 to 36 to print binary, hex, or other bases. Digits above 9 use letters a–z.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call number.toString. Start with this line.

JavaScript
n.toString() / n.toString(radix)
CallWhat it does
n.toString() / n.toString(radix)Primary signature.
number.toString(...)Call with the arguments your case needs.

Built into JavaScript. Call toString(...) on a number (or Number instance) — no import required.

Library declarations
JavaScript
n.toString() / n.toString(radix)

Parameters

ParameterDescription
radixOptional. Base 2–36 (default 10)

Return Value

Return ValueDescription
*Always a string

JavaScript Examples

Example 1 — Decimal, Binary, and Hex

Omit radix for decimal; pass 2 or 16 for other bases.

JavaScript
console.log((17).toString());      // "17"
console.log((6).toString(2));      // "110"
console.log((254).toString(16));   // "fe"
console.log(typeof (17).toString()); // "string"
Try It Yourself

How It Works

  1. Default base 10. (17).toString() is the everyday decimal string.
  2. Binary. 6 in base 2 is 110.
  3. Hex lowercase. 254 becomes "fe" — letters are lowercase.
  4. String type. The return value is always "string".

Example 2 — Negative Numbers Keep the Minus

Negatives are not two’s complement — just a leading -.

JavaScript
console.log((-10).toString(2));    // "-1010"
console.log((-255).toString(16));  // "-ff"
console.log((0).toString(2));      // "0"
console.log((-0).toString(2));     // "0"
Try It Yourself

How It Works

  1. Sign first. Convert the absolute value, then prefix - if negative.
  2. Same for hex. -255 → "-ff", not a padded two’s-complement word.
  3. Zero. Both 0 and -0 format as "0".
  4. Bit patterns. For fixed-width two’s complement, use bitwise ops or typed arrays — not toString.

Example 3 — Convert Bases with parseInt

Parse one base, then print another — a common round trip.

JavaScript
console.log(Number.parseInt("FF", 16).toString(2));  // "11111111"
console.log(Number.parseInt("1010", 2).toString(10)); // "10"
console.log((255).toString(16));                       // "ff"
Try It Yourself

How It Works

  1. Parse hex. Number.parseInt("FF", 16) yields the number 255.
  2. Print binary. .toString(2) turns that into "11111111".
  3. Binary → decimal. Parse with radix 2, print with radix 10 (or omit).
  4. Direct print. You can also call toString(16) on a number you already have.

Browser & Runtime Support

Number.prototype.toString() is part of early ECMAScript and is Baseline Widely available in modern browsers and Node.js.

✓ Baseline · Long-standing

Number.toString()

Supported in Chrome, Firefox, Safari, Edge, and Node.js for years. Safe for modern apps without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
toString Excellent

Bottom line: Use n.toString(radix) freely for decimal display and base conversion.

Frequently Asked Questions

Number.prototype.toString() returns a string representing the number. With no argument it uses base 10. Pass an optional radix from 2 to 36 to print the number in that base (for example 2 for binary, 16 for hexadecimal).
radix is an integer from 2 through 36 that sets the numeric base. Digits above 9 use letters a–z (for example hex uses a–f). If you omit radix, JavaScript uses 10. Values outside 2–36 throw a RangeError.
The leading minus sign is kept. Even in binary, you get a string like "-1010" — not two's complement. Both 0 and -0 become "0".
For radix 10 only, if the magnitude is >= 1e21 or < 1e-6, the string uses exponential form such as "3.1622776601683794e+21". Other radices use a normal digit expansion.
toString() picks a short distinguishing representation and can use scientific notation. toFixed() and toPrecision() let you control decimal places or significant digits. Use String(n) or n + "" for a simple decimal string without calling the method explicitly.
It is part of the ECMAScript language from early editions and is Baseline Widely available — safe in every modern browser and Node.js.

Next: toExponential()

Learn how to format numbers in scientific notation every time.

toExponential() 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.

9 people found this page helpful