JS Operators

The Arithmatic Operators:

The Arithmetic Operators are used with numeric operands and returns a numerical value. There are following arithmatic operators supported by JavaScript language:

Let assume variable a=5 and variable b=10.

OperatorDescriptionExample
+Addition a + b = 15
Subtraction a – b = -5
*Multiplication a * b = 50
/Division b / a = 2
%Modulus (division remainder) b % a = 0
++Increment a++ = 6
Decrement a– = 4

The Assignment Operators:

There are following assignment operators supported by JavaScript language:
Let assume variable a=20 and variable b=10.

OperatorExample 1Same As Example 1Result
=a=b a = 10
+=a+=ba=a+b a = 30
-=a-=ba=a-b a = 10
*=a*=ba=a*b a = 200
/=a/=ba=a/b a = 2
%=a%=ba=a%b a = 0

The Comparison Operators:

There are following comparison operators supported by JavaScript language:
Let assume variable a=2 and variable b=3.

OperatorDescriptionExampleResult
==is equal toa == bis not true
!=is not equala != bis true
>is greater thana > bis not true
<is less thana < bis true
>=is greater than or equal toa >= bis not true
<=is less than or equal toa <= bis true

The Logical Operators:

There are following logical operators supported by JavaScript language:
Let assume variable a=5 and variable b=8.

OperatorDescriptionExampleResult
&&and(a && b)is true
||or(a || b)is true
!not!(a && b)is false