JavaScript Number toString()

The syntax of the toString() method is:

num.toString(radix)

Here, num is a number.


Number toString() Parameters

The toString() method takes in:

  • radix (optional) - An integer between 2 to 36 specifying the base to use for representing numeric values such as 2 (binary), 8 (octal), 16 (hexadecimal).

Note: If argument is less than 2 or greater than 32, a RangeError is thrown


Return value from Number toString()

  • Returns a string representing the given Number object in the specified radix(10 by default).

Example: Using toString()

Output

2512
9d0
-1010
-5.645

Recommended Readings: