Given a number
n = 42
What is the best way to convert it into a string?
s = String(n)
or
s = ''+n
or any better suggestion?
String interpolation might be the most natural approach in CoffeeScript:
s = "#{n}" # Just `'' + n` in disguise.
That might leave people wondering what you're doing though.
I think the best way would be:
(10).toString()
// or
n = 11;
n.toString()
Edited to fix syntax error. 10.toString()
works in the CoffeeScript simulator but it's better to be safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With