Search This Blog

Sunday, 31 July 2016

How to convert string to object in javascript?

Html page:

<p id="P10"></p>

Javascript page:

<script>
    var x = "John";              // x is a string
    var y = new String("John");  // y is an object
    document.getElementById("demo").innerHTML =
typeof x + "<br>" + typeof y;
</script>

Output:
string

object

No comments:

Post a Comment