Operators in JavaScript are special symbols used to perform operations on variables and values. They are essential for calculations, comparisons, logic building, and decision-making in programs.
In this guide, we explain all major types of operators with clear examples.
⭐ What Are Operators?
Operators take one or more values (operands) and produce a result.
Example
let sum = 5 + 10; // + is an operator
JavaScript provides several categories of operators, each serving a different purpose.
⭐ 1. Arithmetic Operators
Used for mathematical operations.
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | 5 + 2 = 7 |
- | Subtraction | 7 - 3 = 4 |
* | Multiplication | 6 * 2 = 12 |
/ | Division | 10 / 2 = 5 |
% | Modulus (remainder) | 10 % 3 = 1 |
** | Exponent | 2 ** 3 = 8 |
++ | Increment | x++ |
-- | Decrement | x-- |
Example
let a = 10;
let b = 3;
console.log(a % b); // 1
⭐ 2. Assignment Operators
Used to assign values.
| Operator | Meaning | Example |
|---|---|---|
= | Simple assignment | x = 10 |
+= | Add and assign | x += 5 |
-= | Subtract and assign | x -= 2 |
*= | Multiply and assign | x *= 3 |
/= | Divide and assign | x /= 2 |
Example
let x = 10;
x += 5;
console.log(x); // 15
⭐ 3. Comparison Operators
Used to compare values. Output is true or false.
| Operator | Meaning |
|---|---|
== | Equal to |
=== | Strict equal (checks value + type) |
!= | Not equal |
!== | Strict not equal |
> | Greater than |
< | Less than |
>= | Greater or equal |
<= | Less or equal |
Example
5 == "5"; // true (loose comparison)
5 === "5"; // false (strict comparison)
⭐ 4. Logical Operators
Used in conditions and decision making.
| Operator | Meaning |
|---|---|
&& | AND |
| ` | |
! | NOT |
Example
let age = 20;
console.log(age > 18 && age < 30); // true
⭐ 5. String Operators
The + operator joins strings.
Example
let first = "Hello";
let second = "World";
console.log(first + " " + second); // "Hello World"
⭐ 6. Ternary Operator
A compact if-else statement.
Syntax
condition ? valueIfTrue : valueIfFalse
Example
let age = 18;
let canVote = (age >= 18) ? "Yes" : "No";
console.log(canVote); // "Yes"
⭐ 7. Type Operators
typeof – returns data type
instanceof – checks if an object belongs to a class
Examples
typeof "Hello"; // "string"
[] instanceof Array; // true
⭐ 8. Bitwise Operators (Advanced)
Work on binary numbers.
| Operator | Meaning |
|---|---|
& | AND |
| ` | ` |
^ | XOR |
~ | NOT |
<< | Left shift |
>> | Right shift |
Example
console.log(5 & 1); // 1
⭐ Conclusion
Operators allow JavaScript to perform calculations, make decisions, compare values, and manage program logic. Mastering them is essential for building any type of application — from simple scripts to advanced web apps.
📌 Citations
🔗 View other articles about Javascript:
https://savanka.com/category/learn/js/
🔗 External Javascript Documentation:
https://www.w3schools.com/js/