JavaScript Operators: The Basics You Need to Know
A beginner-friendly guide to arithmetic, comparison, logical, and assignment operators in JavaScript with clear examples and real-world use cases.

Hey everyone, I have been continuing my deep dive into JavaScript with our Web Dev Cohort 2026. In my last post, we talked about Variables -> the boxes where we store our data.
But having a bunch of labeled boxes sitting in a room is pretty useless if you don't actually do anything with them. You need to combine them, compare them, and change them.
If variables are the Nouns (the things), Operators are the Verbs (the actions). Today, we are going to look at the basic operators you need to know, ditch the confusing jargon, and focus on everyday usage.
Let's get into it.
Operator Categories at a Glance
Before diving deep, here is a quick overview
Category | Operators | Purpose |
|---|---|---|
Arithmetic |
| Perform mathematical operations |
Assignment |
| Assign or update values |
Comparison |
| Compare values |
Logical |
| Combine multiple conditions |
What Exactly Are Operators?
An operator is just a special symbol (like +, =, or >) that tells the JavaScript engine to perform a specific action on your data.
Think of it like being in the kitchen. If your variables are the ingredients (flour, sugar, water), the operators are the actions (mixing, baking, slicing). Without them, you just have raw ingredients staring at you.
1. Arithmetic Operators (The Calculator)
These do exactly what you think they do. They perform basic math. If you have ever split a bill, you already know how these work.
Addition (
+) & Subtraction (-)Multiplication (
*) & Division (/)
let monthlyRent = 8000;
let electricityBill = 1200;
let totalPgExpenses = monthlyRent + electricityBill;
console.log(totalPgExpenses); // Output: 9200
The Odd One Out: Modulo (%)
This one confuses a lot of beginners because it looks like a percentage sign. It is not. Modulo simply gives you the remainder of a division.
Imagine you ordered an 8-slice pizza for 3 friends.
let totalSlices = 8;
let friends = 3;
let slicesLeftOver = totalSlices % friends;
console.log(slicesLeftOver); // Output: 2
// Everyone gets 2 slices, and 2 are left over
2. Assignment Operators (The "Put it in the Box" Rule)
In math class, = means two things are equal. In JavaScript, = means assignment. It tells the engine: Take whatever is on the right, and put it into the box on the left.
let myAge = 21; // Put the number 21 into the myAge box
Writing myAge = myAge + 1 every time feels repetitive. Thankfully, JavaScript gives us shorthand operators to keep our code clean and efficient.
let score = 10;
score += 5; // Exactly the same as score = score + 5
console.log(score); // Output: 15
3. Comparison Operators (The Bouncers)
This is where programming gets interesting. We use these to compare two values, and they always answer with a Boolean (true or false).
The basic ones are straightforward:
>(Greater than)<(Less than)>=(Greater than or equal to)
let passingMarks = 40;
let myScore = 85;
console.log(myScore > passingMarks); // Output: true
The Big Debate: == vs ===
This is the most common trap for beginners. Both check for equality, but they do it very differently.
== (The Chill Bouncer / Loose Equality): This bouncer only checks the value, not the data type. If you show up in a fake mustache, he still lets you in. He converts the types behind the scenes to see if they match.
console.log(5 == "5"); // Output: true (Wait, what?)
Because one is a Number and one is a String, JS converts the string to a number, and says Yep, they look the same.
=== (The Strict Bouncer / Strict Equality): This bouncer checks the value AND the data type. No ID, no entry. No conversions.
console.log(5 === "5"); // Output: false
Golden Rule: Always, always, always use ===. It prevents weird, hard-to-find bugs in your code. (And use !== for strict "Not Equal").
4. Logical Operators (The Rule Makers)
Sometimes one condition is not enough. What if you want to buy a new mechanical keyboard, but you have two rules: I need to have enough money AND it needs to be in stock.
1. The AND Operator (&&) Both conditions must be true for the whole thing to be true.
let hasMoney = true;
let inStock = false;
console.log(hasMoney && inStock); // Output: false (You can't buy it)
2. The OR Operator (||) Only one condition needs to be true.
let isWeekend = true;
let isHoliday = false;
console.log(isWeekend || isHoliday); // Output: true (You get to sleep in)
3. The NOT Operator (!) This is the rebel. It just flips whatever the boolean is to the opposite.
let isTired = true;
console.log(!isTired); // Output: false
Truth Table for AND (&&)
Condition A | Condition B | Result |
|---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
Practical Assignment: Try This Yourself
Just like last time, reading is not coding. Open up your browser console or VS Code and try writing this exact sequence:
Arithmetic: Create two variables (
num1andnum2). Multiply them together and store the result in a new variable. Log it to the console.Comparison: Compare the number
10and the string"10"using both==and===. Log both results.Logical: Create a variable
hasCompletedReactand set it tofalse. Create anotherhasBuiltPortfolioand set it totrue. Use the&&operator to see if you arereadyForJobs.
Small Real-World Example
Let's combine everything:
let age = 20;
let hasID = true;
if (age >= 18 && hasID) {
console.log("Entry Allowed");
} else {
console.log("Entry Denied");
}
Here we used:
Comparison (>=)
Logical (&&)
Assignment (=)
The Cheat Sheet
Arithmetic (+, -, *, /, %)
Used for mathematical operations. Remember, % gives you the remainder.
Assignment (=, +=, -=)
Assigns or updates values in a variable.
Comparison (==, ===, !=, >, <, >=)
Compares two values and returns true or false.
The Golden Rule
Prefer === over == to avoid unexpected type conversion.
Logical (&&, ||, !)
Used to combine or invert conditions.
Thanks for reading. Keep practicing those basics, and I will see you in the next blog where we might finally start making some decisions in our code using if/else statements




