Skip to content
Latest: Publish JavaScript Packages to NPM Like a Pro!

toString() in JavaScript – How to Convert Number to String

toString() converts a number to a string of a specified radix.

toString() accepts only one optional argument. Here is the syntax:

number.toString(radix);

The radix argument specifies the base into which you wish to convert the number.

Below are examples of the toString() method.

(45).toString();
// The invocation above will return: "45"

Try Editing It

Note that the snippet above is equivalent to:

(45).toString(10);
// The invocation above will return: "45"

Try Editing It

(45).toString(2);
// The invocation above will return: "101101"

Try Editing It

(-45).toString(2);
// The invocation above will return: "-101101"

Try Editing It

(45).toString(8);
// The invocation above will return: "55"

Try Editing It

(45).toString(16);
// The invocation above will return: "2d"

Try Editing It

(45).toString(20);
// The invocation above will return: "25"

Try Editing It