JavaScript String constructor Property
Last Updated :
16 Jul, 2024
Improve
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] }
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();
6
1
function func() {
2
let str = 'Geeks for Geeks';
3
let value = str.constructor;
4
console.log(value);
5
}
6
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()
6
1
function myGeeks() {
2
let str = "Hello World!";
3
4
console.log(str.constructor);
5
}
6
myGeeks()
Output
[Function: String]
Supported Browsers:
The browser supported by the String constructor property are listed below.
- Google Chrome 1
- Edge 12
- Apple Safari 1
- Firefox 1
- Opera 3