Part of the “Web Basics for Young Coders” course — written for curious 10‑ to 13‑year‑olds.
Imagine you are building a house. You need different containers to hold things: a bucket for water, a box for nails, a bag for cement. In the world of web pages, we also need containers to hold information. Those containers are called variables. And the kind of information they hold — like numbers, words, or true/false — are called data types.
In this module, you will learn how to create variables, give them names, and store different types of data. You will see how variables make your web pages smart and interactive. You will learn through stories, examples, and fun exercises. By the end, you will be able to write simple JavaScript code that remembers things — just like a human brain remembers your name!
Let’s start this journey together. Take your time. Read each lesson slowly. Try the examples on your computer (or on paper). Ready? Let’s go!
After finishing this module, you will be able to:
let, const, and var.Ada lives in Lagos, Nigeria. One day, her grandmother gave her three magic boxes. “Each box can hold only one kind of thing,” Grandma said. “The blue box holds numbers. The red box holds words. The green box holds yes or no answers.”
Ada was excited. She put her age (12) in the blue box. She put her name (“Ada”) in the red box. She put “true” in the green box because she loves jollof rice. Then she realised: if she wanted to change her age next year, she could just put a new number in the blue box. The box keeps the value safe until she needs it.
In web programming, those magic boxes are called variables. The kinds of things they hold are data types. Just like Ada’s boxes, variables help your web page remember information — your name, your score, whether you clicked a button, and much more. Are you ready to open your own magic boxes? Let’s dive in!
A variable is a named container that stores a value. You can think of it as a labelled box where you keep information.
Without variables, your web page would forget everything. Variables let you save data, change it, and use it again.
Imagine you have a box with the word “score” written on it. You put the number 10 inside. Later, you can open the box, take out 10, add 5, and put back 15. The box always has a label (the variable name) and something inside (the value).
Your school bag is a variable. Its name is “schoolBag”. Inside you put your books (values). Tomorrow you might put different books — the bag stays the same, but the contents change.
In a classroom, the teacher writes “Today’s date” on the board. That’s like a variable called todayDate. Each day she erases it and writes a new date.
Your phone’s battery percentage is a variable called batteryLevel. It changes from 100 to 99 to 98…
In a football match, the scoreboard shows “Super Eagles 2 – 1 Ghana”. The score is stored in variables like eaglesScore and ghanaScore. When a goal is scored, the variable changes.
+-------------------+
| variable name |
| "score" |
+-------------------+
| value: 10 |
+-------------------+
|
V
Later, value becomes 15
A variable is a labelled container that holds a value. You can change the value whenever you want.
Creating a variable means declaring it and giving it a name. In JavaScript we use keywords like let, const, or var.
You must tell the computer that you want a new container. The keyword is like saying “Hey computer, I’m making a new box!”
Use let when the value can change. Use const when the value must never change. Use var in older code (we prefer let and const now).
let is like a whiteboard — you can erase and write again. const is like a carved stone — once written, it stays.
Your class teacher writes the number of students present on a whiteboard (let). The school’s name on the gate is carved in stone (const).
The TV volume (let volume = 10) can change. Your date of birth (const birthday = "12 May 2012") never changes.
let fuelPrice = 600 (price changes often). const country = "Nigeria" (never changes).
let score = 0; // can change
const PI = 3.14; // cannot change
var oldStyle = "ok"; // older way
Use let for values that change, const for values that stay the same, and avoid var unless you see it in old code.
Variable names are the labels you give to your boxes. They must follow certain rules.
Good names make your code easy to read. Bad names confuse you and others.
$, and _.let, const, if (reserved words).score and Score are different.Naming a dog “Dog” is confusing. Naming it “Bingo” is better. So name your variable playerScore not s.
Instead of calling your notebook “book1”, call it “MathsNotes”.
Label your kitchen jars “Rice”, “Beans”, “Sugar” — not “Jar1”, “Jar2”.
Call your variable jollofRicePortions not jrp. Clear names help everyone.
✅ let playerScore = 100;
❌ let 2players = 5; // cannot start with number
❌ let my-name = "Ada"; // hyphen not allowed
✅ let my_name = "Ada"; // underscore is fine
Use clear, descriptive names. Start with a letter, $, or _. No spaces or hyphens.
A number data type stores numeric values, like 7, 3.14, or -5.
Numbers are used for scores, prices, ages, calculations, and much more.
You can do math with numbers: add (+), subtract (-), multiply (*), divide (/).
The price of a loaf of bread is a number. Your age is a number.
Your test score is a number. The number of pencils in your bag is a number.
The temperature in the fridge is a number. The number of eggs left is a number.
The naira price of a bus ticket (e.g., 500) is a number. The number of goals scored by the Super Eagles is a number.
let age = 12;
let price = 350.50;
let temperature = -3;
Numbers are for counting, measuring, and calculating. No quotes around them.
A string is a sequence of characters (letters, numbers, symbols) wrapped in quotes. It represents text.
Strings hold names, sentences, addresses, and any written information.
Use single quotes ' ', double quotes " ", or backticks ` ` to make a string.
Your name is a string. Your school’s name is a string.
The title of a book is a string. The answer to “What is your favourite subject?” is a string.
A text message you send is a string. Your address is a string.
"Lagos", "Jollof rice", "Nollywood" are all strings.
let name = "Ada";
let city = 'Abuja';
let greeting = `Hello, welcome!`;
Strings are text inside quotes. They can be empty ("") or long.
A boolean has only two possible values: true or false.
Booleans help your program make decisions. For example, “Is the user logged in?” true or false.
Think of a light switch: it is either ON (true) or OFF (false).
“Is it raining?” — true or false. “Do I have money?” — true or false.
“Did I finish my homework?” — true or false.
“Is the door locked?” — true or false.
“Is there fuel in the generator?” — true or false. “Did Nigeria win the match?” — true or false.
let isRaining = true;
let hasMoney = false;
Booleans are yes/no answers written as true or false (no quotes).
undefined means a variable has been declared but has no value yet. null means “no value” on purpose.
They help you know when something is missing or empty.
Imagine a box with no label (undefined) versus a box with a label but deliberately empty (null).
Your friend’s phone number is undefined if you never saved it. Your lunch box is null if you decided to fast today.
A test score is undefined if you were absent. A homework mark is null if the teacher chose not to grade it.
The TV remote battery level is undefined if the remote is broken. Your pocket money is null if you spent it all.
The price of petrol at a closed station is undefined. The number of passengers in an empty bus is null (zero is a number, null is “nothing”).
let score; // undefined
let favouriteFood = null; // intentionally empty
undefined happens automatically when you forget to give a value. null is given on purpose to mean “nothing”.
If you used let, you can give the variable a new value later.
Web pages are dynamic — things change. Scores go up, names change, counters increase.
Just write the variable name again and assign a new value with =.
Your age changes every year. So age = age + 1.
Your class attendance count changes. presentCount = presentCount + 1.
The number of slices of bread decreases. breadSlices = breadSlices - 1.
The Super Eagles score increases: eaglesScore = eaglesScore + 1.
let score = 0;
score = 10; // now score is 10
score = score + 5; // now score is 15
Variables declared with let can be updated. const cannot be updated.
Concatenation means joining strings together using the + operator.
You often need to build messages using variables, like “Hello, Ada!”
Just use + between strings and variables that hold strings.
Writing a greeting card: “Dear” + “ “ + name + “,”
Making a name tag: “Student: ” + studentName
Sending a text: “Good morning, ” + mum
“Welcome to ” + city + “, the centre of excellence!”
let firstName = "Ada";
let greeting = "Hello, " + firstName + "!";
// greeting becomes "Hello, Ada!"
Use + to join strings. Make sure to include spaces where needed.
Template literals let you insert variables inside a string using ${ } and backticks.
They make combining strings easier and cleaner, especially with many variables.
Instead of lots of +, you write one string with placeholders.
Filling a form: “My name is ${name} and I am ${age} years old.”
“Student ${name} scored ${score} marks.”
“Dinner is ${food} and it costs ₦${price}.”
“${player} scored a goal for Nigeria!”
let name = "Ada";
let age = 12;
let message = `My name is ${name} and I am ${age} years old.`;
Use backticks and ${ } to drop variables right into strings.
Data types tell the computer how to treat a value — as a number, text, true/false, etc.
If you mix types, you can get strange results. For example, "5" + 5 gives "55" (string), not 10.
Numbers add. Strings join. Booleans help make decisions. Using the wrong type is like putting water in a petrol tank.
If a shop’s price is stored as a string, adding two prices might join them instead of adding them.
If your test scores are strings, averaging them will give a weird result.
If your shopping list total is a string, you cannot calculate change.
If bus fares are strings, adding them gives “500300” instead of 800.
let a = 5; // number
let b = "5"; // string
console.log(a + a); // 10
console.log(b + b); // "55"
Always use the correct data type for the job. Numbers for math, strings for text.
typeoftypeof is an operator that tells you the data type of a value.
It helps you find mistakes when your code behaves strangely.
Just write typeof variableName and it returns a string like "number" or "string".
Like checking the label on a food packet to see if it’s sugar or salt.
Like checking if an answer is a number or a word before marking it.
Like checking if the remote control is for the TV or the fan.
Like checking if a naira note is ₦1000 or ₦500 before using it.
let age = 12;
console.log(typeof age); // "number"
let name = "Ada";
console.log(typeof name); // "string"
typeof is your friend. Use it to check what type a variable holds.
Sometimes you need to change a string to a number, or a number to a string. This is called type conversion.
User input from a web page often comes as strings. You must convert them to numbers for math.
Use Number() to turn a string into a number. Use String() to turn a number into a string.
When you type your age in a form, it arrives as “12” (string). You convert it to 12 (number) to calculate next year’s age.
If your test score is given as “85” (string), you convert it to 85 to find the average.
If your shopping list says “3” apples, you convert it to 3 to count them.
If a bus conductor says “₦500” (string), you convert to 500 to give correct change.
let strNum = "10";
let num = Number(strNum); // 10
let backToStr = String(num); // "10"
Use Number() and String() to switch between types when needed.
A constant is a variable whose value cannot be changed after it is set. In JavaScript we use const.
Some values should never change: your birth date, the value of PI, the name of your country.
Think of a carved stone tablet. Once written, it stays forever. That’s const.
Your national identity number is a constant. Your school’s name is a constant.
The school’s motto is a constant. The number of days in a week (7) is a constant.
Your house address is a constant. The number of months in a year (12) is a constant.
“Nigeria” is a constant. The number of states (36) is a constant.
const BIRTH_YEAR = 2012;
// BIRTH_YEAR = 2013; ❌ Error: cannot change
Use const for values that must stay the same. It prevents accidental changes.
Now we combine variables and data types to make a small, useful program.
This is how real web pages work — they store data in variables and use it to display messages.
Let’s write a program that greets a user and calculates their age next year.
A website that says “Welcome, Ada! You will be 13 next year.”
A class register that shows “Student: Ada, Age: 12, Next year: 13”.
A shopping list that says “3 apples, 2 bread, total 5 items”.
A football app that shows “Super Eagles scored 2 goals. Next match: Nigeria vs Ghana.”
let userName = "Ada";
let userAge = 12;
let nextAge = userAge + 1;
let message = `Hello ${userName}! Next year you will be ${nextAge}.`;
console.log(message);
// Output: Hello Ada! Next year you will be 13.
Variables + data types + string concatenation = useful web messages. You just wrote a tiny program!
| Word | Simple Definition |
|---|---|
| Variable | A named box that holds a value. |
| Data Type | The kind of value, like number or text. |
| Number | A numeric value, like 7 or 3.14. |
| String | Text inside quotes, like "hello". |
| Boolean | True or false. |
| Undefined | A variable with no value yet. |
| Null | An empty value given on purpose. |
| Declaration | Creating a variable with let, const, or var. |
| Assignment | Giving a value to a variable using =. |
| Concatenation | Joining strings with +. |
| Template Literal | A string with backticks that can include ${}. |
| Type Conversion | Changing a value from one type to another. |
typeof | An operator that tells you the data type. |
let for changeable values, const for fixed values.let variable but not a const.+ to join strings, but be careful with numbers and strings.` `) make combining strings easier.typeof helps you check data types.Number() and String().let or const.playerScore).= to assign a value (e.g., let playerScore = 0;).let, you can change the value: playerScore = 10;.+ to join: "Score: " + 10 gives "Score: 10".`Score: ${10}`.let price = 1500; (number). let currency = "₦"; (string).let jollofPortions = 3; (number). let isSpicy = true; (boolean).let trafficLevel = "heavy"; (string).let eaglesScore = 2; let opponentScore = 1; let isWinning = true;.let movieTitle = "The Wedding Party"; let releaseYear = 2016;.let lives = 3; After losing a life: lives = lives - 1;let slices = 8; You eat 2: slices = slices - 2;let age = 10; Next year: age = age + 1;let heroName = "Spider-Boy";let likesChocolate = true;let alarmTime = "7:00 AM"; (string).let batteryPercentage = 85; (number).let isLightOn = false; (boolean).let item1 = "Milk"; let item2 = "Bread"; (strings).let steps = 3000; (number).undefined and null are not errors; they are tools.int score = 0;). JavaScript is more relaxed.typeof operator is so useful that it exists in almost every programming language.typeof null returns "object" — a famous bug in JavaScript that was never fixed to avoid breaking old websites.$, or _."123", but they are still text.let for change, const for no change.+ or template literals.typeof.Number() and String().| Mistake | Why it’s wrong | Fix |
|---|---|---|
let 2cool = "yes"; | Variable names cannot start with a number. | let cool2 = "yes"; |
let my-name = "Ada"; | Hyphens are not allowed. | let my_name = "Ada"; |
const age = 12; age = 13; | Cannot reassign a constant. | Use let if it changes. |
let score = "10"; let total = score + 5; | Results in "105" (string) not 15. | Use Number(score) + 5. |
let name = Ada; | Missing quotes — Ada is seen as a variable, not text. | let name = "Ada"; |
const by default, and let only when you need to change the value.playerScore not x.myFavoriteFood.;.typeof when debugging.
+---------------------+
| name: "score" |
+---------------------+
| value: 10 |
+---------------------+
|
V
After a goal:
+---------------------+
| name: "score" |
+---------------------+
| value: 11 |
+---------------------+
Start
|
V
Is it a number? ----> Yes ----> data type: Number
|
No
|
V
Is it in quotes? ----> Yes ----> data type: String
|
No
|
V
Is it true/false? ----> Yes ----> data type: Boolean
|
No
|
V
Is it undefined? ----> Yes ----> data type: Undefined
|
No
|
V
It might be null or object.
1. Declare: let score;
2. Assign: score = 0;
3. Use: console.log(score);
4. Change: score = 10;
5. Use again: console.log(score);
let vs const vs var| Keyword | Can change? | When to use |
|---|---|---|
let | Yes | For values that will change. |
const | No | For values that stay the same. |
var | Yes | Old code; avoid in new code. |
| Type | Example | Used for |
|---|---|---|
| Number | 42, 3.14 | Math, counting, measuring |
| String | "Ada", 'Lagos' | Text, names, messages |
| Boolean | true, false | Decisions, yes/no |
| Undefined | let x; | No value yet |
| Null | let y = null; | Empty on purpose |
Each lesson above ended with a Mini Summary. That’s your quick recap. If you forget something, go back to that lesson and read the mini summary again.
In this module, you learned that variables are named containers for data. You discovered how to create them with let, const, and var (but we prefer let and const). You explored the main data types: numbers, strings, booleans, undefined, and null. You learned how to change values, combine strings, use template literals, check types with typeof, and convert between types. You also saw many examples from Nigeria, home, school, and fun games. You are now ready to use variables in your own web projects!
const instead of let? To prevent accidental changes.const variable? No, it will cause an error.undefined mean? A variable has been declared but has no value yet.null and undefined? null is given on purpose; undefined happens automatically.+ or template literals with ${}.typeof for? It tells you the data type of a value.Number("123").Match the item on the left with its correct data type on the right.
| Item | Data Type |
|---|---|
1. "Lagos" | A. Number |
2. 42 | B. String |
3. true | C. Boolean |
4. let x; | D. Undefined |
5. null | E. Null |
Answers: 1-B, 2-A, 3-C, 4-D, 5-E
“Variable Boxes” Game
Work in groups of 3 or 4. Each group gets three paper boxes (or drawn boxes). Label them “Number”, “String”, “Boolean”. Then one person reads out a value (e.g., “12”, “Ada”, “true”, “false”, “Lagos”, “3.14”). The group must quickly put the value in the correct box. After 10 values, switch roles. The group with the most correct placements wins!
Write down 5 variables you would use to describe yourself. For each, write the variable name, the value, and the data type. Example:
let myName = "Ada"; — Stringlet myAge = 12; — Numberlet likesJollof = true; — Booleanlet favouriteSubject = "Maths"; — Stringlet shoeSize = 36; — NumberCreate a simple web page (or a plain text file) that uses variables to display information about you. Use at least 4 variables of different data types. Then combine them into a sentence using template literals.
Example:
let name = "Ada";
let age = 12;
let city = "Lagos";
let likesCoding = true;
let message = `My name is ${name}. I am ${age} years old. I live in ${city}. It is ${likesCoding} that I like coding.`;
console.log(message);
You can write this in a JavaScript file and run it in your browser’s console, or just write it on paper and show your teacher.
yourName (string), yourAge (number), isStudent (boolean).yourAge to your age next year. Print the new message.typeof on each variable and print the results.let for changing values, const for fixed values.+ or template literals.typeof; convert with Number() and String().const variable?undefined and null?
In Module Four, we will learn about Operators and Expressions. You will discover how to do math with variables, compare values, and make decisions using if statements. To get ready, make sure you are comfortable creating variables and knowing their data types. Try the practical assignment above. When you are ready, turn the page and let’s continue your coding adventure!
End of Module Three