Do you know what are the operators in JavaScript? Operators are symbols that perform certain operations on one or more variables or values.
Mainly there are six types of operators in JavaScript.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
- Type Operators
Arithmetic Operators
Arithmetic operators perform arithmetic operations on numbers.
Operator Symbol | Description |
---|---|
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
** | Exponentiation |
++ | Increment |
— | Decrement |
% | Modulo |
Assignment Operators
Assignment operators are used to assign a values.
Operator Symbol | Description |
---|---|
= | a = b |
+= | a += b |
-= | a -= b |
*= | a *= b |
**= | a **= b |
/= | a /= b |
%= | a %= b |
Comparison Operators
Comparison operators are used to compare two values or variables.
Operator Symbol | Description |
---|---|
== | equal to |
=== | equal value and equal type |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
!= | not equal |
!== | not equal value or not equal type |
? | ternary operator |
Logical Operators
Operator Symbol | Description |
---|---|
&& | logical and |
|| | logical or |
! | logical not |
Bitwise Operators
Operator Symbol | Description | Example |
---|---|---|
& | AND | 7 & 1 |
| | OR | 7 | 1 |
~ | NOT | ~ 7 |
^ | XOR | 7 ^ 1 |
<< | Zero fill left shift | 7 << 1 |
>> | Signed right shift | 7 >> 1 |
>>> | Zero fill right shift | 7 >>> 1 |
Type Operators
Operator Symbol | Description |
---|---|
typeof | Returns the type of a variable |
instanceof | Returns true if an object is an instance of an object type |
Previous Post: Var Let and Const in JavaScript