Logical Operators
Three logical operators are available for use in JavaScript namely, Not (!), Or (||) and And
(&&). The results of operations that involve these operators are Boolean (true or false).
The results of these operations are computed in accordance with the following:
AND (&&) Binary operator
Both the conditions must be true
OR (||)
Binary operator
At least one of the conditions must be true
NOT (!)
Unary operator
The value of the condition determined is complemented.
For example,
‘Red’ != ‘Blue’ && 5 > 1 = ‘true’
‘Red’ != ‘Blue’ && 5 < 1 = ‘false’
‘Red’ == ‘Blue’ && 5 < 1 = ‘false’
For conditional operators, JavaScript uses short-circuit evaluation. In other words, if the
value of the first condition is computed to be ‘false’, the system does not evaluate the
other condition and directly presents the result.
Do'stlaringiz bilan baham: |