JavaScript Operators

JavaScript operators are used to perform operation on operands. Here is an expression 2+3 = 5. in the expression 2,3 and 5 are operands and + and = are operators. The javascript operators are:

  • Arithmetic Operators
  • Comparison Operators
  • Assignment Operators
  • Logical Operators
  • Bitwise Operators
  • Special Operators


Arithmatic Operators

Operator Description Example
+ Addition 2+3 = 5
- Subtraction 10-5 = 5
* Multiplication 2*5 = 10
/ Division 10/2 = 5
% Modulus 11%5 = 1
++ Increment a++ (it increases the value of variable a by one)
-- Decrement a-- (it decreases the value of variable a by one)



Comparison Operators

Operator Description Example
== Is equal to a == b is not true
!= Not equal to a == b is true
> Greater than a>b is not true
< Less than a<b is true
>= Greater than or equal to a>=b is not true
<= Less than or equal to a<=b is true



Assignment Operators

Operator Description Example
= Assign the values from right side operand to the left side operand a = 5
+= Add the values of right operand to the left operand and assigns the result to the left operand a += 5 is equivalent to a = a+5
-= Subtract the values of right operand to the left operand and assigns the result to the left operand a -= 5 is equivalent to a = a-5
*= Multiply the values of right operand to the left operand and assigns the result to the left operand a *= 5 is equivalent to a = a*5
/= Divide the values of right operand to the left operand and assigns the result to the left operand a /= 5 is equivalent to a = a/5
%= Take the modulus value using two operands and assigns the result to the left operand. a %= 5 is equivalent to a = a%5



Logical Operators

Operator Description Example
&& Logical AND 5==5 && 7==9 is false
|| Logical OR 5==5 || 7==9 is true
! Logical Not !(7==9) is true



Bitwise Operators

Operator Description Example
& Bitwise AND 3==5 & 7==9 is false
| Bitwise OR 3==5 || 7==9 is false
^ Bitwise XOR 3==5 ^ 7==9 is false
~ Bitwise NOT (~2) = -2
<< Bitwise Left Shift (10<<2) = 40
>> Bitwise Right Shift (10>>2) = 2
>>> Bitwise Right Shift (10>>>2) = 2



Some Useful Special Operators

Operator Description
(?:) Conditional Operator returns value based on the condition.
typeof It checks the type of object.
>> Bitwise Right Shift
>>> Bitwise Right Shift