Categories
JavaScript Answers

How to use a case and switch statement with two variables with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.