I read in the 'Professional JavaScript for Web Developers' by Nicholas Zakas in p.78 of 3rd edition (last one I think):
The switch statement compares values using the identically equal operator, so no type coercion occurs (for example the string "10" is not equal to the number 10).
I made up some simple switch statement just to confirm and the result was different:
var num = "9";
switch (true) {
case num < 0:
alert("less than 0");
break;
case num >= 0 && num <10:
alert("between 0 and 10");
break;
default:
alert("False");
}
https://jsfiddle.net/pbxyvjyf/
So, type coercion is done: the alert("between 0 and 10")
is chosen.
Have the rules changed or am I doing something wrong?