- Conditional Operators are one type of alternative option of the the if else condition .
Operator Symbol | Operator Name | Operator Description |
condition ? expersion1 : expersion2 | Conditional Operator | It is a simple version of if-else statement. If the condition is true than expersion1 is executed else expersion2 is executed. |
expersion1 ?? expersion2 | Conditional Operator | If 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.
ย