基礎 -> 略
省略為三元運算寫法 (Ternary Operator)
var count = 10;
// if else
if(count > 5){
console.log('higher than 5')
}else{
console.log('lower than 5')
}
// if else
Ternary Operator
count > 5 ? console.log('higher than 5') : console.log('lower than 5')
Switch 用法
// single case
var test = 0;
switch (test) {
case 5:
console.log('5');
break;
case 2:
console.log('excute here');
break;
default:
console.log('default');
}
// mutl case
var test = 0;
switch (test) {
case 1:
case 2:
case 0:
case 4:
console.log('excute here');
break;
case '10':
default:
console.log('not excute here');
}
falsy values: 在邏輯判斷中,其結果與 false 相等, 但其數值實際上並非 false
ex : undefined, null, 0, '', NaN
truthy values: 不為 falsy values 的值
var test; // undefined, null, 0, '', NaN
if(test){
}else{
// excute here
}
Coding Challenge 2
三場比賽的平均得分比較 -> 略
新手練功中, 歡迎指教、點評~
課程 : https://www.udemy.com/course/the-complete-javascript-course/
來源 :
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/switch
https://amobiz.github.io/2015/09/28/javascript-truthy-falsy/