Dart Operators: Conditional Operators

Dart Operators: Conditional Operators

ยท

1 min read

  • Conditional Operators are one type of alternative option of the the if else condition .
Operator SymbolOperator NameOperator Description
condition ? expersion1 : expersion2Conditional OperatorIt is a simple version of if-else statement. If the condition is true than expersion1 is executed else expersion2 is executed.
expersion1 ?? expersion2Conditional OperatorIf expersion1 is non-null returns its value else returns expression2 value.
//1.
void main()
{
    var a = 15 ;

   (a >10) ? print(true) : print(false); // true

}
void main()
{
var a, b =10 ;

var c = a ?? b;
print(c); //10

}
  • In second example we can see that if a value is null than c will be give " b " value as output but if we assign value to " a " then output will be as " a " value.
ย