JavaScript Operators: The Basics You Need to Know
Understand JavaScript operators, using simple language, real-life logic, and practical examples.

When you start learning JavaScript, one of the first things you’ll encounter is operators.
They may look like small symbols (+, ==, &&), but they play a huge role in how your code works.
In this article, we’ll understand JavaScript operators from scratch, using simple language, real-life logic, and practical examples.
What Are Operators in JavaScript?
In simple words:
Operators are symbols that tell JavaScript to perform some action on values.
Think of operators as instructions.
Real-life analogy:
+→ add things>→ compare things&&→ check multiple conditions
Example:
let a = 10;
let b = 5
let total = a + b;
Here:
+is an operatoraandbare operandsResult →
15
JavaScript supports many operators, but in this article, we’ll focus only on the most commonly used ones in daily coding.
Types of Operators We’ll Cover
| Category | Operators | Purpose |
|---|---|---|
| Arithmetic | + - * / % |
Math calculations |
| Comparison | == === != > < |
Compare values |
| Logical | `&& | Check logic |
| Assignment | = += -= |
Assign values |
Arithmetic Operators ( +, -, *, /, % )
Arithmetic operators are used for basic math operations.
Let’s start with very simple numbers.
Now here’s where things get interesting.
The + symbol does two jobs in JavaScript:
Addition (when both operands are numbers)
String concatenation (when one operand is a string)
Addition (+)
console.log(5 + 3); // 8
Output = 10 (normal addition)
But now look at this:
console.log("5" + 5); // 55
Output = "55"
Why?
Because when JavaScript sees a string, it says:
Oh, we’re working with text now. Let me convert everything into a string
So number 5 becomes "5"
And then it joins them "55"
This automatic conversion is called type coercion.
JavaScript is basically adjusting types automatically to make the operation work.
Subtraction (-)
This is where it gets interesting again.
console.log("10" - 4); // 6
Output = 6
Wait… why didn’t it become "104"?
Because - only works for math.
It cannot concatenate strings.
So here JS says:
Okay, I’ll convert the string
"10"into a number 10
Then when we do:
10 - 4 it return 6
So:
+prefers string concatenation if a string is involved.-,*,/force numeric conversion.
3️⃣ Multiplication (*)
console.log(6 * 2); // 12
Used to multiply values.
4️⃣ Division (/)
console.log(20 / 5); // 4
Used to divide values.
5️⃣ Modulus (%)
This one is extremely useful, yet confusing operator.
Note: This % operator can not calculate percentage of the value, it gives the remainder
console.log(10 % 3); // 1 (remender)
--> % gives the remainder.
Very basic example:
- Check even or odd numbers
console.log(4 % 2); // 0 → Even
console.log(5 % 2); // 1 → Odd
If remainder is 0 - even.
If remainder is 1 - odd.
Modulo is also used in loops, patterns, alternating values, cycling through items it’s small but powerful.
Quick Comparison
"10" + 2 // "102"
"10" - 2 // 8
"10" * 2 // 20
"10" / 2 // 5
See the difference?
That’s type coercion happening silently in the background.
Arithmetic operators feel simple but they can behave differently depending on data types.
If both are numbers => normal math.
If one is a string with
+=> concatenation.Other arithmetic operators force numeric conversion.
%is perfect for remainder logic like even/odd checks.
So yeah, arithmetic operators are basic…
but once strings enter the chat, things get interesting
Comparison Operators ( ==, ===, !=, >, < ) - check how things relate with each other and return boolen value
Comparison operators compare two values and always return boolen value:
trueorfalse
Equal to (==)
console.log(5 == "5"); // true
== checks only value, not data type.
Strict Equal (===)
console.log(5 === "5"); // false
=== checks:
value
AND type
Always prefer === in real projects.
🔥 Difference Between == and ===
console.log(10 == "10"); // true
console.log(10 === "10"); // false
| Operator | Checks Value | Checks Type |
|---|---|---|
== |
Yes | No |
=== |
Yes | Yes |
Not Equal (!=)
console.log(5 != 3); // true
Greater Than (>) and Less Than (<)
console.log(10 > 5); // true
console.log(3 < 1); // false
Used heavily in conditions and loops.
Logical Operators ( &&, ||, ! )
Logical operators help when you need to check multiple conditions together.
| A | B | A && B | A || B | | --- | --- | --- | --- | | true | true | true | true | | true | false | false | true | | false | true | false | true | | false | false | false | false |
1️⃣ AND (&&)
let age = 20;
let hasID = true;
console.log(age > 18 && hasID); // true
Both conditions must be true
OR (||)
let isAdmin = false;
let isEditor = true;
console.log(isAdmin || isEditor); // true
At least one condition must be true
NOT (!)
console.log(!true); // false
console.log(!false); // true
Reverses the result
Assignment Operators ( =, +=, -= )
These operators are used to assign or update values.
Assignment (=)
let x = 10;
Add and Assign (+=)
let score = 5;
score += 2;
console.log(score); // 7
Same as:
score = score + 2;
Subtract and Assign (-=)
let balance = 100;
balance -= 20;
console.log(balance); // 80
Everyday Usage Example (Putting It All Together)
let marks = 75;
if (marks >= 60 && marks <= 100) {
console.log("Passed");
} else {
console.log("Failed");
}
✔ Arithmetic
✔ Comparison
✔ Logical
✔ Assignment
All working together!
Practical Combination Example
Let's use multiple operators in one real example:
let price = 1200;
let discount = 25;
let finalPrice = price - (price * discount / 100);
if (finalPrice < 1000 && discount > 20) {
console.log("You got a great deal!");
} else {
console.log("Keep watching for better discounts.");
}
Here we used Arthmetic, Comparison, Logical, Assignment Operator.
All working together to create real logic.
Small Practice Assignment
Try this yourself:
Perform arithmetic between two numbers
Compare values using both
==and===Write a small condition using logical operators
Experiment with assignment operators (
+=,-=, etc.)
Final Thoughts
JavaScript operators may look small, but they are the backbone of logic and decision-making in your code.
Once you master:
arithmetic for calculations
comparison for decisions
logical operators for conditions
You’ll feel much more confident writing JavaScript.




