
JavaScript Operators are the symbol which is used to perform operations on operands.
Operands can be values and variable.
10 + 20 = 30 // 10 and 20 are operands and + is operator
10 * 20 = 200 // 10 and 20 are operands and * is operator
20 - 10 = 10 // 10 and 20 are operands and - is operator
20 / 10 = 2 // 10 and 20 are operands and / is operator
Types of JavaScript Operators
- Arithmetic Operators
- Comparison Operators
- Logical Operators
- String Operators
- Assignment Operators
- Bitwise Operators
- Conditional (or ternary) Operators
Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations between operands.
Operator | Operator Name | Example |
+ | Addition | a + b |
– | Subtraction | a – b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus | a % b |
** | Exponentiation | a ** b |
++ | Increment | ++a and a– |
— | Decrement | –a and a– |
let a = 20;
let b = 10;
// Addition
console.log('a + b = ', a + b);
// 30
// Subtraction
console.log('a - b = ', a - b);
// 10
// Multiplication
console.log('a * b = ', a * b);
// 200
// Division
console.log('a / b = ', a / b);
// 2
// Remainder
console.log('a % b = ', a % b);
// 0

Comparison Operators
Comparison Operator are used for comparison between two operands.
Operator | Operator Name | Example |
== | Equal to | a == b |
!= | Not Equal to | a != b |
> | Greater then | a > b |
>= | Greater then or equal to | a >= b |
< | Less then | a < b |
<= | Less then or equal to | a <= b |
=== | Strictly equal (is exactly equal to ) | a === b |
// Equal operator
console.log(0 == 0); // true
console.log(12 == '2'); // false
// not equal operator
console.log(3 != 3); // false
console.log('hello' != 'Hello'); // true
// strict equal operator
console.log(0 === 0); // true
console.log(22 === '22'); // false
Logical Operators
Logical Operator are used to perform logical operation and it return a Boolean value (true , false).
Operator | Operator Name | Example |
&& | Logical AND | a && b |
|| | Logical OR | a || b |
! | Logical NOT | !a |
let a = 1, b = 2;
(a < 2) && (b > 1); // true
String Operators
The + operator, and the += operator is used to concatenate strings.
Operator | Operator Name | Example |
+ | used for concatenate String | let t = “t1” + “t2” |
+= | used for concatenate String | let t += “t1” |
// concatenation operator
console.log('Code' + 'Shruta');let a =0
let b=1
console.log(a & b);//0
console.log(a | b);//1
console.log(a ^ b);//1
console.log(~a);//-1
console.log(b >> 1);//0
console.log(b << 1)//2
let a = 'Hello ';
a += ' World';
console.log(a);

Assignment Operators
Assignment Operators are used to assign values to variables.
Operator | Operator Name | Example |
= | Assignment Operator | a = 2 |
+= | Addition Assignment | a += 2 |
-= | Subtraction Assignment | a -= 2 |
*= | Multiplication Assignment | a *= 2 |
/= | Division Assignment | a /= 2 |
%= | Modulus Assignment | a %= 2 |
**= | Exponentiation Assignment | a **= 2 |
//Addition Assignment
let x = 100;
x += 15;
console.log(x);//115
//Subtraction Assignment
let y = 100;
y -= 15;
console.log(y);//85
//Multiplication Assignment
let z = 100;
z *= 15;
console.log(z);//1500
Bitwise Operators
Bitwise Operators perform operations on binary values.
Operator | Operator Name | Example |
& | Bitwise AND | a & b |
| | Bitwise OR | a | b |
^ | Bitwise XOR | a ^ b |
~ | Bitwise NOT | ~ a |
>> | Right Shift | a >> 1 |
<< | Left Shift | a << 1 |
let a =0
let b=1
//Bitwise AND
console.log(a & b);//0
//Bitwise OR
console.log(a | b);//1
//Bitwise XOR
console.log(a ^ b);//1
//Bitwise NOT
console.log(~a);//-1
//Right Shift
console.log(b >> 1);//0
//Left Shift
console.log(b << 1)//2
Conditional Operators
It assign a value to a variable based on some condition.
Syntax | Description | Example |
variable_name=(condition) ?value1:value2 | If condition true then value1 will be assigned to variable and if condition is false then value2 will be assigned. | a= (4>5)? 4:5 so a value is 5 here because 4>5 will return false. |
!!JavaScript Operators !!.
Check All JavaScript Tutorial here JAVASCRIPT TUTORIAL.
Written By : Ankita Kataria.
Pingback: JavaScript Type Conversions and Equality — CodeShruta