Dart Conditional Expressions:

Jinali GhoghariJinali Ghoghari
1 min read

1. ( condition ? expr1 : expr2):

  • The conditional operator evaluates the condition and returns one of two expressions based on whether the condition is true or false.

  • If the condition is true, expr1 is evaluated and returned; otherwise, expr2 is evaluated and returned.

2. (expr1 ?? expr2) : (null aware)

  • The null-aware conditional operator evaluates expr1. If expr1 is non-null, its value is returned; otherwise, expr2 is evaluated and returned.

0
Subscribe to my newsletter

Read articles from Jinali Ghoghari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jinali Ghoghari
Jinali Ghoghari