一、if...else
// if else
var age = 16;
if(0 < age && age <= 6){
console.log("儿童");
}else if(6 < age && age <= 14){
console.log("少年");
}else if(14 < age && age <= 35){
console.log("青年");
}else if(35 < age && age <= 60){
console.log("中年");
}else if(age && age < 60){
console.log("老年");
}else{
console.log("不是年龄段");
}
二、switch...case
// switch case
var key = 3;
switch (key) {
case 1:
console.log("这是1");
break;
case 2:
console.log("这是2");
break;
case 3:
console.log("这是3");
break;
default:
console.log("这是没有符合条件时执行的,等价于else分支");
break;
}