What does the || operator do?


#1

Question

What does the || operator do?

Answer

The or, ||, operator is used to check if either the left or right operand (the left and right sides of the operator) evaluates to true. If either side of the operand evaluates to true when using this operator, the entire expression evaluates to true.

Example:

console.log(true || false); //will print `true` to the console
console.log(false || false); //will print `false` to the console

//the following if statement will run whatever is in between the curly braces
if(5 == '5' || 4 == 5) {
  //do something
}