Multiple conditions for one variable in 'if' condition.
e.g
if(x === "dog" || x === "cat" || x === "dog" || x === "lion" || x === "fish"){
console.log('animal');
}
else if (x === "john" || x === "micheal" || x === "daisy" || x === "smith" )
{
console.log('people')
}
Result is true.
But I want to refactor the code like that
if(x==="john"||"micheal"||"daisy"||"smith")
How can be?
Aucun commentaire:
Enregistrer un commentaire