Open In App

JavaScript String constructor Property

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.




function func() {
    let str = 'Geeks for Geeks';
    let value = str.constructor;
    console.log(value);
}
func();

Output:  

function String() { [native code] }

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




function myGeeks() {
    let str = "Hello World!";
 
    console.log(str.constructor);
}
myGeeks()

Output
[Function: String]

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.

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.

Article Tags :