---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Number.prototype.toString()

The **`toString()`** method returns a string representing the specified number value.

## Syntax

```js
toString()
toString(radix)
```

### Parameters

- `radix` _**optional**_
  - : An integer in the range `2` through `36` specifying the base to use for representing the number value. Defaults to 10.

### Return value

A string representing the specified number value.

### Exceptions

- [`RangeError`](../../../globals/RangeError/RangeError.mdx)
  - : Thrown if `radix` is less than 2 or greater than 36.

## Description

The `Number` object overrides the `toString` method of `Object`; it does not inherit
[`Object.prototype.toString()`](../../../globals/Object/prototype/toString.mdx). For `Number` values, the `toString` method returns a string representation of the value in the specified radix.

For radixes above 10, the letters of the alphabet indicate digits greater than 9. For example, for hexadecimal numbers (base 16) `a` through `f` are used.

If the specified number value 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 number value preceded by a `-` sign, **not** the two's complement of the number value.

Both `0` and `-0` have `"0"` as their string representation. [`Infinity`](../../../globals/Infinity.mdx) returns `"Infinity"` and [`NaN`](../../../globals/NaN.mdx) returns `"NaN"`.

If the number is not a whole number, the decimal point `.` is used to separate the decimal places. [Scientific notation](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#exponential) is used if the radix is 10 and the number's magnitude (ignoring sign) is greater than or equal to 10<sup>21</sup> or less than 10<sup>-6</sup>. In this case, the returned string always explicitly specifies the sign of the exponent.

```js
console.log((10 ** 21.5).toString()); // "3.1622776601683794e+21"
console.log((10 ** 21.5).toString(8)); // "526665530627250154000000"
```

The `toString()` method requires its `this` value to be a `Number` primitive or wrapper object. It throws a [`TypeError`](../../../globals/TypeError/TypeError.mdx) for other `this` values without attempting to coerce them to number values.

Because `Number` doesn't have a [`[Symbol.toPrimitive]()`](../../../globals/Symbol/toPrimitive.mdx) method, JavaScript calls the `toString()` method automatically when a `Number` _object_ is used in a context expecting a string, such as in a [template literal](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Template_literals). However, Number _primitive_ values do not consult the `toString()` method to be [coerced to strings](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) — rather, they are directly converted using the same algorithm as the initial `toString()` implementation.

```js
Number.prototype.toString = () => "Overridden";
console.log(`${1}`); // "1"
console.log(`${new Number(1)}`); // "Overridden"
```
