jeudi 23 août 2018

In JavaScript, how do you check "a" against "b," "c," etc. in a simple manner?

Currently, the only way I know of to do what the title states is by writing the following:

var a = 3, b = 5, c = 3;
if (a === b && a === c) {
  // code
}

Or by using the ternary operator:

(a === b && a === c) ? /* code */ : /* else */

Is there a way to check a against both b and c? Something like this perhaps:

if (a === (b && c)) {
  // code
}

Obviously this doesn't work as intended, which is why I'm asking the question. Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire