(Shamelessly stolen from reddit)

  • MightBeFluffy@pawb.social
    link
    fedilink
    English
    arrow-up
    23
    ·
    2 days ago

    A ternary is a short hand to assign a value based on a true/false statement

    let a; it(isTtrue) a = 2 else a=9

    Becomes

    let a = (isTrue) ? 2 : 9

    • TJA!@sh.itjust.works
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      2 days ago

      I really like the way kotlin is doing it. The readability of the first one and still a direct assignment.

      var a = if (isTrue) 2 else 9