Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Variables and Data Types for Web · Lesson 4 of 5

Data Types for the Web

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
4
Module Three: Variables & Data Types for the Web

📘 Module Three: Variables & Data Types for the Web

Part of the “Web Basics for Young Coders” course — written for curious 10‑ to 13‑year‑olds.

🌟 Module Introduction

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!

🎯 Learning Objectives

After finishing this module, you will be able to:

  • Explain what a variable is using simple words.
  • Create variables in JavaScript using let, const, and var.
  • Name variables correctly (rules and good habits).
  • Identify and use basic data types: numbers, strings, booleans, undefined, and null.
  • Change the value inside a variable.
  • Combine variables with text (string concatenation).
  • Understand why data types matter in real web pages.
  • Spot and fix common mistakes with variables.
  • Use variables to solve simple problems.
  • Build a tiny mini‑project that uses variables and data types.

📖 Warm-up Story: Ada and the Magic Boxes

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!

📚 Lesson 1: What is a Variable?

Definition

A variable is a named container that stores a value. You can think of it as a labelled box where you keep information.

Why it is important

Without variables, your web page would forget everything. Variables let you save data, change it, and use it again.

Simple explanation

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).

Real-life example

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.

School example

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.

Home example

Your phone’s battery percentage is a variable called batteryLevel. It changes from 100 to 99 to 98…

Nigerian example

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.

Illustration

   +-------------------+
   |   variable name   |
   |     "score"       |
   +-------------------+
   |   value:  10      |
   +-------------------+
          |
          V
   Later, value becomes 15
    

Mini summary

A variable is a labelled container that holds a value. You can change the value whenever you want.

📚 Lesson 2: How to Create a Variable in JavaScript

Definition

Creating a variable means declaring it and giving it a name. In JavaScript we use keywords like let, const, or var.

Why it is important

You must tell the computer that you want a new container. The keyword is like saying “Hey computer, I’m making a new box!”

Simple explanation

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).

Real-life example

let is like a whiteboard — you can erase and write again. const is like a carved stone — once written, it stays.

School example

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).

Home example

The TV volume (let volume = 10) can change. Your date of birth (const birthday = "12 May 2012") never changes.

Nigerian example

let fuelPrice = 600 (price changes often). const country = "Nigeria" (never changes).

Illustration

   let score = 0;          // can change
   const PI = 3.14;        // cannot change
   var oldStyle = "ok";    // older way
    

Mini summary

Use let for values that change, const for values that stay the same, and avoid var unless you see it in old code.

📚 Lesson 3: Naming Your Variables

Definition

Variable names are the labels you give to your boxes. They must follow certain rules.

Why it is important

Good names make your code easy to read. Bad names confuse you and others.

Simple explanation

  • Names can contain letters, numbers, $, and _.
  • They cannot start with a number.
  • They cannot be words like let, const, if (reserved words).
  • They are case‑sensitive: score and Score are different.

Real-life example

Naming a dog “Dog” is confusing. Naming it “Bingo” is better. So name your variable playerScore not s.

School example

Instead of calling your notebook “book1”, call it “MathsNotes”.

Home example

Label your kitchen jars “Rice”, “Beans”, “Sugar” — not “Jar1”, “Jar2”.

Nigerian example

Call your variable jollofRicePortions not jrp. Clear names help everyone.

Illustration

   ✅ let playerScore = 100;
   ❌ let 2players = 5;     // cannot start with number
   ❌ let my-name = "Ada";  // hyphen not allowed
   ✅ let my_name = "Ada";  // underscore is fine
    

Mini summary

Use clear, descriptive names. Start with a letter, $, or _. No spaces or hyphens.

📚 Lesson 4: Data Type – Numbers

Definition

A number data type stores numeric values, like 7, 3.14, or -5.

Why it is important

Numbers are used for scores, prices, ages, calculations, and much more.

Simple explanation

You can do math with numbers: add (+), subtract (-), multiply (*), divide (/).

Real-life example

The price of a loaf of bread is a number. Your age is a number.

School example

Your test score is a number. The number of pencils in your bag is a number.

Home example

The temperature in the fridge is a number. The number of eggs left is a number.

Nigerian example

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.

Illustration

   let age = 12;
   let price = 350.50;
   let temperature = -3;
    

Mini summary

Numbers are for counting, measuring, and calculating. No quotes around them.

📚 Lesson 5: Data Type – Strings

