
What is Operators
Operators are used to perform operations on variables and values. They are used to assign values to variables, compare values, perform arithmetic operations, and more. There are several types of operators in JavaScript, including assignment operators, comparison operators, arithmetic operators, logical operators, and bitwise operators.
Types of Operators
There are several types of operators in JavaScript, including:

Example
// Arithmetic Operators
let a = 10;
let b = 3;
console.log("Addition: ", a + b); // 13
console.log("Subtraction: ", a - b); // 7
console.log("Multiplication: ", a * b); // 30
console.log("Division: ", a / b); // 3.333...
console.log("Modulus: ", a % b); // 1
console.log("Exponentiation: ", a ** b); // 1000
console.log("Increment: ", ++a); // 11
console.log("Decrement: ", --b); // 2
Example
// Assignment Operators
let c = 5;
c += 3; // c = c + 3
console.log("Add and assign: ", c); // 8
c -= 2; // c = c - 2
console.log("Subtract and assign: ", c); // 6
c *= 2; // c = c * 2
console.log("Multiply and assign: ", c); // 12
c /= 3; // c = c / 3
console.log("Divide and assign: ", c); // 4
c %= 3; // c = c % 3
console.log("Modulus and assign: ", c); // 1
Example
// Comparison Operators
let x = 10, y = 20;
console.log("Equal: ", x == y); // false
console.log("Not Equal: ", x != y); // true
console.log("Strict Equal: ", x === 10); // true
console.log("Strict Not Equal: ", x !== "10"); // true
console.log("Greater Than: ", x > y); // false
console.log("Less Than: ", x < y); // true
console.log("Greater or Equal: ", x >= 10); // true
console.log("Less or Equal: ", x <= 10); // true
Example
// Logical Operators
let isTrue = true, isFalse = false;
console.log("AND: ", isTrue && isFalse); // false
console.log("OR: ", isTrue || isFalse); // true
console.log("NOT: ", !isTrue); // falseExample
// Bitwise Operators
let bit1 = 5; // 0101 in binary
let bit2 = 3; // 0011 in binary
console.log("Bitwise AND: ", bit1 & bit2); // 0001 (1 in decimal)
console.log("Bitwise OR: ", bit1 | bit2); // 0111 (7 in decimal)
console.log("Bitwise XOR: ", bit1 ^ bit2); // 0110 (6 in decimal)
console.log("Bitwise NOT: ", ~bit1); // -(5+1) = -6
console.log("Left Shift: ", bit1 << 1); // 1010 (10 in decimal)
console.log("Right Shift: ", bit1 >> 1); // 0010 (2 in decimal)
console.log("Unsigned Right Shift: ", bit1 >>> 1); // 2
Example
// Ternary Operator
let age = 18;
let canVote = (age >= 18) ? "Yes" : "No";
console.log("Can Vote: ", canVote); // Yes