The operator or ||

The freecodecamp curriculum offers only one exemple where the operator ‘or’ (which symboled like this|| ) is used in the chalenge . Can anybody offer other exemples using the if statement and operator ‘or’ || (not hard or complicated exemple please as i’m still at beginner level ).
Thank you

The or operator is not that hard to understand, if you can get past the strange syntax.
This code checks if name is equal to ‘John’ or ‘David’. If it is, it logs it to the console.

var name = 'John'

if(name === 'John' || name === 'David') {
1 Like

If either the thing on the left of || or the thing on the right of ||, then the “or” expression is true.

if (animalType = 'cat' || animalType = 'dog') {
    console.log("That is common a pet.");

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.