# Operators in Dart

Every expression is composed of two parts:

1. ***Operand —*** They represent data.
    
2. ***Operator —*** An operator is a symbol that tells the compiler to perform a specific mathematical, relational, or logical operation and produce a final result.
    

* For example, A + B where
    
* Here ***A*** and ***B*** are operands and ***+*** is an operator.
    

## **Types of Operators in Dart**

There are total of eight types of operators are there in Dart.

1. Arithmetic Operator
    
2. Assignment Operator
    
3. Bitwise operator
    
4. Equality Operator
    
5. Logical Operator
    
6. Relational Operator
    
7. Short circuit operator
    
8. Type Test Operator
    

### **Arithmetic Operator**

There are nine types of arithmetic operators are there in a dart.

| **Operator** | **Meaning** |
| --- | --- |
| **+** | Add |
| **\-** | Subtract |
| **\*** | Multiply |
| **/** | Divide |
| **%** | Modulo |
| **\-expr** | Unary Minus (reverse the sign of expression) |
| **~/** | Divide (Return Integer) |
| **++** | Increment Operator |
| **\--** | Decrement Operator |

### **Relational Operator**

* The relational operator shows the relation between the two operands.
    
* The relational operator can have only two values either ***true*** or ***false***.
    
* There are four relational operators are there.
    

| Operator | Meaning |
| --- | --- |
| **&gt;** | Greater Than |
| **&lt;** | Less Than |
| **&gt;=** | Greater Than or Equal To |
| **&lt;=** | Less Than or Equal To |

### **Equality Operator**

* The equality operator checks whether two objects are equal or not.
    
* Same as relational operators they contain Boolean values either ***true*** or ***false***.
    
* There are two equality operators are there.
    

| **Operator** | **Meaning** |
| --- | --- |
| \== | Equal To |
| != | Not Equal To |

* Here remember that two strings are equivalent only if they contain the same character sequence. Here the sequence of characters is important rather than the number of characters.
    

```dart
void main() {
 var a = "Jay";
 var b = "Jya"; //If here value is Jay then this is true
 print(a == b);
}

Output
false
```

### **Type Test Operator**

* Type test operators are used to check the data type.
    

| Operator | Meaning |
| --- | --- |
| **is** | True if the object has a specified type |
| **is!** | True if the object has not specified type |

### **Assignment Operator**

* Dart has two assignment operators.
    

| Operator | Meaning |
| --- | --- |
| **\=** | Assign value from right operand to left operand |
| **??=** | Assign the value only if the variable is null |

* Here note that **(+=, -=, \*=, /=)** are also a type of assignment operator. But as they are just a shortcut way. I didn’t mention them.
    

### **Logical Operator**

* Logical operators are used to combine two or more conditions.
    
* Logical operators return a Boolean value of ***true*** or ***false***.
    
* There are three logical operators are there:
    

| Operator | Meaning |
| --- | --- |
| **&& (AND)** | Returns true if all conditions are true |
| \*\* |  |
| **! (NOT)** | Returns the inverse of the result |

### **Ternary operator**

* Dart has two special operators which can help you to evaluate small expressions that might require an entire if-else statement.
    

**Condition ? expr1 : expr2**

* Here if the condition is true then the **expr1** is evaluated and returns its value. Otherwise, **expr2** is evaluated and returns the value.
    

```dart
void main() {
  var a = 25;
  var res = a > 15 ? "value greater than 15" : "value lesser than or equal to 15";
  print(res);
}

Output
value greater than 15
```

**expr1 ?? expr2**

* Here if ***expr1*** is non-null, return its value. Otherwise, evaluate and return the value of ***expr2***.
    

```dart
void main() {
  var a = 15;
  var b = null;
  var res = a ?? b;
  print ( res );
}

Output
15
```

So, guys, that’s all you need to know about dart operators. Here short circuit and bitwise operators are also there. But as they are rarely used so I didn’t mention them here. But feel free to explore them if you need one. Also, feel free to let me know if I missed something. I’ll love to learn it from you.

Till Then Keep Loving, Keep Coding. And I’ll surely catch you up in another amazing article. Jai Hind, Vande Mataram 🇮🇳

> 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">Subscribe To My Newsletter For More Such Content.</div>
</div>

### **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)
