gpt4 book ai didi

javascript - switch 语句中的 bool 运算符?

转载 作者:数据小太阳 更新时间:2023-10-29 04:23:24 25 4
gpt4 key购买 nike

有什么方法可以在句法上使用 switch 来实现吗?

switch(i){
case ('foo' || 'bar'):
alert('foo or bar');
break;
default:
alert('not foo or bar');
}

最佳答案

switch(i){
case 'foo':
case 'bar':
alert('foo or bar');
break;
case 'other':
default:
alert('other');
}

注意:“其他”不是必需的,我只是展示您也可以使用默认值堆叠案例。

关于javascript - switch 语句中的 bool 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3225805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com