Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript String constructor Property

Improve Article
Save Article
  • Last Updated : 04 Jan, 2023
Improve Article
Save Article

The String constructor property in JavaScript is used to return the string constructor function for the object. The function which is returned by this property is just the reference to this function, not a string containing the function’s name. The JavaScript number constructor, string constructor, and boolean constructor return function Number() { [native code] }, function String() { [native code] } and function Boolean() { [native code] } respectively.

Syntax: 

string.constructor

Return Value: function String() { [native code] }

Below are examples of the String constructor Property. 

Example 1: This example shows the basic use of the String constructor Property in Javascript.

Javascript




<script>
    function func() { 
    var str = 'Geeks for Geeks'
    var value = str.constructor; 
    console.log(value); 
    
    func(); 
</script>

Output:  

function String() { [native code] }

Example 2: This example uses the String constructor Property of Javascript.

html




<h1 style="color:green">
    Welcome to GeeksforGeeks
</h1>
  
<p>
    Click the button to see string
    constructor property.
</p>
  
<button onclick="myGeeks()">
    click me
</button>
  
<p id="GFG"></p>
  
<script>
    function myGeeks() {
        var str = "Hello World!";
          
        document.getElementById("GFG").innerHTML
                = str.constructor;
    }
</script>

Output: 

 

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browsers: The browser supported by the String constructor property are listed below.

  • Google Chrome 1 and above
  • Edge 12 and above
  • Apple Safari 1 and above
  • Firefox 1 and above
  • Opera 3 and above
  • Internet Explorer 3 and above

We have a Cheat Sheet on JavaScript where we covered all the important topics of JavaScript to check those please go through JavaScript Cheat Sheet – A Basic Guide to JavaScript.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!