Skip to Content
Dart📘 Ngôn ngữ DartToán tử logic (Logical Operators)

Toán tử logic (Logical Operators) trong Dart

1. AND Operator (&&)

var age = 25; var hasLicense = true; if (age >= 18 && hasLicense) { print('Can drive'); }

2. OR Operator (||)

var isWeekend = true; var isHoliday = false; if (isWeekend || isHoliday) { print('Day off!'); }

3. NOT Operator (!)

var isRaining = false; if (!isRaining) { print('Go outside'); }

4. Combining Operators

var age = 25; var hasLicense = true; var hasInsurance = false; if (age >= 18 && hasLicense && !hasInsurance) { print('Need insurance'); }

5. Short-circuit Evaluation

var result1 = false && expensiveCheck(); // Không gọi expensiveCheck() var result2 = true || expensiveCheck(); // Không gọi expensiveCheck()

📝 Tóm tắt

  • && - AND (cả hai true)
  • || - OR (một trong hai true)
  • ! - NOT (đảo ngược)
  • Short-circuit evaluation
  • Thứ tự: ! > && > ||
Last updated on