Definition

A string is a sequence of characters (letters, numbers, symbols) wrapped in quotes. It represents text.

Why it is important

Strings hold names, sentences, addresses, and any written information.

Simple explanation

Use single quotes ' ', double quotes " ", or backticks ` ` to make a string.

Real-life example

Your name is a string. Your school’s name is a string.

School example

The title of a book is a string. The answer to “What is your favourite subject?” is a string.

Home example

A text message you send is a string. Your address is a string.

Nigerian example

"Lagos", "Jollof rice", "Nollywood" are all strings.

Illustration

   let name = "Ada";
   let city = 'Abuja';
   let greeting = `Hello, welcome!`;
    

Mini summary

Strings are text inside quotes. They can be empty ("") or long.

📚 Lesson 6: Data Type – Booleans

Definition

A boolean has only two possible values: true or false.

Why it is important

Booleans help your program make decisions. For example, “Is the user logged in?” true or false.

Simple explanation

Think of a light switch: it is either ON (true) or OFF (false).

Real-life example

“Is it raining?” — true or false. “Do I have money?” — true or false.

School example

“Did I finish my homework?” — true or false.

Home example

“Is the door locked?” — true or false.

Nigerian example

“Is there fuel in the generator?” — true or false. “Did Nigeria win the match?” — true or false.

Illustration

   let isRaining = true;
   let hasMoney = false;
    

Mini summary

Booleans are yes/no answers written as true or false (no quotes).

📚 Lesson 7: Data Type – Undefined and Null

Definition

undefined means a variable has been declared but has no value yet. null means “no value” on purpose.

Why it is important

They help you know when something is missing or empty.

Simple explanation

Imagine a box with no label (undefined) versus a box with a label but deliberately empty (null).

Real-life example

Your friend’s phone number is undefined if you never saved it. Your lunch box is null if you decided to fast today.

School example

A test score is undefined if you were absent. A homework mark is null if the teacher chose not to grade it.

Home example

The TV remote battery level is undefined if the remote is broken. Your pocket money is null if you spent it all.

Nigerian example

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”).

Illustration

   let score;          // undefined
   let favouriteFood = null;  // intentionally empty
    

Mini summary

undefined happens automatically when you forget to give a value. null is given on purpose to mean “nothing”.

📚 Lesson 8: Changing the Value of a Variable

Definition

If you used let, you can give the variable a new value later.

Why it is important

Web pages are dynamic — things change. Scores go up, names change, counters increase.

Simple explanation

Just write the variable name again and assign a new value with =.

Real-life example

Your age changes every year. So age = age + 1.

School example

Your class attendance count changes. presentCount = presentCount + 1.

Home example

The number of slices of bread decreases. breadSlices = breadSlices - 1.

Nigerian example

The Super Eagles score increases: eaglesScore = eaglesScore + 1.

Illustration

   let score = 0;
   score = 10;    // now score is 10
   score = score + 5;  // now score is 15
    

Mini summary

Variables declared with let can be updated. const cannot be updated.

📚 Lesson 9: Combining Strings (Concatenation)

Definition

Concatenation means joining strings together using the + operator.

Why it is important

You often need to build messages using variables, like “Hello, Ada!”

Simple explanation

Just use + between strings and variables that hold strings.

Real-life example

Writing a greeting card: “Dear” + “ “ + name + “,”

School example

Making a name tag: “Student: ” + studentName

Home example

Sending a text: “Good morning, ” + mum

Nigerian example

“Welcome to ” + city + “, the centre of excellence!”

Illustration

   let firstName = "Ada";
   let greeting = "Hello, " + firstName + "!";
   // greeting becomes "Hello, Ada!"
    

Mini summary

Use + to join strings. Make sure to include spaces where needed.

📚 Lesson 10: Template Literals (Backticks)

Definition

Template literals let you insert variables inside a string using ${ } and backticks.

Why it is important

They make combining strings easier and cleaner, especially with many variables.

Simple explanation

Instead of lots of +, you write one string with placeholders.

Real-life example

Filling a form: “My name is ${name} and I am ${age} years old.”

School example

“Student ${name} scored ${score} marks.”

Home example

“Dinner is ${food} and it costs ₦${price}.”

Nigerian example

“${player} scored a goal for Nigeria!”

Illustration

   let name = "Ada";
   let age = 12;
   let message = `My name is ${name} and I am ${age} years old.`;
    

