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 returns function Number() { [native code] }, function String() { [native code] } and function Boolean() { [native code] } respectively.
Syntax:
string.constructor
Return Value: function String() { [native code] }
Example:
<!DOCTYPE html> <html> <head> <title> JavaScript String constructor Property </title> </head> <body> <h2> Welcome to GeeksforGeeks </h2> <p> Click the button to see string contructor property. </p> <button onclick="myGeeks()"> click me </button> <p id="GFG"></p> <!--Script to use string constructor property--> <script> function myGeeks() { var str = "Hello World!"; document.getElementById("GFG").innerHTML = str.constructor; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browser supported by String constructor property are listed below:
- Google Chrome
- Apple Safari
- Firefox
- Opera
- Edge
Recommended Posts:
- JavaScript | Number constructor Property
- JavaScript | Date constructor Property
- JavaScript | Boolean constructor Property
- JavaScript | Array constructor Property
- JavaScript | RegExp constructor
- JavaScript | Array prototype Constructor
- Sort array of objects by string property value in JavaScript
- JavaScript | Check if a string is a valid JSON string
- JavaScript | Difference between String.slice and String.substring
- JavaScript | Insert a string at position X of another string
- How to count string occurrence in string using JavaScript?
- JavaScript | multiline Property
- JavaScript | Error name Property
- JavaScript | source Property
- JavaScript | lastIndex Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



