Client Portal Secure Access
JavaScript Foundations Beginner 14 minute lesson

Conditionals

Learn how JavaScript can choose between two paths based on whether a condition is true or false.

What you will learn

  • Learn how JavaScript can choose between two paths based on whether a condition is true or false.
  • Recognize simple if and if/else patterns in tiny beginner examples.
  • Connect booleans and comparisons to simple code decisions.

What you will learn in this lesson

JavaScript does not always follow one single path. Sometimes it needs to make a small decision first.

That is what conditionals are for. They let JavaScript check something and then choose what to do next.

Your lesson goals are simple:
– understand what a conditional is in plain English
– read the idea of if this is true, do this
– see what changes when a false path is added
– connect conditionals back to booleans and comparison operators
– feel calmer when code starts making simple decisions

A decision is still just one step at a time

A conditional lets JavaScript check a condition first, then choose the matching action.

What a conditional is in plain English

A conditional is a way for code to make a decision.

In very simple terms, it means:
if this is true, do this

That is the core idea. JavaScript checks one thing first, then decides which path to take.

Think decision, not complexity

A conditional is not magic. It is only a check followed by an action.

The simple if idea

A small if statement checks one condition.

If the condition is true, JavaScript runs the action inside that path.
If the condition is false, JavaScript skips that action.

One check, one path

A plain if statement only says what happens when the condition is true.

The simple if/else idea

Sometimes JavaScript needs two possible actions:

– one action if the condition is true
– another action if the condition is false

That is when an if/else structure helps. It gives both branches clearly instead of leaving the false case blank.

Two possible paths

If/else helps JavaScript choose between a true path and a false path.

Tiny example 1: show one message if a user is logged in

Here is a small example:

if (isLoggedIn) {
showMessage("Welcome back")
}

Line by line:
if starts the conditional.
isLoggedIn is the condition being checked.
If that condition is true, JavaScript runs the message line.

This is a simple example of one true path and no false path.

The condition is the check

Ask yourself what JavaScript is checking before you worry about the whole block.

Tiny example 2: react differently if a score is high enough

Here is an if/else example:

if (score > 80) {
showMessage("Great job")
} else {
showMessage("Keep practicing")
}

Line by line:
score > 80 is the condition being checked.
If it is true, JavaScript shows Great job.
If it is false, JavaScript shows Keep practicing.

This example uses a comparison operator and a true/false result together.

Conditionals connect earlier lessons

A comparison creates the true-or-false check, and the conditional uses that result to choose the next step.

Tiny example 3: one path if a button was clicked and another if it was not

One more example:

if (wasClicked) {
showMessage("Button pressed")
} else {
showMessage("Waiting for a click")
}

Line by line:
wasClicked is the condition.
The first message is the true path.
The second message is the false path.

This keeps the decision simple: one thing happens when the answer is true, and another happens when it is false.

Look for the two branches

When you see if/else, ask which action belongs to the true path and which one belongs to the false path.

How conditionals connect to booleans and comparison operators

Conditionals do not appear from nowhere. They build on ideas you already learned.

Booleans give true or false answers.
Comparison operators check whether two values match or whether one is bigger than another.
A conditional uses that true-or-false result to decide what to do next.

That is why these lessons sit together in the track.

Earlier lessons still matter

Conditionals feel much easier when you remember that they depend on simple true/false checks.

Separate the parts of a conditional

A helpful reading pattern is to separate three parts:

– the condition being checked
– the action that happens if it is true
– the optional action that happens if it is false

If you break a small conditional into those parts, it becomes much easier to read.

Read the parts in order

First find the check. Then find the true path. Then look for the false path if there is one.

Common beginner mistakes with conditionals

A few small mistakes happen often:

Not understanding what part is being checked:
Slow down and find the condition first.

Mixing up the true path and false path:
Read each branch separately instead of reading the whole block as one blur.

Trying to read the whole block too fast:
Small decision code is easier when you read one line at a time.

Feeling overwhelmed by braces or structure:
The braces are only grouping the actions that belong to each path.

Most conditional confusion is reading-speed confusion

If a conditional feels stressful, slow down and name the condition, the true path, and the false path out loud.

Short recap before lesson 6

A conditional helps JavaScript make a simple decision.
An if statement says what happens when the condition is true.
An if/else statement shows both the true path and the false path.
The condition usually depends on a boolean or a comparison result.

You do not need nested logic or long chains yet. If you can follow one true path and one false path, you are ready for functions next.

One decision at a time is enough

If you can tell what is being checked and which path runs next, you are already learning conditionals the right way.

Mark this lesson complete when the main idea feels clear.

The website can remember completion in this browser. Full saved progress, quizzes, 22 Practice Labs, and certificate tracking live inside the Academy app.