//写法一:if(condition){
code to run if condition is true}else{
run some other code instead
}//写法二:if(condition){
code to run if condition is true}
run some other code
//写法三:if(condition) code to run if condition is trueelse run some other code instead
1.2 嵌套if … else
if(condition){
code to run if condition is true}elseif(condition){
code to run if condition is true}else{
run some other code instead
}
2. switch语句
switch(expression){case choice1:
run this code
break;case choice2:
run this code instead
break;// include as many cases as you likedefault:
actually, just run this code
}//default 部分不是必须的,通过它来处理未知的情况。
3. 三元运算符
( condition )? run this code : run this code instead( select.value ==='black')?update('black','white'):update('white','black');//它以测试条件开始select.value === 'black'。如果返回true,运行update()带有黑色和白色参数的函数.//如果返回false,我们运行update()带有白色和黑色参数的函数。