switch(type)
{
    case 'home':
         console.log('home switch');
         break;
}

The above code does not write out to the console, neither does the following:

switch(type)
{
     case "home":
         console.log('home switch');
         break;
}

The following, however, does:

if (type == 'home')
{
     console.log('home if');
}

I don't have a clue why. This isn't a show-stopper, I can use the if statement instead, but I'm genuinely curious as to why this is the case.

NOTE: These statements are a straight replace, nothing else to consider here. No change in scope, no code I'm not mentioning that could be interfering with the value of type.

有帮助吗?

解决方案

That's not the equivalent if-statement. The switch statement is specified to use the strict equality === operator.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top