Check if Variable is equal to Multiple Values in JavaScript-Code Examples

Radu TM

Check if Variable is equal to Multiple Values in JavaScript

JavaScript by Radu TM June 22, 2022

// check if a variable is equal to multiple values

const value = '🍎';

if (value === '🍎' || value === '🍌' || value === '🍇') {
  console.log('The value is either an apple, a banana, or a grape.');
}

0

23.538

Check if Variable is equal to Multiple Values in JavaScript

JavaScript by Radu TM June 22, 2022

if (variable === 'value1' || variable === 'value2' || variable === 'value3') {
  // do something
}

0

23.538

Check if Variable Doesn't Equal Multiple Values in JS

JavaScript by Radu TM June 21, 2022

let val = "😃"

// check if val doesn't equal "😐" or "😶"
if (val !== "😐" && val !== "😶") {
  console.log("val is not a neutral emoji!")
}

0

10.616

Check if Variable Doesn't Equal Multiple Values in JS

JavaScript by Radu TM June 21, 2022

const animal = '😋'

if (!['🐶', '🐱', '🐭'].includes(animal)) {
  console.log('not a pet');
} else {
  console.log('is a pet');
}

0

10.616

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories