Operators in JavaScript

By | April 6, 2020

In this tutorial, we will learn about Operators in JavaScript. Operators are special symbols and we use these operators to perform some operation on operands. For example, we want to add two number 5 and 10 so we will use + operator there to add these two numbers.

JavaScript provides us with a variety of operators. These operators are categorized into these following categories.

  • Arithmetic Operators
  • Relational Operators
  • Bitwise Operators
  • Logical Operators
  • Assignment Operators

Now we will check all these operators in detail. we will check each category.

Arithmetic Operators:

Arithmetic Operators are used to performing normal mathematical operations. For example to perform addition, subtraction. We have a total of five operators in this category.

OperatorDescriptionExample
+Addition10+20 = 30
Subtraction20-10 = 10
*Multiplication10*20 = 200
/Division20/10 = 2
%Modulus20%10 = 0

Relational Operators:

Relational Operators are used to performing check relation between two operands operations. For example, check less than or greater than. We have a total eight operators in this category.

OperatorDescriptionExample
==Is equal to10==20 = false
===Identical (equal and of same type)10==20 = false
!=Not equal to10!=20 = true
!==Not Identical20!==20 = false
>Greater than20>10 = true
>=Greater than or equal to20>=10 = true
<Less than20<10 = false
<=Less than or equal to20<=10 = false

Bitwise Operators:

Bitwise Operators are work on bit level of the operand. We have a total seven operators in this category.

OperatorDescriptionExample
&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

Logical Operators: 

Logical Operators are work between two expressions. We have a total three operators in this category.

OperatorDescriptionExample
&&Logical AND(10==20 && 20==33) = false
||Logical OR(10==20 || 20==33) = false
!Logical Not!(10==20) = true

Assignment Operators:

Assignment Operators are normally used to assign value to a variable. We have a total six operators in this category.

OperatorDescriptionExample
=Assignvar a=10;
+=Add and assignvar a=10; a+=20; Now a = 30
-=Subtract and assignvar a=20; a-=10; Now a = 10
*=Multiply and assignvar a=10; a*=20; Now a = 200
/=Divide and assignvar a=10; a/=2; Now a = 5
%=Modulus and assignvar a=10; a%=2; Now a = 0