vendredi 31 janvier 2020

How to check if a variable equals one of two values if a clean manner in JS [duplicate]

To check if x variable is equal to 1 or 2, i would do normally something like:

if (x === 1 || x === 2){
   // ....
}

but this can get in some cases very cumbersome.

Edit :I'm working right now on this and writing the fonction name every time i think can be done in a cleaner manner:

if (
      this.getNotificationStatus() === 'denied' ||
      this.getNotificationStatus() === 'blocked'
    )

Is there any other lighter way to write this?

THANKS

Aucun commentaire:

Enregistrer un commentaire