Javascript: "a === b or c"?

javascript, logical-operators

Solution

I don't think there's a shorter or more concise way of doing this in regular JavaScript.

An alternative would be to do a ternary, but this is arguably far less readable, so I would stick with the expression you have.

Ternary:

a === b ? true : a === c

Advised, as in your question

a === b || a === c

Problem

I would like to check whether variable `a` is equal to `b` or `c`. Of course I know the explicit way to do this; ``` a === b || a === c ``` but is there a shorthand way of doing this in Javascript? I mean, for example, ``` a === (b || c) ``` does not work. I found similar questions here Short hand to do something like: if($variable == 1 || $variable == "whatever" || $variable == '492') . PHP: If a equals b or c or d but they are talking about PHP.

Original source

Related problems