In this lesson we will go on all types of operators that any developer must know (not only dart programmers).
To be a good developer you need to master these operators so read them carefully and try to take notes before moving to exercises.
Arithmetic Operators: (easy)
Operator
Meaning
+
Add
-
Subtract
-expr
Unary minus, also known as negation (reverse the sign of the expression)
*
Multiply
/
Divide
~/
Divide, returning an integer result
%
Get the remainder of an integer division (modulo)
Assignment Operators: (shorter)
Assignment operators assign values to dart variables.
Operator
Description
Example
Same As
=
assign
x=y
+=
add & assign
x+=y
x=x+y
-=
subtract & assign
x-=y
x=x-y
*=
multiply & assign
x*=y
x=x*y
/=
divide & assign
x/=y
x=x/y
~/=
divide & assign (integer result)
x~/=y
x=x~/y
%=
mod & assign
x%=y
x=x%y
Unary Operators: ( practical )
Operator
Description
Example
++x
the value of x after increment
x=5; y=++x; //x = 6 & y= 6
x++
the value of x before increment
x=10; y=x++; //x=11 & y=10
--x
the value of x after decrement
x=20 ; y=--x ; //x=19 & y=19
x--
the value of x before decrement
x=50 ; y=x-- ; // x=49 & y50;
Relational Operators : (easy)
Operator
Meaning
==
Equal
!=
Not Equal
>
Greater Than
<
Less Than
>=
Greater than or equal to
<=
Less than or equal to
Loogical Operators : (catch the syntax)
Operator
Meaning
!exp
inverts the following expression (changes false to true, and vice versa)
||
logical OR
&&
logical AND
Type Test Operators : (you will get familiar with them sooner)
The as, is, and is! operators are handy for checking types at runtime
Operator
Meaning
as
Typecast (also used to specify library prefixes)
is
True if the object has the specified type
is!
False if the object has the specified type
Conditional Operators:(you will get familiar with them sooner)
condition ? expr1 : expr2
If condition is true, evaluates expr1 (and returns its value); otherwise, evaluates and returns the value of expr2.
expr1 ?? expr2
If expr1 is non-null, returns its value; otherwise, evaluates and returns the value of expr2.