JavaScript (および他のほとんどのプログラミング言語) では、同じ変数に対して複数の条件をチェックし、各条件に対して同じアクションを実行する場合、if ステートメントを簡潔に記述するのが難しいことに気付きました。このようなシナリオで if ステートメントをより簡潔に書くことは可能ですか?
if(x==1|x==2|x==3){ //Is there any way to make this less verbose?
console.log("X equals either 1 or 2 or 3!");
}
//this isn't syntactically correct, but it's more concise,
//and I wish it were possible to write it more like this
if(x==(1|2|3)){
console.log("X equals either 1 or 2 or 3!");
}