“Variables & Data Types for Web” – Learn how JavaScript remembers information
Welcome, young web coder! Have you ever wondered how a website remembers your name after you log in? Or how a game knows your score? The answer is variables and data types.
A variable is a named container that holds a value. A data type tells the computer what kind of value it is — a number, text, true/false, or something else. Every website you use, from Facebook to your school portal, uses variables and data types thousands of times.
In this module, we will learn what variables and data types are, how to create them, and how to use them in JavaScript. We will use the browser console to test our code. 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 school asked every student to fill a registration form. The form asked for name, age, class, and whether the student had paid fees.
Ada looked at the form and thought, "This is exactly what variables do in JavaScript!" She opened the browser console and typed:
let name = "Ada"; let age = 13; let studentClass = "JSS3"; let hasPaidFees = true;
Each line created a variable. The variable name held the text "Ada". The variable age held the number 13. The variable studentClass held the text "JSS3". The variable hasPaidFees held the value true.
Ada then typed:
console.log("Welcome, " + name);
console.log("You are " + age + " years old.");
The console printed:
Welcome, Ada You are 13 years old.
Ada smiled. She realized that a form is just a set of variables. Every website she had ever used was built the same way — with variables holding information.
From that day, Ada saw the world differently. A shop is a variable. A price is a variable. A customer name is a variable. Her mother’s shop list could be turned into code!
Moral of the story: Variables are named containers for values. Data types tell us what kind of value is inside. Together, they let websites remember and use information.
Definition: A variable is a named container that holds a value.
Why it is important: Variables let your code remember information and reuse it.
Simple explanation: A variable is like a labeled box. You write a name on the box, put something inside, and use it later.
Real-life example: A bank names a value "balance".
School example: A teacher names a value "score".
Home example: A family names a value "shoppingTotal".
Nigerian example: A trader names a value "priceOfRice".
Illustration:
Variable = Labeled Box +-----------+ | name: Ada | +-----------+ +-----------+ | age: 13 | +-----------+
Mini summary: A variable is a labeled container that holds a value.
Definition: Variables store information so we can use it again and again.
Why it is important: Without variables, we would have to type the same value many times, and if it changed, we would have to change it everywhere.
Simple explanation: It is like having a labelled jar of sugar in the kitchen. You use it many times without buying new sugar each time.
Real-life example: A bank keeps a customer balance in a variable and updates it with every transaction.
School example: A teacher keeps a class list in a variable and adds new students.
Home example: A family keeps a shopping list in a variable and adds items.
Nigerian example: A trader keeps the price of goods in variables.
Illustration:
Without variables: "Ada" ... "Ada" ... "Ada" (repeat, repeat)
With variables: let name = "Ada";
console.log(name);
Mini summary: Variables save time and keep information organized.
Definition: Creating a variable means giving it a name and a value in code.
Why it is important: It is the first step to writing any program.
Simple explanation: You write let or const, then a name, then an equals sign, then a value.
Real-life example: A bank creates a variable balance = 5000.
School example: A teacher creates score = 90.
Home example: A family creates shoppingTotal = 2500.
Nigerian example: A trader creates priceOfRice = 3000.
Illustration:
let name = "Ada"; let age = 13; let hasPaidFees = true;
Step-by-step:
let or const.=.;.Mini summary: Creating a variable means giving it a name and a value.
Definition: let creates a variable whose value can change. const creates a variable whose value cannot change.
Why it is important: Some values should stay the same. Others change.
Simple explanation: let is a whiteboard you can erase and rewrite. const is a stone tablet you write once.
Real-life example: A bank uses let balance (it changes) and const bankName (it does not).
School example: A teacher uses let score and const schoolName.
Home example: A family uses let monthlySpending and const homeAddress.
Nigerian example: A trader uses let stock and const shopName.
Illustration:
let age = 13; age = 14; // OK const birthday = "1 Jan"; birthday = "2 Jan"; // ERROR
Mini summary: Use let for changing values and const for fixed values.
Definition: Variable names are the labels you give your containers.
Why it is important: Clear names make code easy to read.
Simple explanation: Names should describe what is inside.
Real-life example: A bank calls it balance, not b.
School example: A teacher calls it mathScore, not m.
Home example: A family calls it monthlyBudget, not mb.
Nigerian example: A trader calls it totalSales, not ts.
Illustration:
Good: let customerName = "Ada"; Good: let priceOfRice = 3000; Bad: let x = "Ada"; Bad: let p = 3000;
Step-by-step:
totalSales).let.Mini summary: Use clear, descriptive names in camelCase.
Definition: A data type tells the computer what kind of value a variable holds.
Why it is important: Different types behave differently.
Simple explanation: A data type is like a container: a bottle for water, a box for shoes.
Real-life example: A bank stores money as numbers and names as text.
School example: A teacher stores scores as numbers and names as text.
Home example: A family stores ages as numbers and addresses 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
Object: { name: "Ada" }
Array: [1, 2, 3]
Mini summary: A data type tells the computer what kind of value a variable holds.
Definition: The number type is used for numeric values.
Why it is important: Numbers are used for math and counting.
Simple explanation: Numbers can be whole or decimal.
Real-life example: A bank uses numbers for account balances.
School example: A teacher uses numbers for scores.
Home example: A family uses numbers for prices.
Nigerian example: A trader uses numbers for quantities and prices.
Illustration:
let age = 13; // whole number let price = 3000.50; // decimal let score = 90; typeof age → "number"
Mini summary: Numbers are used for math and values like age, price, score.
Definition: A string is a piece of text inside quotes.
Why it is important: Text is everywhere on the web — names, messages, titles.
Simple explanation: A string is any text wrapped in quotes.
Real-life example: A bank stores customer names as strings.
School example: A teacher stores student names as strings.
Home example: A family stores addresses as strings.
Nigerian example: A trader stores product names as strings.
Illustration:
let name = "Ada"; let city = "Lagos"; let message = "Welcome!"; typeof name → "string"
Mini summary: Strings are text inside quotes.
Definition: A boolean is a value that is either true or false.
Why it is important: Booleans control decisions on websites.
Simple explanation: A boolean answers yes/no questions.
Real-life example: A bank checks if a customer has paid fees (true/false).
School example: A teacher checks if a student is present (true/false).
Home example: A family checks if the door is locked (true/false).
Nigerian example: A trader checks if a product is in stock (true/false).
Illustration:
let hasPaidFees = true; let isOpen = false; typeof hasPaidFees → "boolean"
Mini summary: Booleans are true or false values used for decisions.
Definition: JavaScript has more types: null, undefined, object, array.
Why it is important: Real data is not just numbers and text.
Simple explanation: Each type is a special tool for a special job.
Real-life example: A bank uses objects to store customer records.
School example: A teacher uses arrays to store class scores.
Home example: A family uses arrays for shopping lists.
Nigerian example: A trader uses objects for product info.
Illustration:
null: let price = null; // empty on purpose
undefined: let score; // not set yet
object: let student = { name: "Ada" };
array: let scores = [85, 92, 78];
Mini summary: JavaScript also has null, undefined, objects, and arrays.
Definition: typeof is an operator that tells you the type of a value.
Why it is important: It helps you check data before using it.
Simple explanation: typeof is like asking, "What is this?"
Real-life example: A bank checks if a value is a number before adding interest.
School example: A teacher checks if a score is a number before averaging.
Home example: A family checks if a price is a number before budgeting.
Nigerian example: A trader checks if a quantity is a number before selling.
Illustration:
typeof "Hello" → "string" typeof 42 → "number" typeof true → "boolean" typeof undefined → "undefined"
Mini summary: typeof tells you the data type of a value.
Definition: The browser console is a tool for testing JavaScript.
Why it is important: It is a safe place to try variables and see results instantly.
Simple explanation: The console is like a notebook that answers back.
Real-life example: A developer tests variables before adding them to a page.
School example: A student tests let age = 13; in the console.
Home example: A family tests a shopping total.
Nigerian example: A trader tests the total price of goods.
Illustration:
Open Console:
Chrome: Ctrl + Shift + J (Windows)
Cmd + Option + J (Mac)
Firefox: Ctrl + Shift + K
Edge: Ctrl + Shift + J
Step-by-step:
let name = "Ada"; and press Enter.name and press Enter to see the value.Mini summary: The browser console is your safe playground for testing variables.
Definition: Every website uses variables to remember user data.
Why it is important: Variables make websites personalized.
Simple explanation: When a website says "Hello, Ada", it used a variable.
Real-life example: A bank shows your balance using a variable.
School example: A school portal shows your name using a variable.
Home example: A shopping site shows your cart total using a variable.
Nigerian example: A fintech app shows your balance using a variable.
Illustration:
Website Flow: User logs in → name stored in variable → "Hello, Ada" shown 🎉
Mini summary: Real websites use variables to greet and remember users.
Definition: Mistakes happen. Knowing them helps you avoid them.
Why it is important: Small mistakes can stop your code.
Simple explanation: Like writing the wrong label on a box.
Real-life example: A bank mixes up two account balances.
School example: A teacher swaps two students’ scores.
Home example: A family reads the wrong shopping total.
Nigerian example: A trader quotes the wrong price.
Table of common mistakes:
| Mistake | What Happens | How to Fix |
|---|---|---|
| Starting name with a number | Syntax error | Start with a letter |
| Using reserved words | Syntax error | Pick another name |
| Reassigning const | Error | Use let if value changes |
| Mixing types | Wrong result | Use correct type |
| Forgetting semicolon | Error | Add ; at the end |
| Using undefined value | undefined result | Check before use |
Mini summary: Common mistakes: bad names, mixing types, missing semicolons.
Definition: Best practices are good habits that make code clean and safe.
Why it is important: Good habits prevent bugs and help others read your code.
Simple explanation: Like keeping a tidy desk.
Real-life example: A bank writes clean code so any developer can read 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:
const by default.let only when the value changes.typeof.Mini summary: Best practices: const by default, clear names, correct types.
You now have a strong foundation in variables and data types.
What you learned:
Next steps: In Module Two, you will learn about strings, numbers, and booleans in depth.
Illustration:
Your Learning Journey:
Module 1: Foundations
|
V
Module 2: Strings, Numbers, Booleans
|
V
Module 3: Objects, Arrays, Special Types
|
V
Module 4: Conversion, Scope & Certification
|
V
Data Types Expert 🎉
Mini summary: You now understand the basics of variables and data types. Time to go deeper!
| Word | Simple Definition |
|---|---|
| Variable | A named container for a value. |
| Value | Any piece of data (number, text, etc.). |
| Data Type | The kind of value (number, string, etc.). |
| let | Creates a variable that can change. |
| const | Creates a variable that cannot change. |
| 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. |
| Object | A collection of key-value pairs. |
| Array | A list of values. |
| typeof | An operator that tells the type of a value. |
| Console | A tool for testing JavaScript. |
| camelCase | A naming style like totalSales. |
let or const.=.;.let name = "Ada";.name and press Enter."Ada".typeof "Hello"."string".let.const.petName = "Buddy".playerScore = 500.favouriteSnack = "Chin Chin".toyCount = 12.booksRead = 5.shoppingTotal = 5000.monthlyBudget = 50000.currentHour = 14.numberOfCups = 2.distanceKm = 120.let without a value?a = b = 5?+-----------+ | name: Ada | +-----------+ +-----------+ | age: 13 | +-----------+
let → whiteboard (can change) const → stone tablet (cannot change)
Number: 42, 3.14
String: "Hello", "Ada"
Boolean: true, false
Null: null
Undefined: undefined
Object: { name: "Ada" }
Array: [1, 2, 3]
typeof "Hello" → "string" typeof 42 → "number" typeof true → "boolean"
Module 1: Foundations
|
V
Module 2: Strings, Numbers, Booleans
|
V
Module 3: Objects, Arrays, Special Types
|
V
Module 4: Conversion, Scope & Certification
|
V
Data Types Expert 🎉
| Feature | let | const |
|---|---|---|
| Can change? | Yes | No |
| Best for | Changing values | Fixed values |
| Example | let score = 90 | const pi = 3.14 |
| Type | Example |
|---|---|
| Number | 42, 3.14 |
| String | "Ada", "Hello" |
| Boolean | true, false |
| Null | null |
| Undefined | undefined |
| Object | { name: "Ada" } |
| Array | [1, 2, 3] |
| Good | Bad |
|---|---|
| customerName | cn |
| totalSales | ts |
| priceOfRice | p |
| monthlyBudget | mb |
| Value | typeof |
|---|---|
| "hi" | string |
| 5 | number |
| true | boolean |
| undefined | undefined |
| null | object |
Lesson 1: A variable is a named container for a value.
Lesson 2: Variables save time and keep information organized.
Lesson 3: Create variables with let or const.
Lesson 4: let changes; const does not.
Lesson 5: Use clear names in camelCase.
Lesson 6: Data types describe what kind of value is inside.
Lesson 7: Numbers are for math and counting.
Lesson 8: Strings are text inside quotes.
Lesson 9: Booleans are true or false.
Lesson 10: Other types: null, undefined, object, array.
Lesson 11: typeof tells the type of a value.
Lesson 12: The console is your testing ground.
Lesson 13: Websites use variables to greet and remember users.
Lesson 14: Common mistakes: bad names, mixing types.
Lesson 15: Best practices: const by default, clear names.
Lesson 16: You now understand the basics of variables and data types.
Congratulations! You have finished Module One of the Variables & Data Types for Web course. You learned what a variable is, why variables matter, and how to create them. You learned about let and const, naming rules, and common data types. You learned how to use typeof to check types and how to test code in the browser console. You learned how real websites use variables. You learned common mistakes and best practices. Most importantly, you now understand the foundation of every JavaScript program. In the next module, you will learn about strings, numbers, and booleans in depth.
Match the term to its meaning.
| Term | Meaning |
|---|---|
| 1. Variable | A. The kind of value |
| 2. Data type | B. A named container for a value |
| 3. let | C. Tells the type of a value |
| 4. const | D. A variable that can change |
| 5. typeof | E. A variable that cannot change |
Answers: 1-B, 2-A, 3-D, 4-E, 5-C
Title: “Create a Class Register Together”
Instructions: In groups of 3–4, create 5 variables for a class register: studentName, studentAge, studentClass, hasPaidFees, and favouriteSubject. Print them using console.log. Present to the class.
Goal: Practice variables and data types.
Task: In the browser console, create:
Write down each and its result.
Project: “My First JavaScript Profile”
Create a small script with variables that describe you:
Print each using console.log() with template literals.
Example:
let name = "Ada";
let age = 13;
let city = "Lagos";
let likesCoding = true;
let favouriteFood = "Jollof rice";
console.log(`My name is ${name}.`);
console.log(`I am ${age} years old and I live in ${city}.`);
console.log(`I like coding: ${likesCoding}.`);
console.log(`My favourite food is ${favouriteFood}.`);
Assignment: Ask a family member about a small business. Then write JavaScript that:
Submit: Your code and a short explanation.
In Module Two, we will learn about strings, numbers, and booleans in depth. We will cover:
To prepare, complete the practical assignment and review the key vocabulary. Practice a few variables in the browser console. Bring your curiosity!
See you in Module Two!
End of Module One – Variables & Data Types for Web