I recently came across code where a switch statement seemed reversed with the answer (boolean) in the switch and the expressions in the case. The code ran fine as intended but I’m concerned about cross browser. Is it valid javascript?
switch(true) {
case (y < 20):
//
break;
case (y < 60):
//
break;
case (y < 130):
//
break;
}
This snippet is perfectly fine. It’s just another way of expressing: