# Programming in Dart: Fundamentals

## Part 2: Introducing Collections & Null Safety

### Episode complete

Play next episode

Next

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In 2021, Dart was upgraded with a huge feature that would affect every single line of Dart. And that was null safety. It was a huge upgrade and it really comes into play when working with collections. So what is null safety? What is being null? Null means the absence of a value. Lets say you are teacher, writing some code to make correcting grades easier for you. You may create a quiz but how do you know that a student has actually taken the quiz? Well, you could set the quiz value to zero, but that’s an actual grade. So you may next choose a negative number like negative one but what if your data store doesn’t accept negative numbers? After all, you can’t actually have a negative grade? You could solve this problem in a variety of ways but with null, it’s already solved for you.

``````var grades = List<int?>.empty(growable: true);
``````
``````grades.add(100);
``````
``````var total = 0;
``````
``````var firstTest = grades[0];
``````
``````total += firstTest;
``````
``````if (firstTest != null) {
total += firstTest;
}
``````
``````total += grades[1] ?? 0;
``````
``````total += grades[2]!;
``````
``````var average = total / grades.length;
print('The average is \$average');
``````