JavaScript Operators: The Basics You Need to Know

We do math every day without thinking about it. We split a bill, calculate how much change we should get, or figure out if we have enough balance before making a purchase. All of that involves operators, and JavaScript works the same way.
Operators are symbols that let us perform operations on values and variables. That is really all they are. Let's go through each type one by one.
Arithmetic Operators
These are the ones we are most familiar with. They do basic math.
let a = 10;
let b = 3;
console.log(a + b); // 13 — addition
console.log(a - b); // 7 — subtraction
console.log(a * b); // 30 — multiplication
console.log(a / b); // 3.33 — division
console.log(a % b); // 1 — remainder (modulus)
The % operator is the one that confuses beginners the most. It does not give us the result of division. It gives us the remainder. So 10 % 3 is 1 because 3 goes into 10 three times, and 1 is left over. This operator is surprisingly useful once we start writing real programs.
Assignment Operators
We have already been using the most basic assignment operator without thinking about it. The = sign does not mean "is equal to" in JavaScript. It means "assign this value to this variable."
let score = 0; // assign 0 to score
But there are shorter ways to update a variable's value:
let score = 10;
score += 5; // same as: score = score + 5 → 15
score -= 3; // same as: score = score - 3 → 12
score *= 2; // same as: score = score * 2 → 24
score /= 4; // same as: score = score / 4 → 6
These are just shortcuts. Instead of writing score = score + 5, we write score += 5. Both do the exact same thing. Once we get used to them, they feel very natural.
Comparison Operators
Comparison operators compare two values and always return either true or false. We use them constantly when writing conditions.
let age = 20;
console.log(age > 18); // true
console.log(age < 18); // false
console.log(age >= 20); // true
console.log(age <= 19); // false
Now the two that every beginner needs to understand properly: == and ===.
console.log(5 == "5"); // true
console.log(5 === "5"); // false
Both are checking for equality, but they do it differently.
== checks only the value. It does not care about the type, so it converts "5" (a string) to 5 (a number) behind the scenes before comparing. This is called type coercion, and it can lead to unexpected results.
=== checks both the value and the type. The number 5 and the string "5" are not the same type, so it returns false.
As a rule, always use === in our code. It is stricter and much more predictable.
console.log(5 != "5"); // false — loose inequality
console.log(5 !== "5"); // true — strict inequality
Same idea applies for not-equal. Prefer !== over != for the same reasons.
Logical Operators
Logical operators let us combine multiple conditions together. There are three of them.
&& means AND. Both conditions must be true for the result to be true.
let age = 22;
let hasID = true;
console.log(age >= 18 && hasID); // true
// both conditions are true, so the result is true
|| means OR. At least one condition needs to be true.
let isWeekend = false;
let isHoliday = true;
console.log(isWeekend || isHoliday); // true
// one of them is true, so the result is true
! means NOT. It flips the value. true becomes false and false becomes true.
let isLoggedIn = false;
console.log(!isLoggedIn); // true
// we flipped false to true
We will use logical operators constantly once we start writing conditions and making decisions in our programs.