Mini summary

Use backticks and ${ } to drop variables right into strings.

📚 Lesson 11: Why Data Types Matter

Definition

Data types tell the computer how to treat a value — as a number, text, true/false, etc.

Why it is important

If you mix types, you can get strange results. For example, "5" + 5 gives "55" (string), not 10.

Simple explanation

Numbers add. Strings join. Booleans help make decisions. Using the wrong type is like putting water in a petrol tank.

Real-life example

If a shop’s price is stored as a string, adding two prices might join them instead of adding them.

School example

If your test scores are strings, averaging them will give a weird result.

Home example

If your shopping list total is a string, you cannot calculate change.

Nigerian example

If bus fares are strings, adding them gives “500300” instead of 800.

Illustration

   let a = 5;        // number
   let b = "5";      // string
   console.log(a + a);  // 10
   console.log(b + b);  // "55"
    

Mini summary

Always use the correct data type for the job. Numbers for math, strings for text.

📚 Lesson 12: Type Checking with typeof

Definition

typeof is an operator that tells you the data type of a value.

Why it is important

It helps you find mistakes when your code behaves strangely.

Simple explanation

Just write typeof variableName and it returns a string like "number" or "string".

Real-life example

Like checking the label on a food packet to see if it’s sugar or salt.

School example

Like checking if an answer is a number or a word before marking it.

Home example

Like checking if the remote control is for the TV or the fan.

Nigerian example

Like checking if a naira note is ₦1000 or ₦500 before using it.

Illustration

   let age = 12;
   console.log(typeof age);  // "number"
   let name = "Ada";
   console.log(typeof name); // "string"
    

Mini summary

typeof is your friend. Use it to check what type a variable holds.

📚 Lesson 13: Converting Between Data Types

Definition

Sometimes you need to change a string to a number, or a number to a string. This is called type conversion.

Why it is important

User input from a web page often comes as strings. You must convert them to numbers for math.

Simple explanation

Use Number() to turn a string into a number. Use String() to turn a number into a string.

Real-life example

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.

School example

If your test score is given as “85” (string), you convert it to 85 to find the average.

Home example

If your shopping list says “3” apples, you convert it to 3 to count them.

Nigerian example

If a bus conductor says “₦500” (string), you convert to 500 to give correct change.

Illustration

   let strNum = "10";
   let num = Number(strNum);   // 10
   let backToStr = String(num); // "10"
    

Mini summary

Use Number() and String() to switch between types when needed.

📚 Lesson 14: Constants and When to Use Them

Definition

A constant is a variable whose value cannot be changed after it is set. In JavaScript we use const.

Why it is important

Some values should never change: your birth date, the value of PI, the name of your country.

Simple explanation

Think of a carved stone tablet. Once written, it stays forever. That’s const.

Real-life example

Your national identity number is a constant. Your school’s name is a constant.

School example

The school’s motto is a constant. The number of days in a week (7) is a constant.

Home example

Your house address is a constant. The number of months in a year (12) is a constant.

Nigerian example

“Nigeria” is a constant. The number of states (36) is a constant.

Illustration

   const BIRTH_YEAR = 2012;
   // BIRTH_YEAR = 2013;  ❌ Error: cannot change
    

Mini summary

Use const for values that must stay the same. It prevents accidental changes.

📚 Lesson 15: Putting It All Together – A Tiny Program

Definition

Now we combine variables and data types to make a small, useful program.

Why it is important

This is how real web pages work — they store data in variables and use it to display messages.

Simple explanation

Let’s write a program that greets a user and calculates their age next year.

Real-life example

A website that says “Welcome, Ada! You will be 13 next year.”

School example

A class register that shows “Student: Ada, Age: 12, Next year: 13”.

Home example

A shopping list that says “3 apples, 2 bread, total 5 items”.

Nigerian example

A football app that shows “Super Eagles scored 2 goals. Next match: Nigeria vs Ghana.”

Illustration

   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.
    

Mini summary

Variables + data types + string concatenation = useful web messages. You just wrote a tiny program!

📖 Key Vocabulary

WordSimple Definition
VariableA named box that holds a value.
Data TypeThe kind of value, like number or text.
NumberA numeric value, like 7 or 3.14.
StringText inside quotes, like "hello".
BooleanTrue or false.
UndefinedA variable with no value yet.
NullAn empty value given on purpose.
DeclarationCreating a variable with let, const, or var.
AssignmentGiving a value to a variable using =.
ConcatenationJoining strings with +.
Template LiteralA string with backticks that can include ${}.
Type ConversionChanging a value from one type to another.
typeofAn operator that tells you the data type.

