switch语句判断表达式,将表达式的值与case子句匹配,然后执行与该case相关的语句。
switch(variable_expression) { case constant_expr1: { //statements; break; } case constant_expr2: { //statements; break; } default: { //statements; break; }
switch…case - 流程图
switch…case - 示例
var grade="A"; switch(grade) { case "A": { console.log("Excellent"); break; } case "B": { console.log("Good"); break; } case "C": { console.log("Fair"); break; } case "D": { console.log("Poor"); break; } default: { console.log("Invalid choice"); break; } }
成功执行以上代码后,将显示以下输出。
Excellent
参考链接
https://www.learnfk.com/es6/es6-switch-case-statement.html
标签:case,console,log,无涯,break,switch,statements From: https://blog.51cto.com/u_14033984/9494766