Null safety

Null safety means a type does not accept null unless it is followed by ?. The ?. and ?? operators handle the absence of a value, and ! forces the value but crashes if it is null, so it should be reserved for certain cases. This avoids many runtime errors.

Example

String? surnom;
print(surnom?.length ?? 0);

Related concepts

The whole glossary