Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Boolean Constructor Property

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 28 Mar, 2023
Improve Article
Save Article
Like Article

JavaScript boolean constructor property returns the constructor function for an object. The function which is returned by this property is just the reference to this function, not a Boolean containing the function’s name The JavaScript number constructor, string constructor, and boolean constructor return function Boolean() { [native code] }, function Number() { [native code] }, and function String() { [native code] } respectively.
Syntax:  

boolean.constructor

Parameter: This method does not accept any parameter. 

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

Below are examples of the Boolean constructor property:

Example 1: 

javascript




function func() {
    var bool = false;
    var value = bool.constructor;
    console.log(value);
}
func();


Output: 

ƒ Boolean() { [native code] }

Example 2: This example illustrates boolean constructor property. 

html




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


Output: 

JavaScript Boolean constructor Property

JavaScript Boolean constructor Property

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

  • Google Chrome 1 and above
  • Internet Explorer 3 and above
  • Mozilla Firefox 1 and above
  • Safari 1 and above
  • Opera 4 and above

We have a complete list of Javascript Boolean methods, to check those please go through the Javascript Boolean Complete Reference article.


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!