String valueOf() Method - Javascript String

Javascript examples for String:valueOf

Description

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

Parameters

None

Return Value:

A String, representing the primitive value of a string

The following code shows how to Return the primitive value of a string object:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from ww w .j av  a2 s  .com
    var str = "Hello World!";
    var res = str.valueOf();
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials