In Dart, an expression is a combination of variables, operators, and method invocations that produces a value. Expressions can range from simple arithmetic calculations to complex logical evaluations.
1. Arithmetic Expressions:
var sum = 10 + 5; // Addition
var difference = 10 - 5; // Subtraction
var product = 10 * 5; // Multiplication
var quotient = 10 / 5; // Division
var greeting = 'Hello' + ' ' + 'World'; // Concatenation
var isEqual = (10 == 5); // Equality comparison
var isGreater = (10 > 5); // Greater than comparison
var isTrue = true;
var isFalse = false;
var result = (isTrue && isFalse); // Logical AND
var age = 20;
var isAdult = (age >= 18) ? true : false; // Ternary operator
int add(int a, int b) {
return a + b;
}
var result = add(10, 5); // Function invocation
class Person {
String name;
int age;
}
var person = Person();
person.name = 'Alice'; // Property access
var person = Person()
..name = 'Bob'
..age = 30; // Cascade notation