||) performs a disjunction on two boolean expressions. It evaluates to true if at least one of the operands is true; otherwise, it evaluates to false.
Syntax
Truth Table
| Operand A | Operand B | Result |
|---|---|---|
true | true | true |
true | false | true |
false | true | true |
false | false | false |
Short-Circuit Evaluation
The|| operator evaluates operands from left to right and employs short-circuit logic.
- Left Operand Evaluation: The left operand is evaluated first.
- Short-Circuiting: If the left operand resolves to
true, the entire expression immediately resolves totrue. The right operand is not evaluated, and any side effects (such as function calls or variable assignments) contained within the right operand are skipped. - Right Operand Evaluation: If the left operand resolves to
false, the right operand is evaluated, and its result determines the final value of the expression.
Type Constraints
Dart is a strongly typed language. Both operands of the|| operator must be of type bool. Unlike languages with “truthy” or “falsy” coercion (e.g., JavaScript), Dart throws a compile-time error if non-boolean types (such as int or String) are used as operands.
Operator Precedence
The|| operator has lower precedence than the logical AND operator (&&) and equality operators (==, !=). In complex expressions without parentheses, && operations are evaluated before || operations.
Master Dart with Deep Grasping Methodology!Learn More





