Symbol.replace JavaScript

The JavaScript Symbol.replace property eliminates the matched substring of a string. Syntax: [Symbol.replace](string) Parameters: Source string. Returns: Modified string. Example 1: <!DOCTYPE html> <html> <body> <script> class obj { constructor(a) { this.a = a; } [Symbol.replace](string) { return `${string}`; } } var display =new obj(“HELLO”); document.writeln(display.a); document.writeln(“WORLD!”.replace(display.a)); </script> </body> </html> Example 2: <!DOCTYPE html> <html> … Read more