SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
JavaScript
1. JavaScript Tutorial for Beginners — Learn JS from Scratch 2. Where to Put JavaScript Code — Head, Body or .js File 3. JavaScript Output Methods — alert, innerHTML, console.log 4. JavaScript Syntax Explained — Statements & Rules 5. JavaScript Comments — How to Write // and /* */ 6. JavaScript Variables — var, let, const Explained 7. JavaScript Operators — Arithmetic, Comparison, Logical 8. JavaScript Data Types — string, number, object, array 9. JavaScript Functions Tutorial — Parameters & Return Values 10. JavaScript Objects — Properties, Methods & this Keyword 11. JavaScript Scope — Global, Local & Block Scope Explained 12. JavaScript Events — addEventListener with Examples 13. JavaScript Strings — Methods, slice, replace & Templates 14. JavaScript Numbers — parseInt, toFixed, NaN Explained 15. JavaScript Arrays — Create, Read, push, pop & More 16. JavaScript Array Methods — map, filter, forEach, find 17. JavaScript Date Object — new Date(), getFullYear & More 18. JavaScript Math Object — random, round, floor, ceil 19. JavaScript if else — Conditions with Examples 20. JavaScript switch Statement — case, break, default 21. JavaScript for Loop — for, for...of, for...in Examples 22. JavaScript while Loop — while & do...while Explained 23. JavaScript Type Conversion — Number, String, Boolean 24. JavaScript try catch — Error Handling with finally 25. JavaScript JSON — stringify & parse with Examples 26. JavaScript Arrow Functions — => Syntax & this 27. JavaScript Classes — Constructor & Objects Explained 28. JavaScript Promises & async/await Explained Simply 29. JavaScript DOM Tutorial — Find & Change Page Elements 30. JavaScript Form Validation Tutorial with Examples 31. JavaScript Fetch API Tutorial — fetch() with Examples 32. JavaScript localStorage — setItem, getItem Explained 33. JavaScript Timers — setTimeout & setInterval Examples 34. JavaScript Regular Expressions — test() & match() Guide 35. JavaScript Debugging — console.log & Fixing Errors
Final Test — Certificate ₹10
Try this code live
Lesson 7 of 35

JavaScript Operators — Arithmetic, Comparison, Logical

4 min read · Free · No login needed

An operator is a small symbol that does something to values: + adds, * multiplies, === checks whether two things are equal. Operators are the verbs of JavaScript — variables hold the nouns, and operators are what you do with them.

Diagram — see how it fits together
Diagram: JavaScript Operators

There are four groups you need: arithmetic operators for maths, assignment operators for storing values, comparison operators for asking questions, and logical operators for combining questions. Together they cover almost everything a beginner program does.

Arithmetic — doing the maths

The arithmetic operators are + add, - subtract, * multiply, / divide, % remainder, and ** power. The remainder operator % is the one beginners meet last and use most: 10 % 3 is 1, because 10 divided by 3 leaves 1 over. It is how programs check whether a number is even (n % 2 === 0) or split items into groups.

let total = 4 * 15;      // 60
let change = 100 - 60;   // 40
let isEven = 10 % 2 === 0; // true

Assignment — storing and updating

The plain assignment = stores a value. The shortcuts combine an operation with storing: += adds and stores, -= subtracts and stores, *= and /= do the same for multiply and divide. total += 10 means exactly the same as total = total + 10, but shorter. Two more shortcuts: ++ adds one, -- subtracts one.

let score = 50;
score += 10; // score is now 60
score++;     // score is now 61

Comparison — asking yes/no questions

Comparison operators answer with true or false: === strictly equal, !== strictly not equal, > greater than, < less than, >= and <=. Always use === and !==, not == and !=. The double-equals versions convert types before comparing, so "10" == 10 is true — a surprise nobody wants. Triple equals compares value and type, so "10" === 10 is false, which is honest.

let marks = 75;
marks >= 33;  // true — the student passed
marks === 75; // true
"75" === 75;  // false — a string is not a number

Logical — combining questions

Logical operators combine true/false answers: && means AND (both must be true), || means OR (at least one must be true), ! means NOT (flips true to false). A scholarship might need marks above 80 and attendance above 90% — that is one &&. A discount might apply to students or teachers — that is one ||.

let passed = marks >= 33;
let distinction = marks >= 75;
passed && distinction; // true only if both are true
Note: = stores a value, === compares two values. Writing if (marks = 33) stores 33 into marks and is always true — the classic beginner bug. If your condition always passes, check for a single = where you meant ===.
Tip: When two operators meet, JavaScript follows the same order as school maths: brackets first, then *, /, %, then + and -. When in doubt, add brackets — (2 + 3) * 4 is clearer than 2 + 3 * 4, even though both are correct.

