Operators in Dart: Chapter Overview

Operators teaches you to work with values.

In this chapter, you will:

  • do maths with + - * /, plus ~/ for whole parts and % for remainders
  • compare values and join conditions with &&, || and !
  • learn how Dart stops the "empty box" crash with null safety
  • use ?., ??, ??= and !, and know when each one is safe

What each lesson covers:

  • Operators: Arithmetic, increment, comparison, logical, assignment, type and bitwise operators, the ternary operator, and the order Dart works them out.
  • Null Safety: What null is, how Dart stops null crashes, nullable types, the operators ?. ?? ??= and !, and late variables.

This chapter has 2 lessons. Plan on about 34 minutes, with 6 exercises to check what you learned. Every example is real Dart code: change it, run it again and compare the output, which is the fastest way to learn how each feature behaves.

Simple lesson: finish this chapter and you can calculate, compare, and handle missing values without crashes.

Lessons in this section

  1. Operators

    Arithmetic, increment, comparison, logical, assignment, type and bitwise operators, the ternary operator, and the order Dart works them out.

    • Do maths with + - * / ~/ and %
    • Compare values and combine conditions with && || and !
    • Use assignment operators, the ternary operator and parentheses
  2. Null Safety

    What null is, how Dart stops null crashes, nullable types, the operators ?. ?? ??= and !, and late variables.

    • Tell nullable and non-nullable types apart
    • Use ?. ?? ??= and ! correctly
    • Use late, and avoid the common null mistakes