“Operators & Expressions for Web” – Learn how JavaScript thinks and calculates
Welcome back, young web coder! In Module One, you learned the basics of operators and expressions. In Module Two, you learned arithmetic and assignment operators.
Now it is time to make JavaScript think. In this module, we will learn about comparison operators (like == and >), logical operators (like && and ||), and string operators (like + for joining text).
These operators are what make a website smart. They help a login page check if a password is correct. They help a shop page show "In Stock" only when items are available. They help a game decide if the player has won.
By the end of this module, you will be able to write JavaScript that compares, decides, and reacts — just like real web apps do.
Let’s begin!
After finishing this module, you will be able to:
Chidi is 14 years old and lives in Port Harcourt. He built a simple login page for his school’s coding club. The page asked for a username and password.
At first, Chidi had a problem. His code accepted every password. Anyone could log in! He said, "I need my page to compare what the user typed to the real password."
His teacher said, "Use the strict equality operator ===."
Chidi wrote:
let entered = "coding4life";
let real = "coding4life";
if (entered === real) {
console.log("Welcome!");
} else {
console.log("Wrong password");
}
The console printed: Welcome!. Chidi was very happy.
Next, he wanted the page to welcome "Admin" or "Member" based on the username. He used the logical OR operator:
let username = "ada";
if (username === "ada" || username === "admin") {
console.log("Hello, leader!");
}
Finally, he wanted to show a greeting. He used string concatenation:
let greeting = "Hello, " + username + "!"; console.log(greeting);
His login page became smarter. It could compare, decide, and respond. Chidi learned that comparison and logical operators are the brains of any website.
Moral of the story: Comparison operators check. Logical operators combine checks. String operators join words. Together, they make websites smart.
Definition: Comparison operators compare two values and return true or false.
Why it is important: They let websites make decisions.
Simple explanation: They answer questions like "Is this bigger?" or "Are these the same?"
Real-life example: A bank checks if a balance is above zero.
School example: A teacher checks if a score is above pass mark.
Home example: A family checks if the shopping total is within budget.
Nigerian example: A trader checks if stock is below reorder level.
Illustration:
Comparison operators return: true or false
Mini summary: Comparison operators check values and give true or false.
Definition: The == operator checks if two values are equal after converting them to the same type.
Why it is important: It is an easy way to compare values quickly.
Simple explanation: == asks "Are these the same?" but it is very forgiving.
Real-life example: A bank checks if a typed PIN equals a stored PIN.
School example: A teacher checks if a score equals 100.
Home example: A family checks if two shopping lists match.
Nigerian example: A trader checks if two prices are the same.
Illustration:
5 == 5 → true "5" == 5 → true (type conversion!) true == 1 → true
Mini summary: == checks equality but converts types first.
Definition: The === operator checks if two values are equal AND have the same type.
Why it is important: It is safer and prevents surprises.
Simple explanation: === asks "Are these the same value and the same type?"
Real-life example: A bank checks if a typed PIN (a number) strictly equals the stored PIN.
School example: A teacher checks if a score (a number) strictly equals a target score.
Home example: A family checks if the quantity (a number) strictly equals 5.
Nigerian example: A trader checks if the price (a number) strictly equals ₦3000.
Illustration:
5 === 5 → true "5" === 5 → false 5 === "5" → false
Mini summary: === checks equality and type. Always prefer ===.
Definition: != checks if two values are not equal. !== checks if they are not equal OR not the same type.
Why it is important: Used to reject wrong values.
Simple explanation: They are the "opposite" of equality checks.
Real-life example: A bank rejects a wrong PIN.
School example: A teacher rejects a wrong answer.
Home example: A family rejects a wrong shopping item.
Nigerian example: A trader rejects a wrong price.
Illustration:
5 != 3 → true 5 != 5 → false "5" !== 5 → true
Mini summary: != and !== check if values are different. !== is stricter.
Definition: > checks if the left value is greater. < checks if it is less.
Why it is important: Used to compare numbers.
Simple explanation: They are the "bigger" and "smaller" checks.
Real-life example: A bank checks if a withdrawal is greater than the balance.
School example: A teacher checks if a score is greater than 50.
Home example: A family checks if the bill is less than the budget.
Nigerian example: A trader checks if stock is less than 10.
Illustration:
10 > 5 → true 10 < 5 → false 7 > 7 → false
Mini summary: > and < check bigger and smaller.
Definition: >= checks if the left value is greater OR equal. <= checks if it is less OR equal.
Why it is important: Very common in form validation and grading.
Simple explanation: Same as > and <, but includes "equal to".
Real-life example: A bank allows withdrawals up to the balance (<=).
School example: A teacher passes anyone with score >= 50.
Home example: A family keeps spending <= income.
Nigerian example: A trader sells if quantity <= stock.
Illustration:
10 >= 10 → true 10 >= 9 → true 5 <= 5 → true 5 <= 3 → false
Mini summary: >= and <= include the equal case.
Definition: Logical operators combine multiple true/false checks into one.
Why it is important: Real life has more than one condition.
Simple explanation: They are the "and", "or", and "not" of code.
Real-life example: A bank requires you to have an account AND a valid ID.
School example: You can attend the trip if you paid AND brought a permission slip.
Home example: You can go out if you finished chores AND did homework.
Nigerian example: You can buy stock if you have money AND the price is good.
Illustration:
&& AND (both true) || OR (at least one true) ! NOT (flips true to false)
Mini summary: Logical operators combine conditions.
Definition: && returns true only if both sides are true.
Why it is important: It enforces strict conditions.
Simple explanation: && is like saying "you must do both".
Real-life example: A bank checks if you have enough money AND a valid account.
School example: A teacher passes you only if you attended AND submitted all work.
Home example: You can watch TV if you cleaned AND did homework.
Nigerian example: A trader accepts an order if stock is available AND payment is confirmed.
Illustration:
true && true → true true && false → false false && true → false false && false → false
Mini summary: && needs both sides to be true.
Definition: || returns true if at least one side is true.
Why it is important: It gives flexibility.
Simple explanation: || is like saying "either this or that is fine".
Real-life example: A bank accepts a phone number OR an email for contact.
School example: You can submit by email OR by hand.
Home example: You can shop at Market A OR Market B.
Nigerian example: A trader accepts payment by transfer OR cash.
Illustration:
true || true → true true || false → true false || true → true false || false → false
Mini summary: || is true if at least one side is true.
Definition: ! flips a true to false or a false to true.
Why it is important: Used to invert checks.
Simple explanation: ! is like saying "the opposite".
Real-life example: A bank shows "Not available" if a service is !available.
School example: A teacher marks a student absent if !present.
Home example: A family stays home if !sunny.
Nigerian example: A trader does not sell if !inStock.
Illustration:
!true → false !false → true
Mini summary: ! flips true and false.
Definition: Truthy values act like true in logical checks. Falsy values act like false.
Why it is important: They affect how && , ||, and if statements behave.
Simple explanation: Some values "feel" like true or false to JavaScript.
Real-life example: A bank treats an empty balance (0) as a "no" for a loan.
School example: An empty string ("") is treated as no answer.
Home example: An empty shopping list is treated as "nothing to buy".
Nigerian example: A trader treats null prices as "no price".
Illustration:
Falsy values:
false, 0, "", null, undefined, NaN
Truthy values:
"text", 1, -1, [], {}
Mini summary: Some values act like false, others act like true. Learn the list.
Definition: The + operator also joins strings together.
Why it is important: Websites show messages like "Welcome, Ada".
Simple explanation: + glues words together.
Real-life example: A bank says "Dear " + customer + "."
School example: A teacher greets students: "Hello, " + name.
Home example: A family writes "Happy birthday, " + name.
Nigerian example: A trader sends "Your order of " + qty + " items is ready."
Illustration:
"Hello, " + "Ada" → "Hello, Ada" "Total: " + 5000 → "Total: 5000"
Mini summary: The + operator joins strings.
Definition: Template literals use backticks (`) to make joining strings easier.
Why it is important: They are cleaner than using + many times.
Simple explanation: They let you put values inside a sentence directly.
Real-life example: A bank writes: `Dear ${name}, your balance is ${balance}`.
School example: A teacher writes: `${name} scored ${score}`.
Home example: A family writes: `We have ${count} eggs left.`
Nigerian example: A trader writes: `Your order costs ₦${price}.`
Illustration:
let name = "Ada";
let score = 90;
`Hello, ${name}! Your score is ${score}.`
Mini summary: Template literals use backticks and ${ } for clean strings.
Definition: Mistakes happen. Knowing them helps you avoid them.
Why it is important: Wrong comparisons give wrong decisions.
Simple explanation: Like using the wrong key on a lock.
Real-life example: A bank using == instead of === can accept "5" as 5.
School example: A teacher using = instead of === gives the wrong grade.
Home example: A family using || instead of && accepts the wrong list.
Nigerian example: A trader using < instead of <= misses a sale.
Table of common mistakes:
| Mistake | What Happens | How to Fix |
|---|---|---|
| Using == instead of === | Wrong type accepted | Use === |
| Using = instead of === | Assigns value | Use === in conditions |
| Confusing && and || | Wrong logic | Read conditions aloud |
| Not checking truthy/falsy | Wrong branch | Test with console |
| Forgetting backticks | String error | Use ` ` for template literals |
| Missing $ before { } | Wrong output | Write ${value} |
Mini summary: Common mistakes: == vs ===, && vs ||, and forgotten backticks.
Definition: Best practices are good habits that make logic clear and safe.
Why it is important: Good habits prevent bugs and confusion.
Simple explanation: Like a clean desk — easier to think.
Real-life example: A bank writes clean conditions.
School example: A student writes clear if-statements.
Home example: A family writes clear shopping rules.
Nigerian example: A business writes clear code.
List of best practices:
Mini summary: Best practices: use ===, clear names, and test often.
You now know how to compare and combine values.
What you learned:
Next steps: In Module Four, you will learn advanced operators and complete your certification project.
Illustration:
Your Learning Journey:
Module 1: Foundations
|
V
Module 2: Arithmetic & Assignment
|
V
Module 3: Comparison & Logic
|
V
Module 4: Advanced & Certification
|
V
Web Operators Expert 🎉
Mini summary: You now have a full logic toolkit. Time to learn advanced operators!
| Word | Simple Definition |
|---|---|
| Comparison Operator | Checks two values and returns true/false. |
| Equality (==) | Checks equal after type conversion. |
| Strict Equality (===) | Checks equal value and type. |
| Not Equal (!=) | Checks if values are different. |
| Strict Not Equal (!==) | Checks if values or types differ. |
| Greater Than (>) | Checks if left is bigger. |
| Less Than (<) | Checks if left is smaller. |
| Greater Than or Equal (>=) | Bigger or same. |
| Less Than or Equal (<=) | Smaller or same. |
| Logical AND (&&) | Both must be true. |
| Logical OR (||) | At least one must be true. |
| Logical NOT (!) | Flips true and false. |
| Truthy | Values that act like true. |
| Falsy | Values that act like false. |
| Template Literal | String using backticks and ${ }. |
10 > 5 in the console.true.10 < 5 and see false.5 === 5 and see true."5" === 5 and see false."5" == 5 which gives true.age >= 18 and hasID.age >= 18 && hasID.hasEmail or hasPhone.hasEmail || hasPhone.balance >= amount for transfers.score >= 50 to pass.stock <= 10 to reorder.price && quantity to check before selling.amount > 0 && isVerified to send money.score >= 100 means you win.money >= price means you can buy.toys !== 0 means you still have toys.isHungry && hasFood means feed the pet.pages <= 10 means almost done.money >= total means you can pay.expenses <= income means safe.hour < 12 means morning.water === 2 means add water.distance > 100 means take the bus.=== equal value + type !== not equal value + type > greater than < less than >= greater or equal <= less or equal
A && B → true only if both true A || B → true if at least one true
Falsy: false, 0, "", null, undefined, NaN Truthy: everything else
`Hello, ${name}!`
name = "Ada"
→ "Hello, Ada!"
Module 1: Foundations
|
V
Module 2: Arithmetic & Assignment
|
V
Module 3: Comparison & Logic
|
V
Module 4: Advanced & Certification
|
V
Web Operators Expert 🎉
| Expression | == result | === result |
|---|---|---|
| 5 == 5 | true | true |
| "5" == 5 | true | false |
| 0 == false | true | false |
| null == undefined | true | false |
| A | B | A && B | A || B |
|---|---|---|---|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
| Operator | Meaning | Example |
|---|---|---|
| === | Equal value & type | 5 === 5 |
| !== | Not equal value & type | 5 !== "5" |
| > | Greater than | 10 > 5 |
| < | Less than | 5 < 10 |
| >= | Greater or equal | 10 >= 10 |
| <= | Less or equal | 5 <= 5 |
| Method | Example |
|---|---|
| + operator | "Hi " + name |
| Template literal | `Hi ${name}` |
Lesson 1: Comparison operators check values and return true/false.
Lesson 2: == checks equality with type conversion.
Lesson 3: === checks equality and type — safer.
Lesson 4: != and !== check if values differ.
Lesson 5: > and < compare bigger and smaller.
Lesson 6: >= and <= include equal.
Lesson 7: Logical operators combine conditions.
Lesson 8: && needs both sides true.
Lesson 9: || is true if at least one side is true.
Lesson 10: ! flips true and false.
Lesson 11: Truthy/falsy affect logical results.
Lesson 12: + joins strings.
Lesson 13: Template literals use backticks and ${ }.
Lesson 14: Common mistakes: == vs ===, && vs ||.
Lesson 15: Best practices: use ===, clear names, test often.
Lesson 16: You now have a full logic toolkit.
Congratulations! You have finished Module Three of the Operators & Expressions for Web course. You learned comparison operators (==, ===, !=, !==, >, <, >=, <=), logical operators (&&, ||, !), truthy and falsy values, and string operators (+ and template literals). You learned common mistakes and best practices. Most importantly, you can now write JavaScript that decides, reacts, and displays dynamic content. In the next module, you will learn advanced operators and complete your certification project.
Match the operator to its meaning.
| Operator | Meaning |
|---|---|
| 1. === | A. Logical OR |
| 2. !== | B. Strict equality |
| 3. && | C. Strict not equal |
| 4. || | D. Greater than |
| 5. > | E. Logical AND |
Answers: 1-B, 2-C, 3-E, 4-A, 5-D
Title: “Build a Login Check Together”
Instructions: In groups of 3–4, write JavaScript that checks a username and password against fixed values. Use === for both. Show a welcome message using template literals. Present to the class.
Goal: Practice comparisons, logic, and strings.
Task: In the browser console, type at least 6 examples:
Write down each and its result.
Project: “My First Login Check”
Create a small login check in JavaScript:
Example:
let user = "ada";
let pass = "1234";
let enteredUser = "ada";
let enteredPass = "1234";
if (enteredUser === user && enteredPass === pass) {
console.log(`Welcome, ${user}!`);
} else {
console.log("Wrong login");
}
Assignment: Ask a family member about a rule they use (e.g., shopping budget, chores). Then write JavaScript that:
Submit: Your code and a short explanation.
In Module Four, we will learn advanced operators and complete the certification project. We will cover:
To prepare, complete the practical assignment and review the key vocabulary. Practice a few comparisons in the console. Bring your curiosity!
See you in Module Four!
End of Module Three – Operators & Expressions for Web