JavaScript String toString() method : The toString() method to return the string object, means we can simply say that it is used to casting the primitive object to the.
Syntax of toString() method :
string.toString()
Example of toString() method :
<!DOCTYPE html>
<html>
<body>
<p>To return the value of the string object, click on button.</p>
<button onclick="castToString()">Show String</button>
<p id="container"></p>
<script>
function castToString() {
var msg = "Hey! how are you?";
var result = msg.toString();
document.getElementById("container").innerHTML = result;
}
</script>
</body>
</html>
Output : Hey! how are you?
0 Comment(s)