🔑 Important Concepts

  • Variables store data so your program can remember it.
  • Use let for changeable values, const for fixed values.
  • Data types: number, string, boolean, undefined, null.
  • You can change a let variable but not a const.
  • Strings are text; numbers are for math.
  • Booleans are true/false used for decisions.
  • Use + to join strings, but be careful with numbers and strings.
  • Template literals (` `) make combining strings easier.
  • typeof helps you check data types.
  • Convert types with Number() and String().

🪜 Step-by-Step Explanations

How to create and use a variable

  1. Choose a keyword: let or const.
  2. Pick a clear name (e.g., playerScore).
  3. Use = to assign a value (e.g., let playerScore = 0;).
  4. Use the variable name later to read or change it.
  5. If using let, you can change the value: playerScore = 10;.

How to combine a string and a number

  1. Make sure the number is a number (no quotes).
  2. Make sure the string is in quotes.
  3. Use + to join: "Score: " + 10 gives "Score: 10".
  4. Or use template literal: `Score: ${10}`.

🌍 Real-life Examples

  • Online form: Storing your name (string) and age (number) when you sign up.
  • Game: Keeping track of your score (number) and whether you are still alive (boolean).
  • Weather app: Storing temperature (number) and city name (string).
  • WhatsApp: Storing your contacts’ names (strings) and online status (boolean).
  • Bank app: Storing your balance (number) and account number (string).

🇳🇬 Nigerian Examples

  • Naira and kobo: let price = 1500; (number). let currency = "₦"; (string).
  • Jollof rice: let jollofPortions = 3; (number). let isSpicy = true; (boolean).
  • Lagos traffic: let trafficLevel = "heavy"; (string).
  • Super Eagles: let eaglesScore = 2; let opponentScore = 1; let isWinning = true;.
  • Nollywood: let movieTitle = "The Wedding Party"; let releaseYear = 2016;.

🎈 Fun Examples Children Can Relate To

  • Video game lives: let lives = 3; After losing a life: lives = lives - 1;
  • Pizza slices: let slices = 8; You eat 2: slices = slices - 2;
  • Birthday age: let age = 10; Next year: age = age + 1;
  • Superhero name: let heroName = "Spider-Boy";
  • Do you like chocolate? let likesChocolate = true;

🏠 Everyday Examples

  • Alarm clock: let alarmTime = "7:00 AM"; (string).
  • Phone battery: let batteryPercentage = 85; (number).
  • Light switch: let isLightOn = false; (boolean).
  • Shopping list: let item1 = "Milk"; let item2 = "Bread"; (strings).
  • Number of steps walked: let steps = 3000; (number).

👨‍👩‍👧 Parent Tips

  • Encourage your child to explain variables using everyday objects (boxes, jars, bags).
  • Ask them to name variables clearly — it builds good coding habits.
  • Let them practise with simple examples like storing their age and calculating next year’s age.
  • Remind them that mistakes are normal. undefined and null are not errors; they are tools.
  • Celebrate small wins — like writing their first variable and printing a message.

💡 Interesting Facts

  • The word “variable” comes from “vary”, meaning to change.
  • In the 1950s, programmers used punched cards to store data — no variables like we have today!
  • JavaScript was created in just 10 days in 1995.
  • Some programming languages require you to say the data type before the variable name (e.g., int score = 0;). JavaScript is more relaxed.
  • The typeof operator is so useful that it exists in almost every programming language.

🤔 Did You Know?

  • typeof null returns "object" — a famous bug in JavaScript that was never fixed to avoid breaking old websites.
  • You can use emojis in variable names? Actually, no — JavaScript variable names must use letters, digits, $, or _.
  • The longest variable name can be thousands of characters long, but nobody does that!
  • Strings can contain numbers, like "123", but they are still text.

🧠 Remember This

  • Variables are named containers for data.
  • let for change, const for no change.
  • Numbers, strings, booleans, undefined, null.
  • Use quotes for strings. No quotes for numbers or booleans.
  • Combine strings with + or template literals.
  • Check types with typeof.
  • Convert types with Number() and String().
  • Clear names make happy coders!

