[JavaScript] Converting Values to strings WITHOUT toString? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[JavaScript] Converting Values to strings WITHOUT toString?

I've tried this a few times. But I've never successfully converted a given value to a string WITHOUT toString. Can anybody help me? Send me your code with comments please.

10th Aug 2018, 6:46 PM
Daniel Cooper
Daniel Cooper - avatar
5 Answers
+ 1
What's wrong with toString? Just curious. Anyways, there are a couple other methods you can use. You can simply put "" prior to it and it'll convert it automatically (Example: "" + myNumVar) You can encompass it inside of String(). (Example: String(myNumVar)) And you can use toString as you already know. That's only ways I can think of off the top of my head. Hope that helps.
10th Aug 2018, 7:00 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
Why don’t you want to use toString()? Is it some assignment requirement?
10th Aug 2018, 6:58 PM
TurtleShell
TurtleShell - avatar
0
Just something I came up with one day. Lol.
10th Aug 2018, 7:01 PM
Daniel Cooper
Daniel Cooper - avatar
0
while n>0: s=chr(48+n%10)+s n//=10
10th Aug 2018, 10:00 PM
VcC
VcC - avatar
0
var num = 123; var str = "" + num; // converted number to string
10th Aug 2018, 10:45 PM
Calviղ
Calviղ - avatar