JavaScript: int to string

JavaScript: int to string

Every built-in JavaScript object type has a toString() method. This method is automatically called when the object needs to be represented as a string value (i.e., when you concatenate some string value with a number), or it can be called manually when such a type conversion is wanted.

The toString() method works on all of the standard JS objects: arrays, dates, numbers, errors, et cetera. For number types, the toString() method also can take an optional “radix” argument: number.toString(radix)

The radix (or base) is the total number of unique digits, including zero, that are used to represent a particular number system. For number systems other than the decimal system, you can use the radix argument to correctly stringify a number from some other number system, such as the octal (base 8) and hexadecimal (base 16) number systems.

Here are some examples of the toString() method being used on numbers:

There isn’t really much more to using toString() on numbers in JavaScript. As always, if you have any questions, ask away in a comment below.