❌ Common Mistakes

MistakeWhy it’s wrongFix
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";

✅ Best Practices

  • Use const by default, and let only when you need to change the value.
  • Give meaningful names: playerScore not x.
  • Use camelCase for multi-word names: myFavoriteFood.
  • Always end statements with a semicolon ;.
  • Use template literals for building messages.
  • Check your data types with typeof when debugging.

📊 ASCII Illustrations, Diagrams & Flowcharts

Variable as a labelled box

   +---------------------+
   |   name: "score"     |
   +---------------------+
   |   value:  10        |
   +---------------------+
          |
          V
   After a goal:
   +---------------------+
   |   name: "score"     |
   +---------------------+
   |   value:  11        |
   +---------------------+
    

Data type flowchart

   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.
    

Timeline: The life of a variable

   1. Declare:    let score;
   2. Assign:     score = 0;
   3. Use:        console.log(score);
   4. Change:     score = 10;
   5. Use again:  console.log(score);
    

📋 Comparison Tables

let vs const vs var

KeywordCan change?When to use
letYesFor values that will change.
constNoFor values that stay the same.
varYesOld code; avoid in new code.

Data type summary

TypeExampleUsed for
Number42, 3.14Math, counting, measuring
String"Ada", 'Lagos'Text, names, messages
Booleantrue, falseDecisions, yes/no
Undefinedlet x;No value yet
Nulllet y = null;Empty on purpose

📝 Summary After Every Lesson

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.

🎓 End-of-Module Summary

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!

❓ Frequently Asked Questions

  1. What is a variable? A named container that stores a value.
  2. What is a data type? The kind of value, like number or string.
  3. Why use const instead of let? To prevent accidental changes.
  4. Can I change a const variable? No, it will cause an error.
  5. What does undefined mean? A variable has been declared but has no value yet.
  6. What is the difference between null and undefined? null is given on purpose; undefined happens automatically.
  7. How do I combine text and variables? Use + or template literals with ${}.
  8. What is typeof for? It tells you the data type of a value.
  9. How do I convert a string to a number? Use Number("123").
  10. Can variable names have spaces? No, use camelCase or underscores.

🔗 Matching Exercises

Match the item on the left with its correct data type on the right.

ItemData Type
1. "Lagos"A. Number
2. 42B. String
3. trueC. Boolean
4. let x;D. Undefined
5. nullE. Null

Answers: 1-B, 2-A, 3-C, 4-D, 5-E

🎭 Scenario-based Exercises

  1. You are making a game. The player’s score starts at 0. They earn 10 points. What variable would you create and how would you update it?
  2. A user types their age in a form. It arrives as a string "15". How do you calculate their age next year?
  3. You want to display “Welcome, Ada!” on a web page. What data type is “Ada”? How do you combine it with “Welcome, ”?
  4. You are building a weather app. You need to store the temperature (25.5) and whether it is raining (false). What data types are these?
  5. Your friend’s name is not saved in your phone. What value does that contact name have? (Hint: undefined or null?)

👥 Group Activity

“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!

✍️ Individual Activity

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"; — String
  • let myAge = 12; — Number
  • let likesJollof = true; — Boolean
  • let favouriteSubject = "Maths"; — String
  • let shoeSize = 36; — Number

🛠️ Mini Project: “About Me” Card

Create 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.

📝 Practical Assignment

  1. Create three variables: yourName (string), yourAge (number), isStudent (boolean).
  2. Print a message using template literals that says: “My name is [name]. I am [age] years old. Am I a student? [true/false].”
  3. Change yourAge to your age next year. Print the new message.
  4. Use typeof on each variable and print the results.

🔑 Key Takeaways

  • Variables are named containers for data.
  • Use let for changing values, const for fixed values.
  • Main data types: number, string, boolean, undefined, null.
  • Strings need quotes; numbers and booleans do not.
  • Combine strings with + or template literals.
  • Check types with typeof; convert with Number() and String().
  • Clear names and consistent style make code readable.

💬 Classroom Discussion Questions

  1. Why do we need variables in a web page?
  2. What happens if you try to change a const variable?
  3. Give an example of a number, a string, and a boolean from your daily life.
  4. What is the difference between undefined and null?
  5. Why is it important to use the correct data type?
  6. How can template literals make coding easier?
  7. What would happen if you added a number and a string together in JavaScript?

🚀 Preparation for the Next Module

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

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→