Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | Symbol.replace Property

  • Last Updated : 25 Mar, 2020

The Symbol.replace property in JavaScript is well-known symbol that is used to determine the method that replace the matched substring of a string. This function is called by the String.prototype.replace() method.



Parameters: It accepts single parameter “String”.

Return value: It will return a new string.

Below examples illustrate the Symbol.replace property in JavaScript:

Example 1:

class Replace1 {
    constructor(value) {
        this.value = value;
    [Symbol.replace](string) {
        return `${string} --> ${this.value}`;
            new Replace1('GEEKSFORGEEKS')));
console.log('Article written by '.replace(
            new Replace1('Shubham Singh')));


> "geeksforgeeks --> GEEKSFORGEEKS"
> "Article written by  --> Shubham Singh"

Example 2:

class Replace2 {  
    constructor(value) {  
        this.value = value;  
    [Symbol.replace](string) {  
        return `${string}`;  
var val = new Replace2("geeksforgeeks");  
console.log("Before: " + val.value);  
console.log("After: " + val.value
var val2 = new Replace2("Few Users");  
console.log("Before: " + val2.value);  
console.log("After: " + "Millions of Users"


> "Before: geeksforgeeks"
> "Before: Few Users"
> "After: Millions of Users"

Supported Browsers: The browsers supported by Symbol.replace property are listed below:

  • Google Chrome 51
  • Firefox 50
  • Edge 15
  • Opera
  • Apple Safari


Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!