JAVASCRIPT OPERATORS
What are Operators in Javascript?
Operators are symbols that define what kind of operation is to be performed on
operators. For example, the symbol of addition (+)
tells javascript engine to add given
operators.
There are different types of operator in javascript mentioned below:
 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 like addition, subtraction, etc. Learn here arithmetic operations in detail.
Operators  Description 

+  Addition 
  Subtraction 
*  Multiplication 
**  Exponential (ES6) 
%  Modulus used to find remainder 
/  Division 
++  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.
let add = 5 + 5;
let sub = 12  8;
let exp = 5 ** 2; // 5^2 = 25
let mod = 12 % 5; // remainder 2
let div = 12 / 3; // output 4
let num = 100;
num++; // increased by one output 101
num; // decrease by one output 100
▶
Run the code
2. Comparison Operators
Comparison operator is used to compare two operators. These operators return
true
or false
values on the basis of result.
Lets see the comparison operators in the table with description.
Operators  Description 

==  equals to operator (returns true when both operators are equal) 
===  Identical to operator (returns true when both operators are equal and of same data type)

>  greater than operator (returns true when left operator is greater than right operator)

<  less than operator (returns true when left operator is lesser than right operator)

>=  greater than equals to operator (returns true when left operator is greater than or equal
right operator) 
<=  less than equals to operator (returns true when left operator is less than or equal right
operator)

!=  Not equals to operator (returns true when operators are not equal) 
!==  Not identical to operator (returns true when operators are either not equal or of
different type) 
Lets see an example to visualise the code and result.
let eql = (5==5);
let ident = (10==='10'); //return false (equal but different type)
let grt = (5>10); // return false
let grt_eql = (15>=10);
let less = (10<20); // return false
let not_eql = (10!=20); // true
▶
Run the code
3. Assignment Operators
Assignment operator is used to assign and change values of the operators. For
example, 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
.
These are the following assignment operators in javascript.
Operators  Description 

=  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.
let a = 10, b = 5, c = 12, d = 15, e = 5, f = 20, g = 45;
b += 10; // 5 + 10 = 15
c = 5; // 12  5 = 7
d *= 2; // 15 * 2 = 30
e **= 2; // 5 ** 2 = 25
f %= 7; // 20 % 7 = 6
g /= 9; // 45 / 9 = 5
▶
Run the code
4. Logical Operators
Logical operators perform logical operations in javascript. For example, &&
operation true && true = true
.
Operators  Description 

&&  Logical AND 
  Logical OR 
!  Logical NOT 
Lets see the example.
let a = (true && true); // output true
let b = (true && false); // output false
let c = (true  true); // output true
let d = (true  false); // output true
let e = !true; // output false
▶
Run the code
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.
These are the following bitwise operators in javascript.
Operator  Name  Description 

&  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.
let a = 5 & 2; // output 0
let b = 5  2; // output 7
let c = 5 ^ 2; // output 7
let d = 5 << 1; // output 10
let e = 5 >> 1; // output 3
let f = 5 >>> 1; // output 2
console.log(a, b, c, d, e);
▶ Run the code
6. Special Operators
Special operators serve special purposes. These following operators lie under special operators categories..
Operators  Description 

( ? : )  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) 
More Learning
Want to learn more about programming and web development? We have a few recommendations for you.