跳轉到內容

JavaScript/保留字/else

來自華夏公益教科書,自由的教科書
上一個:double 保留字 下一個:enum

Theelse關鍵字

[編輯 | 編輯原始碼]

Theelse關鍵字在 if 語句中建立了一個子句。它是可選的,僅在所有其他 if … else if 塊不執行時才執行。

程式碼
  var result = 17;

  if (result%2 == 0) {
    console.log(result + " is even.");
  } else if (result > 20) {
    console.log(result + " is greater than 20.");
  } else {
    console.log(result + " is odd and not greater than 20.");
  }
返回以下
17 is odd and not greater than 20.
上一個:double 保留字 下一個:enum
華夏公益教科書