0Pricing
Dart Academy · Lesson

The Ternary and switch Expression

Pick values concisely without long if-chains.

Picking Values Concisely

Long if-chains can clutter your code. Dart offers shorter ways to choose a value based on a condition. Let us meet them. ✂️

The Ternary Operator

The ternary reads as condition ? valueIfTrue : valueIfFalse. It is a compact if-else that produces one of two values.

String label = isOn ? "On" : "Off";

All lessons in this course

  1. Booleans and Comparison Operators
  2. if, else if, and else
  3. Logical Operators and Short-Circuiting
  4. The Ternary and switch Expression
← Back to Dart Academy