JavaScript Operators

JavaScript includes operators same as other languages. An operator performs some operation on single or multiple operands (data value) and produces a result. For example, in 1 + 2 , the + sign is an operator and 1 is left side operand and 2 is right side operand.

JavaScript Operator Types

Here is a list of different operators you will learn in this tutorial.

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

1. Assignment Operators:

Assignment operators are used to assign values to different variables. For example,

let x = 20;

Equal to = operator is used to assign value 20 to variable X.

list of commonly used assignment operators:

OperatorNameExample
=Assignment operatora = 5; // 5
+=Addition assignmenta += 5; // a = a + 5
-=Subtraction Assignmenta -= 20; // a = a - 20
*=Multiplication Assignmenta *= 30; // a = a * 30
/=Division Assignmenta /= 5; // a = a / 5
%=Remainder Assignmenta %= 10; // a = a % 10
**=Exponentiation Assignmenta **= 2; // a = a**2

2. Arithmetic Operators:

It is used to perform arithmetic calculations. For example,

const total = 5 + 5; // 10

Plus + operator is used to add two operands.

list of commonly used arithmetic operators:

OperatorNameExample
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Remainderx % y
++Increment (increments by 1)++x or x++
--Decrement (decrements by 1)--x or x--
**Exponentiation (Power)x ** y

3. Comparison Operators:

It compare two values and return a boolean value, either true or false. For example,

const x = 5, x = 4;
console.log(x > y); // true
 
const a = 5, b = 10;
console.log(a > b); // false

Greater than operator > is used to compare whether x is greater than y.

list of commonly used Comparison operators:

OperatorDescriptionExample
==Equal to: returns true if the operands are equalx == y
!=Not equal to: returns true if the operands are not equalx != y
===Strict equal to: true if the operands are equal and of the same typex === y
!==Strict not equal to: true if the operands are equal but of different type or not equal at allx !== y
>Greater than: true if left operand is greater than the right operandx > y
>=Greater than or equal to: true if left operand is greater than or equal to the right operandx >= y
<Less than: true if the left operand is less than the right operandx < y
<=Less than or equal to: true if the left operand is less than or equal to the right operandx <= y

4. Logical Operators :

Logical operators perform logical operations and return a boolean value, either true or false. For example,

const a = 5, b = 10;
(a < 10) && (a < 5); // true

// logical AND
console.log(true && true); // true
console.log(true && false); // false

// logical OR
console.log(true || false); // true

// logical NOT
console.log(!true); // false

 && is the logical operator AND. Since both x < 6 and y < 5 are true, the result is true.

OperatorDescriptionExample
&&Logical AND: true if both the operands are true, else returns falsex && y
||Logical OR: true if either of the operands is true; returns false if both are falsex || y
!Logical NOT: true if the operand is false and vice-versa.!x

5. Bitwise Operators :

Bitwise operators perform operations on binary representations of numbers.

  • The four most critical bitwise operators present in JavaScript are:
    • Bitwise And
    • Bitwise Or
    • Bitwise Not
    • Bitwise XOR
OperatorDescription
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
<<Left shift
>>Sign-propagating right shift
>>>Zero-fill right shift
JavaScript Operators
  1. An Operator performs some operation on single or multiple operands (data value) and produces a result.
  2. Assignment operators are used to assign values to different variables.
  3. Arithmetic used to perform arithmetic calculations.
  4. Comparison Operators compare two values and return a boolean value, either true or false.
  5. Logical Operators perform logical operations and return a boolean value, either true or false.
  6. Bitwise operators perform operations on binary representations of numbers.