How to convert a number to a string in JavaScript
Learn, how to convert a given number to a string in JavaScript with the help of examples.
Using Number.toString() method
To convert a number to a string, we can use the Number.toString()
method in JavaScript.
Here is an example:
const num = 10;
const string = num.toString();
console.log(string);
Output:
"10"
Similarly, we can also convert the number to string by adding an empty string (''
) in front of a number.
Here is an example
const num = 20;
const string = '' +num;
console.log(string); // "20"
Additional resources
You can also checkout similar tutorials by reading the following: