JavaScript Operators: The Basics You Need to Know

Hey Everyone,
In this blog, we will learn about JavaScript Operators.
In programming, we often need to perform calculations, compare values, or combine conditions.
For example:
Add two numbers
Check if two values are equal
Verify multiple conditions
To perform these actions, JavaScript uses operators.
Let’s understand the most important ones every beginner should know.
What Are Operators?
An operator is a symbol that tells JavaScript to perform an operation on values.
Example:
let result = 5 + 3;
console.log(result) // 8
Here:
+is the operator5and3are operands
Example
let a = 10;
let b = 3;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);
Output:
13
7
30
3.333...
1
The % operator returns the remainder of a division.
Example:
10 % 3 = 1
Comparison Operators
Comparison operators compare two values and return true or false.
| Operator | Meaning |
|---|---|
| == | Equal (value only) |
| === | Strict equal (value + type) |
| != | Not equal |
| > | Greater than |
| < | Less than |
Example
let x = 10;
let y = 20;
console.log(x > y);
Output
false
Difference Between and =
This is very important in JavaScript.
Using ==
console.log(5 == "5"); // true
Why?
Because == converts types before comparing.
Using ===
console.log(5 === "5"); // false
Because:
5→ number"5"→ string
=== checks both value and type.
Best practice:
Use === in most cases.
Logical Operators
Logical operators combine multiple conditions.
Example: AND (&&)
let age = 20;
let hasID = true;
if (age >= 18 && hasID) {
console.log("Entry allowed");
}
Both conditions must be true.
Example: OR (||)
let isWeekend = true;
let isHoliday = false;
if (isWeekend || isHoliday) {
console.log("You can relax");
}
Only one condition needs to be true.
Example: NOT (!)
let isLoggedIn = false;
console.log(!isLoggedIn); // true
Assignment Operators
Assignment operators are used to assign or update values.
| Operator | Meaning |
|---|---|
| = | Assign value |
| += | Add and assign |
| -= | Subtract and assign |
Example
let score = 10;
score += 5;
console.log(score); // 15
Equivalent to:
score = score + 5;
Practice Assignment
Try these examples in your browser console.
1. Arithmetic Operations
let a = 8;
let b = 4;
console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
2. Compare Values
console.log(5 == "5");
console.log(5 === "5");
Observe the difference.
3. Logical Condition
let age = 19;
let hasTicket = true;
if (age >= 18 && hasTicket) {
console.log("You can enter the event");
}
And now, you know what JS operators are.
If you have any doubt or want to connect, feel free to drop a comment — I’d be happy to help.
Thanks for reading, and see you in the next blog!
Peace ✌️ and Happy Learning!




