JavaScript Operators

Operators in JavaScript are special symbols or keywords that are used to perform operations on operands (values and variables). They are essential in every JavaScript program to perform mathematical, logical, or assignment operations.

1. Arithmetic Operators

These operators are used to perform arithmetic calculations such as addition, subtraction, multiplication, etc.

OperatorDescriptionExampleOutput
+Additionlet x = 5 + 3;8
-Subtractionlet x = 5 - 3;2
*Multiplicationlet x = 5 * 3;15
/Divisionlet x = 6 / 3;2
%Modulus (remainder)let x = 7 % 3;1
**Exponentiationlet x = 2 ** 3;8

2. Comparison Operators

These operators are used to compare two values and return a Boolean value (true or false).

OperatorDescriptionExampleOutput
==Equal to5 == '5'true
===Strict equal to (value and type)5 === '5'false
!=Not equal5 != '6'true
!==Strict not equal5 !== '5'true
>Greater than6 > 3true
<Less than2 < 5true
>=Greater than or equal to5 >= 5true
<=Less than or equal to4 <= 3false

3. Logical Operators

Used to combine multiple conditions or expressions and return Boolean results.

OperatorDescriptionExampleOutput
&&Logical AND(5 > 2) && (4 < 10)true
||Logical OR(5 < 2) || (4 < 10)true
!Logical NOT!(5 === 5)false

4. Assignment Operators

Used to assign values to variables and combine with arithmetic operations.

OperatorDescriptionExampleOutput
=Assignx = 1010
+=Add and assignx += 515
-=Subtract and assignx -= 213
*=Multiply and assignx *= 226
/=Divide and assignx /= 213
%=Modulus and assignx %= 41

5. Bitwise Operators

Know more in Detail

Perform bit-level operations on binary representations of integers.

OperatorDescriptionExampleOutput
&Bitwise AND5 & 31
|Bitwise OR5 | 37
^Bitwise XOR5 ^ 36
~Bitwise NOT~5-6
<<Left Shift5 << 110
>>Right Shift5 >> 12