Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | Symbol.match Property

  • Last Updated : 25 Mar, 2020

The Symbol.match property in JavaScript is a well-known symbol which is used to identify the matching of a regular expression against a string and this function is called using String.prototype.match() method.

Syntax:

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!

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:

Example 1:




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

Output:

false
true

Example 2: This example returns the TypeError.




    
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

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match

My Personal Notes arrow_drop_up
Recommended Articles
Page :