Skip to content
Related Articles

Related Articles

Improve Article
JavaScript Boolean constructor Property
  • Last Updated : 27 Jun, 2020

Below is the example of the Boolean constructor property.

  • Example:




    <script type = "text/javascript"
            var bool = false;
            document.write("bool.constructor:" 
                    + bool.constructor); 
    </script>     
  • Output:
    bool.constructor:function Boolean() { [native code] }

In JavaScript, the boolean constructor property returns the constructor function for an object. For JavaScript Boolean, the constructor property returns function Boolean() { [native code] }.

Syntax:

boolean.constructor

Return value: It returns the function Boolean() { [native code] }.

More example codes for the above property are as follows:
Example 1: This example illustrates boolean constructor property.






<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript Boolean constructor Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <div>
              
        <h1 style="color: green;">GeeksforGeeks</h1>
                  
        <p>
            JavaScript Boolean constructor Property
            returns the function that created
            the boolean's prototype:
        </p>
                  
        <b id="GFG"></b>
          
    </div>
      
    <!-- Script to use boolean constructor -->
    <script>
        var bool = false;
        document.getElementById("GFG").innerHTML
                = bool.constructor;
    </script>
</body>
  
</html>                     

Output:

Example 2: This example illustrates boolean constructor property.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript Boolean constructor Property
    </title>
</head>
  
<body style="text-align:center;">
  
    <div>
              
        <h1 style="color: green;">GeeksforGeeks</h1>
                  
        <p>
            JavaScript Boolean constructor Property
            returns the function that created
            the boolean's prototype:
        </p>
        <button onclick="gfg()">Click me</button>
        <p id="name"></p>
    </div>
      
    <!-- Script to use Boolean constructor Property -->
    <script>
    function gfg(){
        var bool = false;
        document.getElementById("name").innerHTML
                = bool.constructor;
    }
    </script>
</body>
  
</html>         

Output:

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

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :