We now have a youtube channel. Subscribe!

How to implement the JavaScript Boolean Properties with examples


Hello! morning to you all, trust you guys are having a wonderful day. I want to welcome you all to this new section of my tutorial on JavaScript. In my previous tutorial we discussed about JavaScript  Boolean Object with examples.

In this tutorial, we will be using few examples to demonstrate the properties of Boolean object.

Boolean constructor() Method

JavaScript boolean constructor() method returns a reference to the Boolean function that created the instance's prototype.

Syntax

Use the following syntax to create a Boolean constructor() method.

boolean.constructor()

Return Value

Returns the function that created this object's instance.

Example

Try the following example.

<html>
     <head>
          <title>JavaScript constructor() Method</title>
     </head>

     <body>
          <script type = "text/Javascript">
               var  bool = new Boolean();
               document.write("bool.constructor() is : " + bool.constructor);         
          </script>
     </body>
</html> 

Output

Below is the output of the above example.

bool.constructor() is : function Boolean() { [native code] }       

You can also read our tutorial post on: How to create Html Forms


Object - prototype

The prototype property allows you to add properties and methods to any object(Number, Boolean, String and Date etc.).

Note - Prototype is a global property which is available with almost all the objects.

Syntax
It's syntax is as follows -

object.prototype.name = value

Example
Try the following example.

<html>
     <head>
          <title>User-defined objects</title>
          <script  type = "text/Javascript">
               function book(title,  author)  {
                    this.title = title;
                    this.author = author; 
               }
          </script> 
     </head>

     <body>
          <script type = "text/Javascript">
               var  myBook = new book("Java", "Kennedy");
               book.prototype.price = null;
               myBook.price = 400;
               
               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> 

Output
Below is the output of the above example.

Book title is : Java
Book author is : Kennedy
Book price is : 400

Alright guys, we have come to the end of this tutorial post on JavaScript Boolean properties. In our next tutorial post we will be using few examples to illustrate JavaScript Boolean Methods.

Follow us on our various social media platforms to stay updated with our latest tutorials, also feel free to ask your questions via the comment box below. Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain