“Operators & Expressions for Web” – Learn how JavaScript thinks and calculates
Welcome, young web coder! Have you ever wondered how a website knows that 2 + 2 = 4? Or how a login page knows your password is correct? The answer is operators and expressions.
Operators are the symbols that tell the computer what to do — like +, -, =, and >. Expressions are the little puzzles you build with those symbols, like 2 + 3 or age > 18. Every website you use — from Facebook to your school portal — uses them thousands of times.
In this module, we will learn what operators and expressions are, how they work, and how to use them in the browser. We will use JavaScript, the language of the web. By the end, you will understand the foundation of every line of code you will ever write.
Let’s begin!
After finishing this module, you will be able to:
Ada is 13 years old and lives in Lagos. Her mother runs a small provisions shop. One Saturday, Ada was helping at the shop. A customer came in and bought:
Ada’s mother quickly wrote down the total on paper. Ada watched and thought, "This is exactly what operators do in JavaScript!"
She opened her laptop and typed in the browser console:
(2 * 3000) + 1500 + (3 * 800);
The console showed: 9900. Ada smiled. She had used the multiplication operator (*), the addition operator (+), and the grouping operator ( ) — all in one line.
She also typed:
let total = (2 * 3000) + 1500 + (3 * 800); total > 5000 ? "Big sale!" : "Small sale";
The console replied: "Big sale!". Ada had used the greater than operator (>), the assignment operator (=), and even the ternary operator ( ? : ). Her mother was amazed.
From that day, Ada used JavaScript to help with the shop’s calculations. She learned that operators are everywhere — in business, at home, and on the web.
Moral of the story: Operators are the tools computers use to calculate and compare. Expressions are the little puzzles they solve. Once you understand them, you can make websites do almost anything.
Definition: An operator is a symbol that tells the computer to do something with values.
Why it is important: Every calculation, comparison, or decision uses operators.
Simple explanation: An operator is like a tool in a toolbox. Each tool does a specific job.
Real-life example: A bank adds interest with the + operator.
School example: A teacher adds scores with the + operator.
Home example: A family subtracts spending with the - operator.
Nigerian example: A trader multiplies price by quantity with the * operator.
Illustration:
Operator = Tool + add - subtract * multiply / divide > greater than = assign
Mini summary: An operator is a symbol that tells the computer what to do.
Definition: An expression is a piece of code that produces a value.
Why it is important: Every expression the computer reads becomes a value, like a number, text, or true/false.
Simple explanation: An expression is a mini puzzle that has one answer.
Real-life example: 2 + 3 is an expression. Its value is 5.
School example: score >= 50 is an expression. Its value is true or false.
Home example: price * 2 is an expression.
Nigerian example: quantity * unitPrice is an expression.
Illustration:
Expression → Value 2 + 3 → 5 "a" + "b" → "ab" 5 > 3 → true
Mini summary: An expression is a piece of code that gives a value.
Definition: Operands are the values that an operator works on.
Why it is important: Operators need operands to do anything.
Simple explanation: Operands are the things. Operators are what you do to them.
Real-life example: In 5 + 3, 5 and 3 are operands.
School example: In mathScore + englishScore, both scores are operands.
Home example: In rent + food, both are operands.
Nigerian example: In price * quantity, both are operands.
Illustration:
Operand Operator Operand
5 + 3
| |
operand operand
Mini summary: Operands are the values that operators work on.
Definition: A value is any piece of data, like a number, text, or true/false.
Why it is important: Operators behave differently with different types.
Simple explanation: Values are the ingredients. Operators are the cooking methods.
Real-life example: A bank stores balances as numbers and names as text.
School example: A teacher stores scores as numbers and names as text.
Home example: A family stores a shopping list as text.
Nigerian example: A trader stores prices as numbers and product names as text.
Illustration:
Common Types: Number: 42, 3.14 String: "Hello", "Ada" Boolean: true, false Null: null Undefined: undefined
Mini summary: Values come in types: number, string, boolean, null, undefined.
Definition: A statement is a full instruction. An expression is a piece that produces a value.
Why it is important: Knowing the difference helps you understand code structure.
Simple explanation: A statement is a full sentence. An expression is a phrase inside it.
Real-life example: "Pay ₦500" is a statement. "₦500" is an expression.
School example: "Write your name" is a statement. "Your name" is a value.
Home example: "Buy milk" is a statement. "milk" is a value.
Nigerian example: "Send the goods to Enugu" is a statement.
Illustration:
Statement: let total = 2 + 3;
Expression: 2 + 3
Statement: if (score > 50) { ... }
Expression: score > 50
Mini summary: Statements are full instructions. Expressions are parts that give values.
Definition: On the web, expressions control what users see and do.
Why it is important: Every button, form, and message uses expressions behind the scenes.
Simple explanation: Expressions are the "thinking" part of a website.
Real-life example: A bank login page checks if the password matches.
School example: A school portal checks if grades are above pass mark.
Home example: A shopping site calculates the cart total.
Nigerian example: A fintech app calculates transfer fees automatically.
Illustration:
Website Flow: User types → Expression checks → Result shown 🎉
Mini summary: Expressions make websites think, calculate, and react.
Definition: The browser console is a tool that lets you type and run JavaScript directly.
Why it is important: It is a safe place to test expressions quickly.
Simple explanation: The console is like a notepad where the computer answers you back.
Real-life example: A developer tests new code in the console before using it on a site.
School example: A student tests 2 + 2 in the console.
Home example: A family calculates a bill in the console.
Nigerian example: A trader calculates the total price of goods in the console.
Illustration:
Open Console:
Chrome: Ctrl + Shift + J (Windows)
Cmd + Option + J (Mac)
Firefox: Ctrl + Shift + K
Edge: Ctrl + Shift + J
Step-by-step:
2 + 3.Mini summary: The browser console is your safe playground for testing expressions.
Definition: Running an expression means typing it and pressing Enter to see its value.
Why it is important: It is the first step to writing code.
Simple explanation: Like typing a question and getting an answer immediately.
Real-life example: A developer tests a calculation before adding it to a page.
School example: A student tests 10 * 5 in the console.
Home example: A family tests the total of the groceries.
Nigerian example: A trader tests the total price of 5 bags of rice.
Illustration:
Console: > 2 + 3 < 5 > "Hello " + "Ada" < "Hello Ada" > 10 > 5 < true
Step-by-step:
2 + 3.5.10 * 10 and "a" + "b".Mini summary: Typing expressions in the console gives immediate results.
Definition: A variable is a named container that holds a value.
Why it is important: Variables let you store and reuse values.
Simple explanation: It is like a labeled box. You put a value in and use it later.
Real-life example: A bank names a value "balance".
School example: A teacher names a value "mathScore".
Home example: A family names a value "shoppingTotal".
Nigerian example: A trader names a value "totalSales".
Illustration:
let balance = 5000; let name = "Ada"; let isOpen = true;
Step-by-step:
let or const.=.Mini summary: Variables hold values in named containers.
Definition: Variables can be used inside expressions just like regular values.
Why it is important: It lets you calculate using names instead of numbers.
Simple explanation: If the value inside the box is 5, the box name becomes 5 in the puzzle.
Real-life example: A bank adds interest using the variable balance.
School example: A teacher adds mathScore + englishScore.
Home example: A family calculates rent + food + transport.
Nigerian example: A trader calculates quantity * price.
Illustration:
let a = 5; let b = 3; a + b; // 8 let price = 3000; let qty = 2; price * qty; // 6000
Mini summary: Variables can be used inside expressions to calculate values.
Definition: Operator precedence is the order in which operators are calculated.
Why it is important: It decides the final value of an expression.
Simple explanation: Like a queue — some operators go first, others wait.
Real-life example: A bank calculates multiplication before addition.
School example: In math, multiplication is done before addition.
Home example: You weigh ingredients before mixing them.
Nigerian example: A trader prices items before calculating the total.
Illustration:
2 + 3 * 4 Step 1: 3 * 4 = 12 Step 2: 2 + 12 = 14 (2 + 3) * 4 Step 1: 2 + 3 = 5 Step 2: 5 * 4 = 20
Step-by-step:
Mini summary: Operator precedence decides which part of an expression is calculated first.
Definition: Parentheses ( ) group parts of an expression and force them to be calculated first.
Why it is important: They prevent confusion and bugs.
Simple explanation: Parentheses are the "do this first" sign.
Real-life example: A bank uses ( ) to calculate fees before interest.
School example: A student uses ( ) to add scores before averaging.
Home example: A family adds groceries before adding tax.
Nigerian example: A trader adds quantity costs before applying a discount.
Illustration:
2 + 3 * 4 → 14 (2 + 3) * 4 → 20 Parentheses change the answer!
Mini summary: Parentheses tell JavaScript which part to calculate first.
Definition: Mistakes happen. Knowing them helps you avoid them.
Why it is important: A small mistake can give the wrong answer.
Simple explanation: Like typing a phone number wrong — you get the wrong person.
Real-life example: A bank uses the wrong operator and pays wrong interest.
School example: A teacher forgets parentheses and gets wrong averages.
Home example: A family miscounts a shopping total.
Nigerian example: A trader forgets multiplication and undercharges a customer.
Table of common mistakes:
| Mistake | What Happens | How to Fix |
|---|---|---|
| Forgetting parentheses | Wrong answer | Add ( ) to group |
| Mixing numbers and strings | Wrong result | Use the right type |
| Missing semicolon | Error | Add ; at the end |
| Using = instead of === | Assignment instead of check | Use === to compare |
| Wrong variable name | ReferenceError | Check spelling |
| Dividing by zero | Infinity | Check the denominator |
Mini summary: Common mistakes: missing parentheses, wrong types, missing semicolons.
Definition: Best practices are good habits that make your code clean and safe.
Why it is important: Good habits prevent bugs and help others read your code.
Simple explanation: Like keeping your desk tidy — easier to find things.
Real-life example: A bank writes clean code so any developer can understand it.
School example: A student writes neat notes for exams.
Home example: A family keeps a tidy shopping list.
Nigerian example: A business writes clear, simple code.
List of best practices:
Mini summary: Best practices: clear names, parentheses, and simple expressions.
You now have a strong foundation in operators and expressions.
What you learned:
Next steps: In Module Two, you will learn about arithmetic and assignment operators in depth.
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 understand the basics of operators and expressions. Time to go deeper!
| Word | Simple Definition |
|---|---|
| Operator | A symbol that tells the computer what to do. |
| Expression | A piece of code that produces a value. |
| Operand | A value that an operator works on. |
| Value | Any piece of data (number, text, etc.). |
| Type | The kind of value (number, string, boolean). |
| Statement | A full instruction in code. |
| Variable | A named container for a value. |
| Precedence | The order operators are calculated. |
| Parentheses | Symbols ( ) that group parts of an expression. |
| Console | A tool for testing JavaScript. |
| Number | A numeric value, like 5 or 3.14. |
| String | A text value, like "Hello". |
| Boolean | A true or false value. |
| Null | A special value meaning "nothing". |
| Undefined | A value that has not been set. |
2 + 2.let followed by a name.= and a value.;.typeof followed by a value.price * quantity for sales.balance + interest to update accounts.math + english + science.stock - sold to track goods.amount - fee to send money.20 - 5 for what is left.playerScore + 10 for a new score.price * 2 for two sweets.toys - borrowed for how many remain.booksRead + 1 for a new book.2 * 500 for two loaves of bread.income - expenses for savings.hours + minutes / 60 for total hours.cups * 2 to double a recipe.speed * time for distance.
Operand Operator Operand
5 + 3
|
V
Expression
|
V
Value: 8
Statement: let total = 2 + 3;
\_____/
Expression
Step 1: ( ) Step 2: * / Step 3: + - Step 4: left to right
let price = 3000; let qty = 2; price * qty → 6000
Module 1: Foundations
|
V
Module 2: Arithmetic & Assignment
|
V
Module 3: Comparison & Logic
|
V
Module 4: Advanced & Certification
|
V
Web Operators Expert 🎉
| Feature | Statement | Expression |
|---|---|---|
| Purpose | Full instruction | Produces a value |
| Example | let x = 5; | 2 + 3 |
| Can stand alone? | Yes | Sometimes |
| Type | Example |
|---|---|
| Number | 42, 3.14 |
| String | "Ada", "Hello" |
| Boolean | true, false |
| Null | null |
| Undefined | undefined |
| Order | Operators |
|---|---|
| 1 | ( ) |
| 2 | * / |
| 3 | + - |
| 4 | Left to right |
| Mistake | Fix |
|---|---|
| Missing ( ) | Add parentheses |
| Mixing types | Use the right type |
| Using = not === | Use === for compare |
| Missing ; | Add semicolon |
Lesson 1: An operator is a symbol that does an action.
Lesson 2: An expression produces a value.
Lesson 3: Operands are the values in an expression.
Lesson 4: Values come in types: number, string, boolean, etc.
Lesson 5: Statements are full instructions; expressions are parts.
Lesson 6: Expressions make websites think and react.
Lesson 7: The browser console is your testing tool.
Lesson 8: Running an expression gives an instant value.
Lesson 9: Variables hold values in named containers.
Lesson 10: Variables can be used inside expressions.
Lesson 11: Operator precedence decides calculation order.
Lesson 12: Parentheses group parts of an expression.
Lesson 13: Common mistakes: missing parentheses, wrong types.
Lesson 14: Best practices: clear names, parentheses, simple expressions.
Lesson 15: You now understand the basics of operators and expressions.
Congratulations! You have finished Module One of the Operators & Expressions for Web course. You learned what an operator is and what an expression is. You learned about operands, values, and data types. You learned the difference between statements and expressions. You learned how to open the browser console and run expressions. You learned how to create variables and use them in expressions. You learned about operator precedence and parentheses. You learned common mistakes and best practices. Most importantly, you now understand the foundation of every line of JavaScript you will ever write. In the next module, you will learn about arithmetic and assignment operators in depth.
Match the term to its meaning.
| Term | Meaning |
|---|---|
| 1. Operator | A. A value an operator works on |
| 2. Expression | B. A symbol that does an action |
| 3. Operand | C. A named container for a value |
| 4. Variable | D. A piece of code that produces a value |
| 5. Statement | E. A full instruction in code |
Answers: 1-B, 2-D, 3-A, 4-C, 5-E
Title: “Build a Mini Calculator in the Console”
Instructions: In groups of 3–4, open the browser console and together type 5 different expressions. Include one with parentheses. Explain each result to the class. Try to use Nigerian examples like price × quantity.
Goal: Practice typing and reading expressions.
Task: Open the browser console. Type and run at least 5 expressions:
Write down each expression and its answer.
Project: “My First JavaScript Expressions Notebook”
Create a document with at least 10 expressions:
Example:
Purpose: Total price of 2 bags of rice Code: 2 * 3000 Value: 6000 Explanation: Multiply quantity by price.
Assignment: Interview a family member who sells goods. Ask them:
Then write 5 JavaScript expressions that match their calculations.
Submit: Your 5 expressions with explanations.
In Module Two, we will dive deep into arithmetic and assignment operators. We will cover:
To prepare, complete the practical assignment and review the key vocabulary. Practice a few expressions in the browser console. Bring your curiosity!
See you in Module Two!
End of Module One – Operators & Expressions for Web