- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the best way to convert a number to a string in JavaScript?
The best way to convert a number to a string is using the toString() method, with different bases. The method has an optional parameter “radix”, which is used as a base (2, 8, 16) for a numeric value.
Example
You can try to run the following code to convert a number to a string −
<!DOCTYPE html> <html> <body> <script> var num = 10; var val1 = num.toString(); var val2 = num.toString(2); var val3 = num.toString(8); var val4 = num.toString(16); document.write(val1 + "<br>" + val2 + "<br>" + val3 + "<br>" + val4); </script> </body> </html>
Output
10 1010 12 a
- Related Articles
- What is the best way to initialize a JavaScript number?
- What is the best way to initialize a JavaScript Date to midnight?
- What is the best way to concatenate strings in JavaScript?
- What is the best way to handle a Javascript popup using Selenium Webdriver?
- What is the best way to compare two strings in JavaScript?
- What is the best way to add an event in JavaScript?
- What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time in C#?
- Can I extend a JavaScript error? What is the best way to do so?
- What is the best way to reduce and merge a collection of objects – JavaScript?
- What is the easiest way to convert int to string in C++
- What is the best way to read an entire file into a std::string in C++?
- What is the best way to log a Python exception?
- What is the best way to do optional function parameters in JavaScript?
- What is the best way to break from nested loops in JavaScript?
- What is the best way to search for an item in a sorted list in JavaScript?

Advertisements