Understanding Data Types and References
Explore how variables in Dart act as references to objects in memory rather than holding values directly. Learn about key data types including numbers, strings, and booleans, the role of literals, and get introduced to Dart's sound null safety that avoids uninitialized variables, building a strong foundation for stable Dart programming.
We'll cover the following...
The data type of a variable tells us what kind of information that variable can hold. We can find data types all around us. We classify numbers, text, and true or false conditions based on the shared properties they possess.
Variables store references
In Dart, all data types are objects. Because everything is an object, variables do not store the actual value directly inside themselves. Instead, variables store references to objects. A reference is simply a pointer to the location in computer memory where the object is stored.
When we assign a value to a variable, we are giving it a reference to that object. If we assign one variable to another, we are copying the reference, not creating a second physical copy of the object itself.
We can see how this works in the code below.
Line 2: We create a variable named
original. In memory, Dart creates a string object ...