converting a number into string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TheKeith

    #1

    converting a number into string

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

    Thanks


  • Lee

    #2
    Re: converting a number into string

    TheKeith said:[color=blue]
    >
    >can you convert a number into a string by simply adding a set of quotes like
    >this: 5 + ""[/color]

    Yes.

    alert((5+"").ch arAt(0))

    Comment

    • Evertjan.

      #3
      Re: converting a number into string

      Lee wrote on 24 okt 2003 in comp.lang.javas cript:[color=blue]
      > alert((5+"").ch arAt(0))[/color]

      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)

      Comment

      Working...