Operators in Dart
Tags: dart, todayilearned, code, beginners
Published: 2019-09-15 21:38:08

> ***An expression is a special kind of statement that evaluates in a single value.***

Every expression is composed of two parts:

1. ***Operand*** — They represents 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 an arithmetic operator are there in a dart.

![](https://miro.medium.com/max/662/1*9Fy4F4aw773v-IrqUwTsKA.png)

###Relational Operator
****

* 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.

![](https://miro.medium.com/max/776/1*NsKARNlGePT-etFB96wfLg.png)

###Equality Operator
****

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

![](https://miro.medium.com/max/577/1*-jnIgLm0n4TFEhIReTe8Cg.png)

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

```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.

![](https://miro.medium.com/max/639/1*qTStvdSm8Zwts4P6cHMzUA.png)

###Assignment Operator
****

* Dart has main two assignment operator.

![](https://miro.medium.com/max/670/1*kl79sd_O6nS_XMFWpV3Y3A.png)

* 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:

![](https://miro.medium.com/max/731/1*d5LYKUDgVNB7xP5hos2BoA.png)

###Conditional Expression
****

* 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.

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 hesitate 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.

###For More Information Please Visit Following Links
* [Fuchsia OS official site](https://fuchsia.dev/)
* [Dart official site](https://dart.dev/)
* [Flutter official site](https://flutter.dev/)

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

- [My Site] (https://www.jaytillu.in)
- [My Blogs] (https://blogs.jaytillu.in)
- [Twitter](https://twitter.com/jay_tillu)
- [Facebook](https://www.facebook.com/jaytillu.1314/)
- [Instagram](https://www.facebook.com/jaytillu.1314/)
- [Medium](https://medium.com/jay-tillu)
- [LinkedIn](https://www.linkedin.com/in/jaytillu/)
- [Github](https://www.github.com/jay-tillu)
- [Stack overflow](https://stackoverflow.com/users/8509590/jay-tillu)
or just mail me at jd.tillu@gmail.com