Possible Duplicate:
Is it safe to assume strict comparison in a Javascript switch statement?
Does a switch/case statement in javascript compare types or only values?
In other words, when I have the following code:
switch (variable)
{
case "0": [...] break;
case "1": [...] break;
default: [...] break;
}
is it equivalent to
if ( variable == "0" )
{
[...]
}
else if ( variable == "1" )
{
[...]
}
else
{
[...]
}
or to
if ( variable === "0" )
{
[...]
}
else if ( variable === "1" )
{
[...]
}
else
{
[...]
}
edit: is there a way to force compare values and types at once?
Yes, types are compared.
If input is equal to clauseSelector as defined by the === operator, then set found to true.
ECMA-262, page 95.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With