0

Is there a concise or better way to write this condition without having to use so many ||.

if (myVar != 'A' && myVar != 'B' && myVar != 'C'){
   ...
}
PhantomQuest
  • 349
  • 4
  • 12

1 Answers1

1

You can also express it like an array,

if (!['A', 'B', 'C'].includes(myVar)) {
  // if myVar is none of the values in the array
}

edit: added negation to grab the opposite case as your example

Ignacio
  • 1,056
  • 8
  • 17