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