Yes, case statements in JavaScript can contain multiple values, allowing checking for multiple similar values or contiguous ranges of values in a single branch.

Can a case statement in JavaScript contain multiple values?
Answer: Yes
Details:
JavaScript case statements allow inclusion in a single case branch Multiple values. This syntax can be used in the following situations:
Syntax:
<code class="javascript">switch (expression) {
case value1:
case value2:
// 执行代码
break;
default:
// 处理其他值
}</code>Example:
Check whether the value of a numeric variable is between 1 and 5 Interval:
<code class="javascript">switch (number) {
case 1:
case 2:
case 3:
case 4:
case 5:
console.log("数字在 1 到 5 之间");
break;
default:
console.log("数字不在 1 到 5 之间");
}</code>Note:
The above is the detailed content of Can case write two values in js?. For more information, please follow other related articles on the PHP Chinese website!