The ternary operator is a shorthand for if-else conditions. It’s useful for simple conditional assignments.
The ternary operator condition ? expr1 : expr2 evaluates condition and executes expr1 if the condition is true, otherwise it executes expr2.
void main() {
int score = 85;
// Ternary operator
String result = (score > 90) ? 'Excellent' : 'Good';
print(result); // Output: Good
// Another example with nested ternary operators
result = (score > 90) ? 'Excellent' : (score > 75) ? 'Good' : 'Needs Improvement';
print(result); // Output: Good
}