Is it valid JavaScript to nest an if/else in a switch?
Yes, it is perfectly valid. Have you tried it?
You can combine a switch
and an if
in a better way, if you really have to:
switch (true) {
case (foo === 'bar' && raz === 'something'):
// execute
break;
case (foo === 'bar'):
// do something else
break;
default:
// yada yada
}
Sorry to revive such an old post, but it may help people who came here looking how to combine or nest a switch
and an if
statement.