JS Operator
Operators is a symbols that are used to perform action on operands.
Where, + is the arithmetic operator and = is the assignment operator.
Types of Operator
There are following types of operators that is.
- Arithmetic Operators
- Comparison Operators or Relational Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Special Operators
1) Arithmetic Operators in Javascript
Arithmetic operators is used to perform arithmetic operations on operands.
Operator | Description | Example |
+ | Addition | 10+20 = 30 |
- | Subtraction | 20-10 = 10 |
* | Multiplication | 10*20 = 200 |
/ | Division | 20/10 = 2 |
% | Modulus (Remainder) | 20%10 = 0 |
++ | Increment | var a=10; a++; Now a = 11 |
-- | Decrement | var a=10; a--; Now a = 9 |
2) Comparison Operators or Relational Operators in Javascript
Its compare the two operands.
Operator | Description | Example |
== | Is equal to | 10==20 = false |
=== | Identical (equal and of same type) | 10==20 = false |
!= | Not equal to | 10!=20 = true |
!== | Not Identical | 20!==20 = false |
> | Greater than | 20>10 = true |
>= | Greater than or equal to | 20>=10 = true |
< | Less than | 20<10 = false |
<= | Less than or equal to | 20<=10 = false |
3) Assignment Operators in Javascript
Operator | Description | Example |
= | Assign | 10+10 = 20 |
+= | Add and assign | var a=10; a+=20; Now a = 30 |
-= | Subtract and assign | var a=20; a-=10; Now a = 10 |
*= | Multiply and assign | var a=10; a*=20; Now a = 200 |
/= | Divide and assign | var a=10; a/=2; Now a = 5 |
%= | Modulus and assign | var a=10; a%=2; Now a = 0 |
4) Logical Operators in Javascript
Operator | Description | Example |
&& | Logical AND | (10==20 && 20==33) = false |
|| | Logical OR | (10==20 || 20==33) = false |
! | Logical Not | !(10==20) = true |
5) Bitwise Operators in Javascript
This operators perform perform operations on operands.
Operator | Description | Example |
& | Bitwise AND | (10==20 & 20==33) = false |
| | Bitwise OR | (10==20 | 20==33) = false |
^ | Bitwise XOR | (10==20 ^ 20==33) = false |
~ | Bitwise NOT | (~10) = -10 |
<< | Bitwise Left Shift | (10<<2) = 40 |
>> | Bitwise Right Shift | (10>>2) = 2 |
>>> | Bitwise Right Shift with Zero | (10>>>2) = 2 |
6) Special Operators in Javascript
Operator | Description |
(?:) | Conditional Operator returns value based on the condition. It is like if-else. |
, | Comma Operator allows multiple expressions to be evaluated as single statement. |
delete | Delete Operator deletes a property from the object. |
in | In Operator checks if object has the given property |
instanceof | checks if the object is an instance of given type |
new | creates an instance (object) |
typeof | checks the type of object. |
void | it discards the expression's return value. |
yield | checks what is returned in a generator by the generator's iterator. |
|