By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,527 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,527 IT Pros & Developers. It's quick & easy.

converting a number into string

P: n/a
can you convert a number into a string by simply adding a set of quotes like
this: 5 + ""

Thanks
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
TheKeith said:

can you convert a number into a string by simply adding a set of quotes like
this: 5 + ""


Yes.

alert((5+"").charAt(0))

Jul 20 '05 #2

P: n/a
Lee wrote on 24 okt 2003 in comp.lang.javascript:
alert((5+"").charAt(0))


This part of js is not very intuitive, please test thoroughly:
<script>

x = 5 + ""
alert(x) // 5 string

x = x + x
alert(x) // 55 string

y = x + x * 7
alert(y) // 55385 string

y = x * 7 + x
alert(y) // 38555 string

y = y + 1
alert(y) // 385551 string

y = x * 7 + x * 1
alert(y) // 440 number!

y = y + 1
alert(y) // 441 number!
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.