Common mistakes

  • Using == instead of === — the loose version converts types and hides real differences between strings and numbers.
  • Using = inside a condition — it stores a value instead of comparing, and the condition is always true.
  • Writing & or | (single) when you mean && or || (double) — the single versions are bit operators, a different thing entirely.
  • Forgetting that + also joins text — "5" + 3 is "53", not 8, because + with a string means "join".

Remember

  • Arithmetic: + - * / % **. The remainder % checks even numbers and groups.
  • Assignment: = += -= *= /=, plus ++ and --.
  • Comparison: === !== > < >= <=. Always use the triple versions.
  • Logical: && AND, || OR, ! NOT.

Example explained

  • Number(document.getElementById("marks").value) — reads the marks the visitor typed and turns the text into a number, so the maths works properly.
  • marks >= 33 — a comparison that answers true or false: did the student reach the pass marks?
  • marks >= 75 — a second comparison for distinction. Both answers are stored in variables, not thrown away.
  • passed && distinction — the AND operator: true only when the student both passed and scored a distinction.
  • if ... else — picks one of two messages based on the answers. You will learn the full if statement in the Conditions lesson; here, just notice how the operators feed it true or false.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Exam Result Checker</title>
<style>
body { background-color: #fff8e1; font-family: Verdana, sans-serif; text-align: center; }
h1 { color: #b45309; }
input { padding: 10px; font-size: 16px; width: 80px; text-align: center; }
button { background-color: #e13611; color: white; border: none; padding: 12px 24px; font-size: 16px; cursor: pointer; }
#result { color: green; font-weight: bold; font-size: 18px; }
</style>
</head>
<body>

<h1>Exam Result Checker</h1>
<p>Enter your marks out of 100. Pass is 33, distinction is 75.</p>
<input id="marks" type="number" value="82">
<button onclick="checkResult()">Check result</button>
<p id="result">Enter your marks and click the button.</p>

<script>
function checkResult() {
  let marks = Number(document.getElementById("marks").value);
  let passed = marks >= 33;
  let distinction = marks >= 75;
  if (passed && distinction) {
    document.getElementById("result").textContent = "Pass with distinction! Great work.";
  } else if (passed) {
    document.getElementById("result").textContent = "Pass. Keep improving!";
  } else {
    document.getElementById("result").textContent = "Fail. Try again next time.";
  }
}
</script>

</body>
</html>

Output

Output — how it looks in the browser
Output of JavaScript Operators — Arithmetic, Comparison, Logical

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What does the % operator do?

It gives the remainder after division: 10 % 3 is 1, which is how programs check even numbers with n % 2 === 0.

2. What is the difference between = and ===?

= stores a value, while === compares value and type strictly; the lesson says always use the triple versions for comparison.

3. What do &&, || and ! mean?

&& means AND, || means OR, and ! means NOT — they combine yes/no questions into bigger conditions.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
WordPress Website Development Course (10 Days)
₹399
View
Full Stack PHP Development Course 2026
₹3,000
View
Browse all courses
JavaScript — Lessons
1. JavaScript Tutorial for Beginners — Learn JS from Scratch 2. Where to Put JavaScript Code — Head, Body or .js File 3. JavaScript Output Methods — alert, innerHTML, console.log 4. JavaScript Syntax Explained — Statements & Rules 5. JavaScript Comments — How to Write // and /* */ 6. JavaScript Variables — var, let, const Explained 7. JavaScript Operators — Arithmetic, Comparison, Logical 8. JavaScript Data Types — string, number, object, array 9. JavaScript Functions Tutorial — Parameters & Return Values 10. JavaScript Objects — Properties, Methods & this Keyword 11. JavaScript Scope — Global, Local & Block Scope Explained 12. JavaScript Events — addEventListener with Examples 13. JavaScript Strings — Methods, slice, replace & Templates 14. JavaScript Numbers — parseInt, toFixed, NaN Explained 15. JavaScript Arrays — Create, Read, push, pop & More 16. JavaScript Array Methods — map, filter, forEach, find 17. JavaScript Date Object — new Date(), getFullYear & More 18. JavaScript Math Object — random, round, floor, ceil 19. JavaScript if else — Conditions with Examples 20. JavaScript switch Statement — case, break, default 21. JavaScript for Loop — for, for...of, for...in Examples 22. JavaScript while Loop — while & do...while Explained 23. JavaScript Type Conversion — Number, String, Boolean 24. JavaScript try catch — Error Handling with finally 25. JavaScript JSON — stringify & parse with Examples 26. JavaScript Arrow Functions — => Syntax & this 27. JavaScript Classes — Constructor & Objects Explained 28. JavaScript Promises & async/await Explained Simply 29. JavaScript DOM Tutorial — Find & Change Page Elements 30. JavaScript Form Validation Tutorial with Examples 31. JavaScript Fetch API Tutorial — fetch() with Examples 32. JavaScript localStorage — setItem, getItem Explained 33. JavaScript Timers — setTimeout & setInterval Examples 34. JavaScript Regular Expressions — test() & match() Guide 35. JavaScript Debugging — console.log & Fixing Errors
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →