Search⌘ K
AI Features

Logical Operators

Explore the use of logical operators in Dart, including AND, OR, and NOT. Understand reduction rules and how short-circuit evaluation optimizes performance, enabling you to write efficient and safe conditional statements.

Types of logical operators

Logical operators perform operations such as the logical AND and logical OR. They take bool operands and always yield a bool result.

Below is a list of the logical operators supported by Dart.

Operator

Name

Use

!

Logical NOT

Reverses the logical state of its operand. If a condition is true, this unary operator evaluates to false.

||

Logical OR

Evaluates to true if at least one of the two operands is true.

&&

Logical AND

Evaluates to true only if both operands are true.

.

The logical NOT (!) is a unary operator, meaning it takes only one operand. The logical OR and AND operators require two operands.

Reduction rules

We can predict the outcome of complex expressions by understanding how Dart reduces logical operations. In the rules below, expr represents an arbitrary expression that evaluates to a bool.

  • !true evaluates to false ...