Conditional operators

When using logical operators in an IF statement, is there any shorthand for comparing a variable to multiple possible values?

if (base === "G" || base === "C")

In this example I want to evaluate if base === G or C. Although this may not be very time consuming to type out for two comparisons I can see it becoming impractical when more possible values need to be compared.

The only shorter way I can think of for larger scales is to add values to an array and then use array.includes. Is the the only/best way?

I believe the way you mentioned with an array would be the easiest for if statements, however you could also use a switch statement which may accomplish what you are looking for, if not always being the prettiest.

let tester = 2 // if statement if (tester == 1 || tester == 2 || tester == 3 || tester == 4 || tester == 5) { console.log('success!') } // switch statement switch(tester) { case 1: case 2: case 3: case 4: case 5: console.log('success!') break }

We can see that upon changing the value of tester above, both the if and the switch still work, however it’s slightly faster to type a new case than it is to type a new condition in your if statement. Really though, the different is minor, and what I actually did was copy tester == 1 || and then just paste it several times, then change the number on each. Sometimes with code there’s no quick way to write something, and that’s when copy paste comes in handy.