Gus*_*ube 3 javascript google-chrome syntax-error switch-statement
当我在Chrome上运行以下代码时,控制台会显示Unexpected identifier异常.
var a = true;
var b = false;
switch (true) {
a:
window.alert('test A');
break;
b:
window.alert('test B');
break;
default:
window.alert('test C');
}
Run Code Online (Sandbox Code Playgroud)
我试图直接在控制台上运行代码,以保证错误不是由我的脚本上的其他行引起的,但我仍然收到异常.
我也通过谷歌寻找答案,但没有找到任何答案这种奇怪的行为.
谢谢.
你不能写b:你必须写case b:
var a = true;
var b = false;
switch (true) {
case a:
window.alert('test A');
break;
case b:
window.alert('test B');
break;
default:
window.alert('test C');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
644 次 |
| 最近记录: |