It is commonly known that
typeof null
returns "object".
However, I have a piece of code that looks like this:
switch(typeof null){
case "object":
1;
default:
3;
}
This code returns 3.
Why does "object" as returned by typeof null not cause the first branch of the case statement to be executed?
You're missing break for the first case - so it falls through to the default case and returns 3.
switch(typeof null){
case "object":
1;
break;
default:
3;
}
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