可能重复:
Is it safe to assume strict comparison in a Javascript switch statement?
javascript中的switch / case语句是比较类型还是只比较值?
换句话说,当我有以下代码时:
switch (variable)
{
case "0": [...] break;
case "1": [...] break;
default: [...] break;
}
等同于
if ( variable == "0" )
{
[...]
}
else if ( variable == "1" )
{
[...]
}
else
{
[...]
}
或
if ( variable === "0" )
{
[...]
}
else if ( variable === "1" )
{
[...]
}
else
{
[...]
}
编辑:有没有办法强制一次比较值和类型?