Javascript Reference - JavaScript String toString() Method








The toString() method returns the value of a String object.

Browser Support

toString() Yes Yes Yes Yes Yes

Syntax

stringObject.toString();

Parameters

None.

Return Value

A string representing the value of a string.





Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--  w w  w  .  j  a va  2 s  .  c  om-->
    var str = "Hello World!";
    var res = str.toString();
    document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>

The code above is rendered as follows: