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.

ABOUT THE AUTHOR
Ryan Frankel

Ryan Frankel has been a professional in the tech industry for more than 10 years and has been developing websites for more than 15. With his background in integrated circuit design and digital signal processing, he has a fundamental understanding of hardware systems and the software that runs them. Ryan now sits as the CTO of Digital Brands Inc. and manages all of the server infrastructure of their websites, as well as their development team. In addition, Ryan has a passion for guitars, good coffee, and puppies.