Skip to content

三种常用判断

  • if

    javascript
    if () {
      // ...
    } else if () {
      // ...
    } else () {
      // ...
    }
  • 三元运算符

    javascript
    x > 1 ? y++ : null // 为假时什么都不做
    x = y > 1 ? 1 : null // 为假时将 null 赋值给 x
  • switch

    javascript
    switch (x) {
      // 基于 === 比较
      case 1:
        x += 1
        break
      case 2:
        x += 2
        break
      default:
        x += 3
    }