Operators are symbols that define what kind of operation is to be performed on
operators. For example, the symbol of addition
- Arithmetic Operators
- Comparison Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Special Operators
1. Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on numbers. These are the following operators with their use. Check here for detailed study.
|%||Modulus used to find remainder|
|++||Increment operation used to increase number by 1|
|--||Decrement operation used to decrease number by 1|
Now let's see an example of how to use these arithmetic operators.
2. Comparison Operators
Comparison operator is used to compare two operators. These operators return
false values on the basis of result.
Lets see the comparison operators in the table with description.
|==||equals to operator (returns
|===||Identical to operator (returns
|>||greater than operator (returns
|<||less than operator (returns
|>=||greater than equals to operator (returns
|<=||less than equals to operator (returns
|!=||Not equals to operator (returns
|!==||Not identical to operator (returns
Lets see an example to visualise the code and result.
3. Assignment Operators
Assignment operator is used to assign and change values of the operators. For
a = 10; now a is equal to 10.
In assignment operators can also do arithmetic operations and then assign results to operators. For example,
let a = 10; a += 10 now a become 20 as
a += 10 is equivalent to
a = a + 10.
|=||Used to assign given value|
|+=||Used to add and assign result|
|-=||Used to subtract and assign result|
|*=||Used to multiply and assign result|
|**=||Used to get exponential and assign result|
|%=||Used to get modulus and assign result|
|/=||Used to divide and assign result|
Lets see the example.
4. Logical Operators
true && true = true.
Lets see the example.
5. Bitwise Operators
Bitwise operators are the operators that are used to change bit values of the operands. Bitwise operators treat their operands as a sequence of 0's and 1's of 32 bits.
|&||AND||give 1 only when both bits are 1. ie 1 & 1 = 1|
||||OR||give 0 only when both bits are 0. ie 0 | 1 = 1 and 0 | 0 = 0|
|^||XOR||give 1 only when one bits is 1. ie 1 & 1 = 0 and 0 ^ 1 = 1|
|~||NOT||Reverse the bit value. ie ~ 1 = 0|
|<<||Left Shift(zero fill)||Shift all bit values to left by the given number and fill 0 in rightmost. ie 5 << 1=10|
|>>||Right Shift (sign preserving)||Shift all bit values to right by the given number and preserving sign. ie -10 >> 1 = -5|
|>>>||Right Shift (zero fill)||Shift all bit values to let by the given number and fill 0 in rightmost. ie 15 >>> 1=7|
Lets see an example.
6. Special Operators
Special operators serve special purposes. These following operators lie under special operators categories..
|( ? : )||Ternary operator. It is used for if else purposes.|
|delete||used to delete object's property|
|in||Used to check if object has given property|
|new||Creates new instance of a class(object)|