How to convert an Integer into a string in Javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to convert an Integer into a string in Javascript?

I tried researching here in Javascript but it only shows the conversion from String into an Integer. Is there a way to convert an Integer into a String? parseStr() and parseString() wont work :/

31st Oct 2019, 5:09 AM
Name Omitted until I come back
2 Answers
+ 4
There are a lot of ways. The most simple one would be to just add an empty string to the variable, e.g. var str = number + ""; or var str = "" + number; With ES6, using a template literal is also possible: var str = '${number}'; The most obvious and direct way would be an explicit conversion, either through the toString() method, or the constructor: var str = number.toString(); var str = String( number ); I'd favor the toString() method though, as it communicates its intend in the best way, making it easier to read for others.
31st Oct 2019, 5:39 AM
Shadow
Shadow - avatar
- 2
Can anyone help me with this code:”hello world!”?
1st Nov 2019, 3:40 PM
Madison Robinson
Madison Robinson - avatar