Contents

Roo

The ternary operator

The ternary operator lets us write a if...else construct in a shorter way:

var a = 1 > 2 ? 3 : 4 # => 4

# The above is the same as:
var a
 if 1 > 2 {
    a = 3
} else {
    a = 4
}

The syntax is: (condition) ? (value if truthy) : (value if falsey).