String Properties

A static property is a property that has the same value for the entire class.

Properties Description
Constructor This property returns a reference to the string function which created the instance prototype.
Length This property returns the length of the string.
Prototype This property is a global property that is available with almost all objects. This allows you to add properties and methods to an object, where the prototyped object has different behavior compared to string primitive auto-boxing.

Example: In this example, we will show the use of ES6 String properties usage.

Javascript




function hero(id, name) {
    this.id = id;
    this.name = name;
}
 
// Object e
let e = new hero(123, "w3wiki");
 
// Object e1
let e1 = new hero(124, "Courses");
 
// This prototype property is constant for all objects.
hero.prototype.group = "Edutech";
 
// Returns object reference
console.log("Constructor Property = " + e.constructor);
 
// Returns length
console.log("Length of emp.name(w3wiki) = " + e.name.length);
 
// Returns the new property(group)
console.log("Prototype(emp1.name=Courses) group = " + e1.group);
 
// Returns the new property(group)
console.log("Prototype(emp.name=w3wiki) group = " + e.group);


Output

Constructor Property = function hero(id, name) {
    this.id = id;
    this.name = name;
}
Length of emp.name(w3wiki) = 13
Prototype(emp1.name=Courses) group = Edutech
Prototype(emp.name=Geeksf...

ES6 String

ES6 string is an object that is used to represent a sequence of characters or manipulate the character’s sequence and It can contain zero or more characters within quotes. The text within the single or double quotes is called a string in Javascript.

Similar Reads

Methods to Create a String in ES6 JavaScript:

There are two ways to create a string in ES6 JavaScript:...

Method 1: Using a String literal

Syntax:...

Method 2: By using String Object

...

String Properties:

This method takes in arguments and creates a new String object....

Methods of String Objects:

...

Contact Us