The toString() Method

The toString() method returns a number as a string. All number methods can be used on any type of numbers (literals, variables, or expressions):

HTML file: Displayed by browser:
<body>
<p>The toString() method converts a number to a string.</p>
<p id="demo"></p>
<script>
var x = 123;
document.getElementById("demo").innerHTML =
    x.toString() + "<br />" +           // returns 123 from variable x
    (123).toString() + "<br />" +    // returns 123 from literal 123
    (100 + 23).toString();               // returns 123 from expression 100 + 23
</script>
</body>

The toString() method converts a number to a string.


BackTable of ContentsNext