elibraryportal Logo

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.

  1. Arithmetic Operators
  2. Comparison Operators or Relational Operators
  3. Assignment Operators
  4. Logical Operators
  5. Bitwise Operators
  6. Special Operators

1) Arithmetic Operators in Javascript

Arithmetic operators is used to perform arithmetic operations on operands.

+Addition10+20 = 30
-Subtraction20-10 = 10
*Multiplication10*20 = 200
/Division 20/10 = 2
%Modulus (Remainder)20%10 = 0
++Incrementvar a=10; a++; Now a = 11
--Decrementvar a=10; a--; Now a = 9

2) Comparison Operators or Relational Operators in Javascript

Its compare the two operands.

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

3) Assignment Operators in Javascript

=Assign10+10 = 20
+=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

4) Logical Operators in Javascript

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

&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

(?:)Conditional Operator returns value based on the condition. It is like if-else.
,Comma Operator allows multiple expressions to be evaluated as single statement.
deleteDelete Operator deletes a property from the object.
inIn Operator checks if object has the given property
instanceofchecks if the object is an instance of given type
newcreates an instance (object)
typeofchecks the type of object.
voidit discards the expression's return value.
yieldchecks what is returned in a generator by the generator's iterator.
Next Topic