Logical operators
Overview
The operators available in Javascript are shown in the table below.
Name | Usage | Evaluates to |
---|---|---|
AND | a && b | true if a and b are both true , otherwise false |
OR | a || b | true if a is true or b is true (or both), otherwise false |
NOT | !a | the opposite of a (false if a is true ; true if a is false ) |
Using the operators
Here are some examples of using the operators:
js
const isBookAvailable = false
const hasOverdueBooks = true
console.log(!isBookAvailable) // NOT
console.log(isBookAvailable && hasOverdueBooks) // AND
console.log(isBookAvailable || hasOverdueBooks) // OR
console
true
false
true