Symbol.toStringTag JavaScript

The JavaScript Symbol.toStringTag property creates the default string description of an object. The Object.prototype.toString() method internally use it. Syntax: Symbol.toStringTag Example 1: <!DOCTYPE html> <html> <body> <script> class obj {get [Symbol.toStringTag]() { return ‘HELLO’; } } document.write(Object.prototype.toString.call(new obj())); </script> </body> </html> Example 2: <!DOCTYPE html> <html> <body> <script> class TestDisplay { get [Symbol.toStringTag]() { return … Read more

Symbol.split JavaScript

The JavaScript Symbol.split property splits a part of the string from the indices that match the specified regular expression. Syntax: Symbol.split(string) Parameters: string: It represents the string. Returns: It returns a string that is split from the specified expression. Example 1: <!DOCTYPE html> <html> <body> <script> class obj { constructor(a) { this.a = a; } … Read more

Symbol.search JavaScript

The JavaScript Symbol.search property finds out the index within a string that matches with the regular expression. Syntax: [Symbol.search](string) Parameters: string: It represents the string that matches against the regular expression. Returns: Index of the specified string with a match. Example 1: <!DOCTYPE html> <html> <body> <script> class obj { constructor(a) { this.a = a; … Read more

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

Symbol.prototype JavaScript

The JavaScript Symbol.prototype property gives a prototype for the symbol constructor. Symbol.prototype is the parent of all Symbol objects. Syntax: Symbol.prototype Returns: Prototype for the symbol constructor. Example 1: <!DOCTYPE html> <html> <body> <script> var alpha = Symbol(‘HELLO’); Symbol.prototype.toString = function() { return (‘HELLO WORLD!’); } document.write(alpha.toString()); </script> </body> </html> Example 2: <!DOCTYPE html> <html> … Read more

Symbol.match JavaScript JS

The JavaScript Symbol.match property looks for the matching of a regular expression against a string. Syntax: Symbol.match Parameters: string: It represents the string. Returns: It returns true if a regular expression matches against a string, otherwise, it returns true. Example 1: <!DOCTYPE html> <html> <body> <script> var alpha = /HELLO WORLD/; alpha[Symbol.match] = false; document.write(‘/HELLO … Read more

Symbol.isConcatSpreadable JavaScript

The JavaScript Symbol.isConcatSpreadable property determines if an object should be flattened to its array elements or not. Syntax: Array_name[symbol.isConcatSpredable] = true/false Returns: Symbol corresponding to a specific key. Example 1: <!DOCTYPE html> <html> <body> <script> var alpha = [‘X’, ‘Y’, ‘Z’]; var beta = [‘A’, ‘B’, ‘C’]; beta[Symbol.isConcatSpreadable] = true; var Display = alpha.concat(beta); document.write(Display); … Read more

Symbol.hasInstance JavaScript

The JavaScript Symbol.hasInstance property finds out that a constructor object recognizes an object as its instance or not. Syntax: [Symbol.hasInstance] (object) Parameters: object: It represents the specific object to be checked as a symbol instance. Returns: It returns true if the object is an instance of a symbol, otherwise returns false. Example 1: <!DOCTYPE html> … Read more

JavaScript Symbol.toString() method

The JavaScript Symbol.toString() method retrieves a string representation of an object. Syntax: Symbol.toString(); Returns: String representation of a symbol object. Example: <!DOCTYPE html> <html> <body> <script> var alpha = Symbol.for(“a”); document.write(alpha.toString(alpha)); </script> </body> </html>

JavaScript Symbol.keyFor() method

The JavaScript Symbol.keyFor() method is used to search for the key of a global symbol. It returns undefined if the symbol is not found. Syntax: Symbol.keyFor(symbol); Parameters: symbol: It represents the specific symbol for which the key has to be fine. Returns: Key corresponding to a specific symbol. Example 1: <!DOCTYPE html> <html> <body> <script> … Read more