Understand how JavaScript operators work — from basic arithmetic to tricky type-coercion bugs — and learn to debug them confidently.
JavaScript Operators are symbols used to perform operations on values and variables — assigning values, performing arithmetic calculations, and evaluating expressions.
Every program you write relies on operators, from storing a score in a variable to checking whether a user is logged in.
Operators are tools that tell JavaScript: "Do something with these values."
let score = 10; // Assign value
score += 5; // Add 5 to score
console.log(score);
= assigns a value to a variable+= adds to the variable and updates it in one steplet 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);
% returns the remainder after division — 10 ÷ 3 = 3 remainder 1n % 2 === 0 means evenlet x = 10;
let y = "5";
console.log(x + y);
JavaScript sees "5" as a string, so + concatenates instead of adding.
console.log(x + Number(y));
Think of operators like managing money in a wallet:
Operators work inside real HTML pages too. Click ▶ Preview to run it live in the browser below.
<!DOCTYPE html>
<html>
<head><title>Operators Demo</title></head>
<body style="font-family:sans-serif;padding:20px;background:#f8f9fa">
<h2>JavaScript Operators</h2>
<p id="result"></p>
<script>
let marks = 40;
marks += 10;
document.getElementById("result").textContent =
"Total Marks: " + marks;
</script>
</body>
</html>
let marks = 50;
20 to marks using +=console.log()let total = 100;
let spent = 37;
% to check the remainder when divided by 5+= do?
+= adds the right-hand value and saves it back — one
step instead of two.
console.log(10 % 3);
%
operator returns that remainder.
console.log(5 + "5");
+ is a string, JavaScript converts
the other to a string too and concatenates — giving "55", not 10.
Prefer Number() when you expect a numeric value from a string — it's explicit and avoids
silent concatenation bugs.
Always check a value's type before operating on it:
let value = 42;
console.log(typeof value);
Watch out for the =+ vs += typo — a very common mistake:
let a = 5;
a =+ 3; // WRONG → unary +3, so a becomes 3
a += 3; // RIGHT → a = a + 3 = 6
Use console.log() frequently while debugging — it's your best tool for catching unexpected
values at any point in your code.
Predict the output before running — apply each operator one step at a time.
let coins = 10;
coins += 5;
coins %= 4;
console.log(coins);
// Step 1: coins = 10
// Step 2: coins += 5 → coins = 15
// Step 3: coins %= 4 → 15 % 4 = 3 (15 = 3 × 4 + 3)
// Output: 3