Carrot reference
Operators

?: (elvis)

Evaluates the truthiness of the first expression, and returns its value if that value is truthy. If the value of the first expression is not truthy, it returns the value of the second expression.

Syntax

condition ?: ifFalse

  • condition - the conditional expression to be evaluated for truthiness.
  • ifFalse - the expression to be evaluated if condition is not found to be truthy.

Sample usage

name.pref ?: name.first returns someone's preferred first name if available, otherwise returns their formal first name.

See also



Updated 19 Dec 2023
Doc contributor
Did this page help you?