We can convert from Number to String by String
, toString
, Type Coercion or Template String.
Version
ECMAScript 2015
String
let x = 123
String (x) // ?
String
is a constructor function to create a Wrapper Object bynew
String
is a normal function to convert from Number to String
toString
let x = 123
x.toString () // ?
We can also to use Number.prototype.toString
to convert from Number to String.
Type Coercion
let x = 123
x + '' // ?
When using Number + String, Number is converted to String first. So we can use +
Empty String to Convert from Number to String.
Template String
let x = 123;
`${x}` // ?
We can also use Template String to convert from Number to String.
Conclusion
String
andtoString
is the most intuitive way to convert from Number to String- Template String is another concise way to convert from Number to String