所以我有一些代码:
var Animal = 'Giraffe';
switch (Animal) {
case 'Cow':
case 'Giraffe':
case 'Dog':
case 'Pig':
console.log('This animal will go on Noah\'s Ark.');
break;
case 'Dinosaur':
default:
console.log('This animal will not.');
}
理想情况下,我希望第一个 console.log 打印“This Giraffe will go on Noah's Ark”,或者任何变量 Animal 碰巧是什么。我想引用一下这个案例。但是,我不确定如何编写该代码。有人可以帮忙吗?
最佳答案
只需对 log
和 Animal
使用附加参数即可。
console.log('This', Animal, 'will go on Noah\'s Ark.');
关于javascript - 在 Javascript 中使用 switch 语句处理多个 case 时,如何引用一个 case?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742855/