Sponsored Links
JavaScript Tutorials
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
Tutorials
JavaScriptJavaScript Boolean Object
JavaScript Boolean Object
JavaScript Boolean Object
In this JavaScript tutorial you will learn about JavaScript boolean object, how to pass value to the boolean object, properties and methods used with boolean object.
Usage of the Boolean Object:
The Boolean object is a wrapper for the Boolean data type. The Boolean object is used to convert a non-Boolean value to a Boolean value. If a programmer wants to convert a non-Boolean value to a Boolean value, he can use Boolean as a function to perform this task, instead of using a Boolean object to convert a non-Boolean value to a Boolean value.
The Boolean object returns false when the passed value to the object is any one of the following:
- 0
- ""
- false
- undefined
- NaN
Other than the above values, any other value passed to the Boolean Object returns true. The programmer must clearly understand that a Boolean object is different from Boolean data type.
When an object’s value is not undefined or null (including a Boolean object whose value is false), it evaluates to true when passed to a conditional statement.
For example, the condition in the following if statement evaluates to true:
|
The above concept does not apply for Boolean primitives.
For example, the condition in the following if statement evaluates to false:
|
General Syntax for defining the Boolean Object:
General Syntax for defining the Boolean Object is as follows:
|
Here the keyword new is used to define the Boolean object.
For example:
|
The above example defines a Boolean Object exforsys.
How to pass value to the Boolean object:
The general syntax for writing this is as follows:
|
The above statement creates a Boolean Object given in a variable name with the initial value set to the value passed in arguments of the Boolean. The value can be any one of the following:
0, "", false, undefined, NaN, true, any string and so on.
For example:
|
The above example creates two Boolean objects exforsys and sample with initial value as true.
|
The above example creates two Boolean objects exforsys1 and sample1 with initial value as false.
Comments
Sponsored Links
