JavaScript Foundations

Variables and values

Learn how JavaScript stores information in named variables so it can be reused later.

Starter Public preview lesson 4 practice exercises 1 homework item

What you will learn

  • Learn how JavaScript stores information in named variables so it can be reused later.
  • Explain what variables and values are in plain English.
  • Read tiny beginner JavaScript examples without pressure to memorize every symbol.

Lesson shape

14 minute lesson with 9 sections, 4 exercises, 8 checkpoint questions, and 1 homework submission.

Student mode saves sections, safe practice results, quiz progress, and completion status.

Lesson preview

Step-by-step structure before you start

Overview

What you will learn in this lesson

This is the first lesson where JavaScript starts to look a little more like code. That can feel intimidating at first, but the idea behind it is simple.

Variables help JavaScript remember information. If the code needs a name, a number, or a short message later, it can store that information first and use it again when needed.

Your lesson goals are simple:
- understand what a variable is in plain English
- understand what a value is in plain English
- read tiny examples without rushing
- see why variables make code easier to reuse and change
- leave this lesson feeling calmer about beginner JavaScript syntax

The big idea is small

A variable is a named place where JavaScript stores a value.

Explain

What a variable is in plain English

A variable is a name that points to stored information.

You can think of it as a labeled spot where JavaScript keeps something for later. The name helps the code find that stored information again instead of guessing.

If a page needs to remember a student's name, a score, or a short message, a variable gives that information a clear label.

A variable is not the stored thing itself

The variable name is the label. The stored information is the value.

Explain

What a value is in plain English

A value is the actual information being stored.

The value might be text like "Ava". It might be a number like 3. Later, it might even be a true-or-false answer such as true or false.

The important part for now is this:
the variable is the named place
the value is what is inside it

Keep the two roles separate

If you can tell the difference between the name and the stored value, you are already learning the right way.

Practice

Tiny example 1: storing a name

Here is a tiny example:

let studentName = "Ava"

Line by line:
The word let starts a simple variable line.
studentName is the variable name.
"Ava" is the stored value.

This line tells JavaScript to remember the name Ava so the code can use it again later.

The name describes the job

A variable like studentName is easier to understand than a vague name like x.

Practice

Tiny example 2: storing a number

Here is another tiny example:

let lessonCount = 3

Line by line:
let starts the variable line.
lessonCount is the variable name.
3 is the value being stored.

This is useful when the code needs to remember a count, score, or step number.

Values are not always text

A value can be a number too. JavaScript can store different kinds of information in variables.

Practice

Tiny example 3: storing page text for later

One more beginner-safe example:

let welcomeMessage = "Welcome back"

Line by line:
welcomeMessage is the variable name.
"Welcome back" is the value.

A line like this is useful when the page may need to show the same message more than once. Instead of rewriting the text everywhere, JavaScript can store it once and reuse it.

Stored text can be reused

A variable helps you keep one useful value ready for later instead of repeating it everywhere.

Explain

Why variables are useful

Variables help because they let code:

- reuse information later
- change information in one place
- stay easier to read

If the code stores a student's name once, it can use that same value later without typing it again and again. That makes small code examples feel clearer and less messy.

Variables reduce repetition

Store once, use again. That is one of the biggest beginner wins variables give you.

Explain

Common beginner mistakes with variables

A few small mistakes happen often:

Confusing the variable name with the stored value:
studentName is the label. "Ava" is the value.

Using a vague variable name:
A name like x gives less help than a name like welcomeMessage.

Changing too many things at once:
It is easier to learn when you change one small part and then check the result.

Feeling like every symbol must be memorized immediately:
It does not. The goal right now is understanding the idea of storing information, not perfect memory.

Most variable mistakes are small

If the line feels confusing, slow down and ask: what is the variable name and what is the value?

Wrap up

Short recap before lesson 3

A variable is a named place where JavaScript stores a value.
The variable name is the label.
The value is the information being stored.
Variables help code remember, reuse, and change information more clearly.

That is the real win from this lesson. You do not need advanced rules yet. You only need a calm understanding of how JavaScript stores simple information.

You only need the core idea

If you can spot the variable name and the stored value in a tiny example, you are ready for the next lesson.

Keep moving

Finish this lesson, then move forward without losing your place.

Use the student player for saved sections, safe practice, quiz progress, and completion tracking.