Answer the question
In order to leave comments, you need to log in
Constants in a JavaScript switch statement?
I recently started learning JavaScript and I'm having trouble with the switch construct. I can’t figure out the constants in the switch construction, tell me if it’s possible to do this:
switch(x) {
case x >= 20 && x < 60:
console.log("Option 1.");
break;
case x > 60:
console.log("Option 2.");
break;
case x < 20:
console.log("Option 3.");
break;
default:
console.log("Invalid option.");
}
or is a constant always an integer or a string? and how then to use the comparison operators in this example?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question