In an attempt to better understand switch, I have been playing with the following JS code:
switch(true) {
case false: console.log("1"); break;
case false: console.log("2"); break;
case true : console.log("Unconditional");
case false: console.log("4"); break;
case false: console.log("5"); break;
default: console.log("Default");
}
My output is simply:
Unconditional
4
I'm surprised that the "4" line executed since the relevant case expression was, "false". Similarily, I'm also surprised that the "Default" line didn't execute. (In a similar test with all breaks removed, the Default line did execute.) Can someone please explain what's going on? Thanks.