mercredi 12 juin 2019

Is there a way in javascript to avoid repeating the same variable in a logic expression? [duplicate]

This question already has an answer here:

For example, instead of:

if (ext === "_st" || ext ==="_mt" || ext === "_00" ){
   //do something
}

I would intuitively expect that the following also works:

if (ext === ("_st" || "_mt" || "_00" )){
    //do something
}

But that doesn't work. Is there a way to avoid repeating the same ("ext" in this case) variable for more compressed and efficient code?

Aucun commentaire:

Enregistrer un commentaire