JavaScript | global Property
The global Property in JavaScript is used to specify whether the “g” modifier is set or not. If the “g” modifier is set than this property returns true else false.
Syntax:
RegexObj.global
Return Value: It returns true if g modifier is set, else false.
Example 1: This example checks if the regular expression contains g Modifier or not.
<!DOCTYPE html> <html> <head> <title>global Property</title> </head> <body style="text-align:center"> <h1 style="color:green">GeeksforGeeks</h1> <h2>global Property</h2> <button onclick="geek()">Click it!</button> <script> function geek() { var regex = new RegExp('foo', 'g'); alert(regex.global); } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Example 2: This example checks if the regular expression contains g Modifier or not.
<!DOCTYPE html> <html> <head> <title> source Property </title> </head> <body style="text-align:center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2> source Property </h2> <button onclick="geek()"> Click it! </button> <script> function geek() { var regex = /[a-d]/; var str = "GeeksforGeeks\n"+ "is the computer\n"+ "science portal for geeks."; if (regex.global) { alert("g Modifier is present"); } else { alert("g Modifier is absent."); } } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browsers supported by JavaScript source Property are listed below:
- Google Chrome
- Apple Safari
- Mozilla Firefox
- Opera
- Internet Explorer
Recommended Posts:
- Global and Local variables in JavaScript
- How to change the value of a global variable inside of a function using JavaScript ?
- JavaScript | Infinity Property
- JavaScript | Error name Property
- JavaScript | Math.PI Property
- Javascript | MouseEvent which Property
- JavaScript | source Property
- JavaScript | lastIndex Property
- How to remove CSS property using JavaScript?
- JavaScript | Math.LN2 property
- JavaScript | multiline Property
- JavaScript | undefined Property
- JavaScript | Cursor property
- JavaScript | arrayBuffer.byteLength property
- JavaScript | Math.SQRT2 property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



