JavaScript Booleans

Last Updated Jul 29, 2015, 07:00:14 PM





JavaScript Booleans

Booleans in programming are like Yes or No statements. A booleans statement retuns either of a statement. For example In registration form you might see a check box saying Do you own a car? If you check the box it becomes TRUE otherwise FALSE.

JavaScript boolean statements are used to evaluate to true or false cases

NOTE: Boolean statements does not return any other value other than TRUE or FALSE

Syntax

Any object whose value is not undefined or null, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement. For example, the condition in the following if statement evaluates to true:

Example Try It Now

You can also check the boolean values with the boolean function like below

Try It Now

Boolean Properties and Methods

The global Boolean object contains no methods of its own. However, it does inherit some methods through the prototype chain:

Properties

Boolean.prototype.constructor The boolean property default behavior is to return the function that is created an instance protorype.

Methods

toSource()

The toSource() method returns a string representing the source code of the object.

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web.

Syntax

JavaScript Boolean toString() Method

This methods returns a string valued representation of the object.

Syntax
Example
Try It Now

JavaScript - Boolean valueOf() Method

The valueOf() method returns the primitive value of a Boolean object.

Syntax

This method is usually called internally by JavaScript and not explicitly in code.


Example
Try It Now


Browser compatibility

Feature
Basic support Yes Yes Yes Yes Yes Yes Yes





Sources and Credits

The source of the content has been referred and updated with Mozilla Developer Network and W3C Organization

Last Updated Jul 29, 2015, 07:00:14 PM