# Using Javascript booleans

## Using Javascript booleans.

• The boolean datatype has only two possible values which is true or false.
• The boolean value is for the most the result of comparisons you make in your JavaScript programs.
• Any program code is meant to do some actions based on conditions.
• These conditions is normally based on an evaluation of values using relational operators which in Javascript are:
Operator Example Comments
==
(equality)
``````'50'==50 // true
30 ==50 // false``````
Returns true when both operands are equal. The operands are converted to the same type before being compared.
!=
(non-equality)
``````'50'!=50 // false
30 !=50 // true``````
Returns true when both operands are not equal. The operands are converted to the same type before being compared.
===
(equality)
``````'50'===50 // false
50 ===50 // true``````
Returns true if both operands are equal and of the same type.
!==
(non-equality)
``````'50'!==50 // true
50 !==50 // false``````
Returns true if both operands are not equal and of the same type.
>
(greater than)
``````'50'>40 // true
50 >50 // false``````
Returns true if the left operand is greater than the right one.
>=
(greater than or equal)
``````'50'>=50 // true
30 >=50 // false``````
Returns true if the left operand is greater than or equal to the right one.
<
(less than)
``````'50'<40 // false
50 <50 // false``````
Returns true if the left operand is greater than the right one.
<=
(less than or equal)
``````'50'<=50 // false
50 <=50 // true``````
Returns true if the left operand is greater than or equal to the right one.
• In such evaluation we can use some Logical Operators as well:
Name Operator Sample Description
AND && expession1 && expression2 Both expressions must return true if the outcome shall be true
OR || expession1 || expression2 One of the expressions must return true if the outcome shall be true
NOT ! !expression If the expression return false the outcome will be true

© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.