Introduction:
A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator.
&&(AND) Operator:
The && operator accepts multiple arguments and it mainly does the following:
- Evaluates the operands from left to right
- For each operand, it will first convert it to a Boolean. If the result is false, stops and returns the original value of that operand.
- otherwise, if all were truthy it will return the last truthy value.
||(OR) Operator:
The ‘OR’ operator is somewhat opposite of ‘AND’ operator. It does the following:
- evaluates the operand from left to right.
- For each operand, it will first convert it to a Boolean. If the result is true, stops and returns the original value of that operand.
- otherwise, if all the values are falsy, it will return the last value.
!(NOT) Operator:
It reverses the Boolean result of the operand (or condition). The operator converted the value ‘1’ to Boolean and it resulted in ‘true’ then after it flipped(inversed) that value and that’s why when we finally alert the value we get ‘false’.
The following operator accepts only one argument and does the following:
- Converts the operand to Boolean type i.e. true/false
- returns the flipped value
Supported Browser:
- Google Chrome
- Microsoft Edge
- Firefox
- Opera
- Safari