Open In App

JavaScript Symbol match Property

Last Updated : 19 May, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

JavaScript Symbol match property is used to identify the matching of a regular expression against a string and this function is called using String match() method.

Syntax:

regexp[Symbol.match] = false;

Parameters: It does not accept any parameters. 

Return value: It will return the Boolean value for a string matching if matches found then it will return true otherwise returns false. Below examples illustrate the Symbol.match property in JavaScript.

Below examples illustrate the JavaScript Symbol match Property:

Example 1: In this example, we will check if a string starts with a particular expression defined in regexp

javascript




const regexp1 = /geeksforgeeks/;
  
regexp1[Symbol.match] = false;
  
console.log('/geeks/'.startsWith(regexp1));
console.log('/geeksforgeeks/'.endsWith(regexp1));


Output:

false
true

Example 2: In this example, we will pass a regular expression and see the type of error returned. 

javascript




reg[Symbol.match] = false;  
  
console.log('/bar/'.startsWith(/bar/));


Output:

Error: First argument to String.prototype.startsWith must not be a regular expression.

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

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

We have a complete list of Javascript symbols’ properties and methods, to check those please go through the Javascript Symbol Complete Reference article.


Master DSA with JavaScript in just 90 days. Explore core DSA concepts, refine your coding skills, and tackle real-world challenges. Take on the Three 90 Challenge—complete 90% of the course in 90 days and earn a 90% refund as a reward for your commitment!


Next Article

Similar Reads

Difference Between Symbol.iterator and Symbol.asyncIterator in JavaScript
JavaScript offers powerful mechanisms for handling iteration through objects, especially with the introduction of symbols like Symbol.iterator and Symbol.asyncIterator. These symbols play important roles in defining how objects are iterated over, whether synchronously or asynchronously. In this article, we will explore the differences between Symbo
3 min read
JavaScript Symbol constructor Property
JavaScript Symbol constructor property is used to return the Symbol constructor function for the object. The function returned by this property is just the reference, not the actual WeakSet. It is an object property of JavaScript and can be used with Strings, Numbers, etc. Syntax: symbol.constructor Below examples will illustrate the Symbol Constru
1 min read
JavaScript Symbol description Property
JavaScript symbol description is an inbuilt property in JavaScript that is used to return the optional description of the specified symbol objects. Syntax: Here "A" is the specified symbol object which might be Symbol('anyValues'), Symbol.iterator, Symbol.for('anyValues') etc. A.description;Parameters: This property does not accept any parameter. R
1 min read
JavaScript Symbol isConcatSpreadable Property
JavaScript Symbol.isConcatSpreadable is a well-known symbol used to configure if a given object should be flattened to its array elements while using the Array.prototype.concat() method. Syntax: Array[Symbol.isConcatSpreadable]Here Array is the array object which is to be flattened to its array elements. Parameters: This symbol does not accept any
2 min read
JavaScript Symbol toStringTag Property
The Symbol.toStringTag is a well-known symbol and string-valued property in JavaScript which is used in the creation of the default string description of an object. Syntax: Symbol.toStringTagParameters: This does not take any parameter. Return value: This returns the String Object. Example 1: In this example, we will use Symbol toStringTag Propert
1 min read
JavaScript Symbol hasInstance Property
JavaScript Symbol hasInstance is used to determine if a given constructor object recognizes the object as its instance. Syntax: [Symbol.hasInstance](Object) Parameters: It accepts a parameter "object". Return value: This returns true if the value is in the chain of the object otherwise false.JavaScript code to show the working of this function. Bel
1 min read
JavaScript Symbol unscopables Property
The Symbol.unscopables property in Javascript is a well-known symbol that is used to specify an object value of whose own and inherited property names are excluded from the environment bindings. Syntax: object[Symbol.unscopables] Property attributes: This property holds an Object and it is not Writable, Enumerable and Configurable. Return value:
2 min read
JavaScript Symbol split Property
JavaScript Symbol split property is used to specify the method that splits a string at the indices that match a regular expression. This property is called by the String.split() method. Syntax: [Symbol.split](string) Property attributes: It accepts a "String" which is not Writable, Enumerable, and Configurable. Return value: It returns a string tha
2 min read
JavaScript Symbol search Property
JavaScript Symbol search property determines the method that returns the index within a string that matches the regular expression. This function is called by the String search() method. Syntax: [Symbol.search](string) Parameters: It accepts single parameter "String". Return value: This returns the position of a string where it matches and if not m
1 min read
JavaScript Symbol replace Property
JavaScript Symbol replace the property is used to determine the method that replaces the matched substring of a string. This function is called by the String replace() method. Syntax: [Symbol.replace](string) Parameters: It accepts single parameter "String". Return value: It will return a new string. The below examples illustrate the Symbol.replace
2 min read
  翻译: