Computer >> Computer tutorials >  >> Programming >> Javascript

What are the properties of a boolean object in JavaScript?


The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.

Here is a list of the properties of a Boolean object −

Sr.No
Property & Description
1
constructor
Returns a reference to the Boolean function that created the object.
2
prototype
The prototype property allows you to add properties and methods to an object.

Example

Here’s an example showing the usage of prototype Boolean object −

<html>
   <head>
      <title>JavaScript Boolean objec</title>
      <script>
         function book(title, author) {
            this.title = title;
            this.author = author;
         }
      </script>
   </head>

   <body>
      <script>
         var myBook = new book("WordPress Development", "Amit");
         book.prototype.price = null;
         myBook.price = 500;
         document.write("Book title is : " + myBook.title + "<br>");
         document.write("Book author is : " + myBook.author + "<br>");
         document.write("Book price is : " + myBook.price + "<br>");
      </script>
   </body>
</html>