Javascript 利用 switch 语句进行范围判断

const x = 6;
switch (true) {
    case (x < 5):
        alert("less than five");
        break;
    case (x < 9):
        alert("between 5 and 8");
        break;
    case (x < 12):
        alert("between 9 and 11");
        break;
    default:
        alert("none");
        break;
}
原文地址:https://www.cnblogs.com/niuben/p/12049336.html