Data Types in Dart

Learn about the different data types available in the Dart programming language.

Variables

Variables are placeholders to store certain values. Those values can be numbers, booleans, characters, or strings.

Variable names are written using the camel-casing style. Examples of good variable names are: myInt, employeeSalary, totalScore.

⚠️ Warning

Don’t create variables which don’t have any meaning. Variables by themselves should be intuitive!

Examples of bad variable names are: a, num, value.

Data Types

The type of values we can store inside a variable is defined by its data type.

We can create variables of different data types in Dart.

Numbers

Working with numbers in Dart revolve around 3 data types:

  1. int - storing integer values, used for counting, indices, etc.
  2. double - storing floating point numbers or decimals, used for measurements, prices, etc.
  3. num - this is the parent data type for numbers that can hold either an int or a double value.
void main() {
  int intVar = 34;
  double myDouble = 3.14;
  num intOrDouble = 34; // or we can store a double value as well!
}