Understanding Data Types and References
Explore how Dart variables reference objects in memory and the distinction between variables and literals. Understand core data types including numbers, strings, and booleans, and grasp the concept of empty references with null safety. This lesson lays the foundation for writing stable, predictable Dart code by mastering data types and references.
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 ...