Reputation: 21
I have a switch statement that is running a formula but it is giving me a result of $0. If I run the same formula in an if statement I get the desired $46. Why isn’t the switch statement giving me the value of $46 but the IF statement is?
Switch Statement
switch (true) {
case ((VS_MTKL.match(/F../)) || (VS_MTKS.match(/M../))):
VO_HOOK_0 = SoS_HFXD;
break;
default:
var VO_HOOK_0 = 0;
break;
}
IF Statement
if ((VS_MTKL.match(/F../)) || (VS_MTKS.match(/M../))) {
VO_HOOK_0 = SoS_HFXD;
} else {
var VO_HOOK_0 = 0;
}
Upvotes: 1
Views: 84
Reputation: 413826
The case
expression values in a switch
are evaluated and then compared as if ===
were used in an if
. The .match()
function returns either null or an array, so it will never be true
. It may be truthy, as an array is in an if
, but that's a different situation.
Upvotes: 4