Logical Operators
Working with conditions means using booleans,
true
orfalse
values. In JavaScript there are operators that work with boolean values known as logocal operators.There are three logical operators:
the and operator
&&
the or operator
||
the not operator, otherwise known as the bang operator
!
&&
operator:
&&
operator:When using &&
operator, we are checking both sides to evaluate to true for the entire condition to evaluate to true
and execute, otherwise the else
block will execute.
Example:
Example:
||
operator:
||
operator:When using the ||
operator only one side of condition needs to be true
for the overall statement to evaluate to true
.
Example:
!
operator:
!
operator:The !
not operator reverses or negates the values of a boolean.
Example:
Last updated