# DART – Operators

An operator is a symbol that tells of performing specific mathematical, relational or logical operations.

The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry out operations on one or two operands.

## Types of Operators

Dart supports the following types of operators.

• Arithmetic Operators
• Assignment Operators
• Relational Operators
• Type test Operators
• Logical Operators
• Bitwise Operator
• Conditional Operators

## Arithmetic Operators

Arithmetic operators perform addition, subtraction, multiplication, division, etc.

```void main(){
var a = 10;
var b = 5;

print("a+b = \${a+b}");
print("a-b = \${a-b}");
print("a*b = \${a*b}");
print("a/b = \${a/b}");
print("a%b = \${a%b}");
}  ```

## Assignment Operator

Assignment operators are used to assign value to the variables.

```void main(){
var a = 10;
var b= 5;

a+=b;
print("a+=b= \${a}");

a-=b;
print("a-=b= \${a}");

a*=b;
print("a*=b = \${a}");

a~/=b;
print("a~/=b= \${a}");
a%=b;
print("a%=b= \${a}");
} ```

## Relational Operator

Relational operators or Comparison operators are used to make a comparison between two expressions and operands. The comparison of two expressions returns the Boolean true and false.

## Type test operators

The `as``is`, and `is!` operators are handy for checking types at runtime.

## Logical operators

You can invert or combine boolean expressions using logical operators.

## Dart Bitwise Operators

The Bitwise operators perform operations bit by bit on the value of the two operands.

## Dart Conditional Operators (?:)

The Conditional Operator is the same as the if-else statement and provides similar functionality as a conditional statement. It is the second form of an if-else statement. It is also identified as a “Ternary Operator”. The syntax is given below.

Syntax 1 –

1. `condition ? exp1 : exp2 `

If the given condition is TRUE then it returns exp1 otherwise exp2.

Syntax 2 –

1. `exp1 ?? expr2  `

If the exp1 is not-null, returns its value, otherwise returns the exp2’s value.

Cascades (`..``?..`) allow you to make a sequence of operations on the same object. In addition to accessing instance members, you can also call instance methods on that same object. This often saves you the step of creating a temporary variable and allows you to write more fluid code. 5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%