Home >>JavaScript String Methods >JavaScript String toString() Method

JavaScript String toString() Method

JavaScript String toString() Method

JavaScript toString() method is used to return the value of a given input String object. It is used with a number num using the ‘.’ operator. It converts the num to a string.

Syntax:
string.toString()

Browser Support

Method Chrome Edge Firefox Safari Opera
toString() Yes Yes Yes Yes Yes
Here is an example of toString() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  var str = "PHPTPOINT!!";
  var res = str.toString();
  document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads