JavaScript operators are special symbols used to perform operations on values, variables, and expressions. They help you perform tasks like addition, comparison, assignment, and logical decision-making.
Operators are one of the most essential fundamentals every JavaScript learner must understand before moving to advanced concepts.
This blog explains all major types of operators with clear examples.
✅ 1. Arithmetic Operators
Used for mathematical calculations.
| Operator | Description | Example |
|---|---|---|
+ | Addition | 5 + 2 → 7 |
- | Subtraction | 5 - 2 → 3 |
* | Multiplication | 5 * 2 → 10 |
/ | Division | 10 / 2 → 5 |
% | Modulus (Remainder) | 10 % 3 → 1 |
** | Exponentiation | 2 ** 3 → 8 |
Example:
let a = 10;
let b = 3;
console.log(a + b); // 13
console.log(a % b); // 1
console.log(a ** b); // 1000
✅ 2. Assignment Operators
Used to assign values to variables.
| Operator | Meaning | Example |
|---|---|---|
= | Assign | x = 10 |
+= | Add & assign | x += 5 (x = x + 5) |
-= | Subtract & assign | x -= 5 |
*= | Multiply & assign | x *= 3 |
/= | Divide & assign | x /= 2 |
Example:
let x = 10;
x += 5;
console.log(x); // 15
✅ 3. Comparison Operators
Used to compare values.
They return true or false.
| Operator | Description | Example |
|---|---|---|
== | Equal to | 5 == "5" → true |
=== | Strict equal (type + value) | 5 === "5" → false |
!= | Not equal | 5 != 3 → true |
!== | Strict not equal | 5 !== "5" → true |
> | Greater than | 10 > 5 → true |
< | Less than | 3 < 8 → true |
>= | Greater or equal | 5 >= 5 → true |
<= | Less or equal | 3 <= 2 → false |
Example:
console.log(5 == "5"); // true
console.log(5 === "5"); // false
✅ 4. Logical Operators
Used in decision-making with conditions.
| Operator | Meaning | Example |
|---|---|---|
&& | AND | both must be true |
| ` | ` | |
! | NOT | reverses value |
Example:
let age = 20;
console.log(age > 18 && age < 30); // true
console.log(age < 18 || age > 25); // false
console.log(!true); // false
✅ 5. String Operators
The + operator can combine (concatenate) strings.
let first = "Hello";
let second = "World";
console.log(first + " " + second);
// Hello World
✅ 6. Unary Operators
Single value operations.
| Operator | Description | Example |
|---|---|---|
++ | Increment | x++ |
-- | Decrement | x-- |
typeof | Returns data type | typeof "hello" |
Example:
let x = 5;
x++;
console.log(x); // 6
console.log(typeof x); // number
✅ 7. Ternary Operator
Short-form of an if-else.
Syntax:
condition ? valueIfTrue : valueIfFalse
Example:
let age = 18;
let message = age >= 18 ? "Adult" : "Minor";
console.log(message); // Adult
Final Thoughts
JavaScript operators are the building blocks for logic, calculations, decisions, and expressions. Mastering them is essential before moving to functions, loops, objects, or advanced topics.
🔗 View other articles about Javascript:
https://savanka.com/category/learn/js