...

The OR Operator (||)

How would you write a program that tells if today is a weekend? We need to check if it's either Saturday or Sunday:

  • day === "Saturday" checks if it's Saturday.
  • day === "Sunday" checks if it's Sunday.

How can we write an if statement that's true when either condition is true? It's the weekend if day === "Saturday" OR day === "Sunday".

The OR Operator (||)

This is how we can check if day === "Saturday" OR day === "Sunday" using the || operator:

if (day === "Saturday" || day === "Sunday") { ...

The || operator evaluates to true when at least one of the conditions is true. It only evaluates to false when all conditions are false.

Loading...

Output (Console)