Number.prototype.toString()

Returns a string representing the number in the specified radix (base).

Since ES1 Spec ↗

Syntax

num.toString(radix)

Parameters

NameTypeRequiredDescription
radix number No An integer between 2 and 36 giving the base. Defaults to 10.

Returns

string — A string representation of the number in the given base.

Throws

  • RangeError — radix is not between 2 and 36.

Examples

console.log((255).toString(16));
Output
ff
console.log((10).toString(2));
Output
1010

Notes

Commonly used for hex/binary conversion. When calling on a numeric literal use parentheses or a space (`255 .toString(16)`) so the dot is not parsed as a decimal point.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also