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
- Booleans and Comparison Operators
- if, else if, and else
- Logical Operators and Short-Circuiting
- The Ternary and switch Expression