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 NowYou can also check the boolean values with the boolean function like below
Try It NowBoolean 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.
JavaScript Boolean toString() Method
This methods returns a string valued representation of the object.
SyntaxExample
Try It Now
JavaScript - Boolean valueOf() Method
The valueOf() method returns the primitive value of a Boolean object.
SyntaxThis 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
Complete Beginner to JavaScript Developer - Udemy
Advanced JavaScript Development - Udemy
Learn javascript in one month from experts -OneMonth
Become a Certified Web Developer - Udemy