JS的流程控制
分支结构
- if-else
- switch-case
swith (score){
case 1:{
}
break;
case 2{} break;
default:{
}
}
循环语句
- while
- for (var i =1;i<100;i++){}
中断和跳转
- break
- continue 继续
异常
throw “ throw it error ”
函数
- 常用函数
function yourfunctionName(name){
//todo funciton
return name;
}
- 用函数表达式定义函数
var outputAge=funciton(age){
console.log("马云 is" +age);
}
outputAge(25);//结果是马云 is 25
var mathFunc=function mathF(a) {
var res=a;
a--;
if (a>0) {
res*= matchFunc(a)
}
return res;
};
var mathRes=mathFunc(5)
console.log(mathRes) // 5*4*3*2*1=120