Sometimes, we want to use a case and switch statement with two variables with JavaScript.
In this article, we’ll look at how to use a case and switch statement with two variables with JavaScript.
How to use a case and switch statement with two variables with JavaScript?
To use a case and switch statement with two variables with JavaScript, we use switch
with true
.
For instance, we write
switch (true) {
case var1 === true && var2 === true:
//...
break;
case var1 === false && var2 === false:
//...
break;
default:
}
to use switch
with true
.
Then the case
statements can check for any boolean expression.
Conclusion
To use a case and switch statement with two variables with JavaScript, we use switch
with true
.