Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | global Property

  • Last Updated : 12 Apr, 2021

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. 
 

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!

html




<!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: 
 

global

Example 2: This example checks if the regular expression contains g Modifier or not. 
 

html




<!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 = /[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: 
 

global

Supported Browsers: The browsers supported by JavaScript global Property are listed below: 
 

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!