AND and OR Operators

The AND && and OR || operators are used in JavaScript to combine two or more conditions to produce a single boolean result.

The AND operator returns true if all conditions it is combining are true. For example:

Loading Code . . .

In the code above, the canBuyAlcohol variable is assigned true if age is greater than or equal to 21 and hasID is true. Since age is only 18, canBuyAlcohol is assigned false.

The OR operator, on the other hand, returns true if at least one of the conditions is true. For example:

Loading Code . . .

In the code above, the isCatOrDog variable is assigned true if animal is equal to cat or dog. Since animal is equal to dog, isCatOrDog is assigned true.


In the exercise below, select all the options that will make the condition evaluate to true.

Loading Code . . .

© 2024 - ®Mewters