Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

js variable comparison. Short version

i need to compare a variable with multiple values

let test = 'e'
if(test == 'q' || test == 'w' || test == 'e') console.log('TEST')

Can you make this entry shorter?

I present it this way, but it is not correct.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let test = 'e'
if(test == 'q' || 'w' || 'e') console.log('TEST')

>Solution :

You can use an array:

const test = 'e'
if (['q', 'w', 'e'].includes(test)) {
  console.log('TEST');
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading