mercredi 15 mars 2017

How do I test if a JS variable does equal either of two values?

Is there a short way to test if a variable is equal to two string, in plain JS5?

My code is like:

var type = 'display'
if (type === 'display' || type === 'filter') { ... }

Is there a way to make shorter, like:

if ( type === ('display' || 'filter') ) { ... }

Aucun commentaire:

Enregistrer un commentaire