Convert a Number to a String in JavaScript
This example shows you two ways to convert a number to a string in JavaScript.
The first way, we use toString()
method. And the second way, we add an empty string to the variable. The code looks like below:
app.js
var age = 18;
var ageString1 = age.toString();
var ageString2 = age + '';
console.log(ageString1, typeof ageString1); // 18 string
console.log(ageString2, typeof ageString2); // 18 string