# Data Types in Dart

Dart supports mainly nine types of data type. They are represented in a very simple and concise manner. Data types can be categorized into two main groups: primitive types and non-primitive types (also known as reference types). Let's explore both categories:

## Primitive Data Types in Dart

Primitive types in Dart are basic data types that represent single values. They are immutable, and their values are stored directly in memory. Dart provides several primitive types, including:

1. **int** - Represents integers. (e.g., `int age = 25;`).
    
2. **double** - Represents floating-point numbers. (e.g., `double price = 19.99;`).
    
3. **String:** Represents a sequence of characters. (e.g., `String name = "John";`).
    
4. **bool** - Represents a Boolean value. (`true` or `false`, e.g., `bool isStudent = true;`).
    

### Example

```dart
int age = 25; // age is an integer with a value of 25
age = 30; // Now age is 30, and the old value (25) is replaced.
```

```dart
String name = "John"; // name is a string with the value "John"
name = "Alice"; // Now name is "Alice," and the old value ("John") is replaced.
```

When you assign a new value to a variable of a primitive type, it replaces the previous value.

## Non-Primitive Data Types in Dart

Non-primitive types represent more complex data structures and store references to the data. When you assign a non-primitive variable to a new value, you change the reference to the data, not the data itself.

1. **List** - Represents a collection of variables. (Array). (e.g., `List<int> numbers = [1, 2, 3];`).
    
2. **Map** - Represents a collection of key-value pairs. (e.g., `Map<String, dynamic> person = {'name': 'Alice', 'age': 30};`).
    
3. **Set** - Represents an unordered collection of unique values. (e.g., `Set<String> colors = {'red', 'green', 'blue'};`).
    
4. **Symbol** - Represents an operator or identifier. (e.g., `Symbol mySymbol = #example;`).
    
5. **Function** - You can also use data types to represent functions. (e.g., `Function myFunction = () => print('Hello, Dart!');`).
    
6. **Runes** - Represents a sequence of Unicode characters. (e.g., `Runes heart = '\u2665';`).
    
7. **null** - Represent the absence of a value.
    
8. **dynamic** - Represents a variable whose type is not known at compile time.
    

### Example

```dart
List<int> numbers = [1, 2, 3]; // numbers is a list of integers.
numbers.add(4); // You modify the list by adding a new number (4).
```

```dart
Map<String, dynamic> person = {'name': 'Alice', 'age': 30};
person['age'] = 31; // You modify the map by changing the 'age' value to 31.
```

In summary, primitive types store values directly, and when you change the value, you replace the old value. Non-primitive types store references to data structures, and when you change them, you modify the data structure itself. Understanding this difference is crucial when working with Dart, especially in cases where you need to manage and manipulate data structures.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>NOTE:-</strong>&nbsp;Although Dart is strongly typed, type annotations are optional because Dart&nbsp;<strong>can infer types</strong>.</div>
</div>

That’s all you need to know about data types in the dart. Feel free to let me know if I missed something. I’d love to learn that.

Till then Keep Loving, Keep Coding.

> Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">I have written a different article for Map and List. Check them as well for more information on Data types. Subscribe to My Newsletter For More Such Content...</div>
</div>

Jai Hind, Vande Mataram 🇮🇳

### Do you know how many types of hackers are there?

%[https://youtu.be/s0zW8v7CBW4?si=M29hNBP6h-7iq_QZ] 

### **Learn More about Dart and Flutter**

* [List in Dart](https://jaytillu.com/blogs/list-in-dart)
    
* [Abstract Class and Abstract Method in Dart](https://jaytillu.com/blogs/abstract-classes-and-abstract-methods-in-dart)
    
* [Inheritance in Dart](https://jaytillu.com/blogs/interface-in-dart)
    
* [Constructors in Dart](https://jaytillu.com/blogs/constructors-in-dart)
    
* [Classes and Objects in Dart](https://jaytillu.com/blogs/classes-and-objects-in-dart)
    
* [Arrow Functions in Dart](https://jaytillu.com/blogs/arrow-functions-in-dart)
    
* [User-Defined Functions in Dart](https://jaytillu.com/blogs/user-defined-function-in-dart)
    
* [Functions in Dart](https://jaytillu.com/blogs/functions-in-dart)
    
* [Switch Case in Dart](https://jaytillu.com/blogs/switch-case-in-dart)
    
* [Conditionals in Dart](https://jaytillu.com/blogs/conditionals-in-dart)
    
* [Operators in Dart](https://jaytillu.com/blogs/operators-in-dart)
    
* [Keywords in Dart](https://jaytillu.com/blogs/keywords-in-dart)
    
* [Variables in Dart](https://jaytillu.com/blogs/variables-in-dart)
    
* [Data Types in Dart](https://jaytillu.com/blogs/data-types-in-dart)
    
* [Dart SDK](https://jaytillu.com/blogs/dart-sdk)
    

### **Follow me for more such content**

* [My Site](https://www.jaytillu.com/)
    
* [My Blogs](https://jaytillu.com/blogs)
    
* [LinkedIn](https://www.linkedin.com/in/jaytillu/)
    
* [Instagram](https://www.instagram.com/jay.tillu/)
    
* [Twitter](https://twitter.com/jay_tillu)
    
* [Stackoverflow](https://stackoverflow.com/users/8509590/jay-tillu)
    
* [Github](https://github.com/Jay-Tillu)
    
* [Dev](https://dev.to/jay_tillu)
    
* [Medium](https://jaytillu.medium.com/)
    
* [My YouTube Channel](https://www.youtube.com/@jay_tillu)
