JavaScript Boolean constructor Property

Below is the example of the Boolean constructor property.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type = "text/javascript"> 
            var bool = false;
            document.write("bool.constructor:" 
                    + bool.constructor); 
    </script>    

    chevron_right

    
    

  • 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.



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
BERJAYA
Example 2: This example illustrates boolean constructor property.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
BERJAYA

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

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

full-stack-img




My Personal Notes arrow_drop_up

BERJAYA
Check out this Author's contributed articles.

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.