Skip to content
Clairos Learn

JavaScript basics · Lesson 6 of 12 · 7 minutes

JavaScript basics: Conditional branches

An if statement chooses a path from a condition; the else branch handles the other case.

Mastery 0/3Run itExplain itApply it
Web workshopInert preview · code inspection

Current edit

PreviewNo external resources

Understand the pattern

An if statement chooses a path from a condition; the else branch handles the other case.

An if statement chooses a path from a condition; the else branch handles the other case.

Misconceptions to reject

  • A string containing code executes automatically when it is assigned.
  • A successful element lookup guarantees that the rest of an event handler is correct.

This is a code-inspection lab, not a full JavaScript runtime.

Worked example and expected result
const ready = true;
let message = "Waiting";
if (ready) { message = "Ready to practice"; } else { message = "Try again later"; }

An if statement chooses a path from a condition; the else branch handles the other case.

Try a variation

Adapt the final example to a different project name while retaining its structure and relationships. A different context still needs a real browser and accessibility check.

Explain it

Which statement correctly explains conditional branches?

Apply it elsewhere

You reuse conditional branches in a different project. What must still be verified?

Keep the momentum.

Complete the lab, then explain and apply the pattern.

Next: JavaScript basics: ArraysTry an incident drill

Anonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.

Keep learning

  1. 01JavaScript basics: Boolean decisionsComparisons produce booleans. Strict equality avoids implicit conversion when checking a known type.Practice
  2. 02JavaScript basics: ArraysArrays hold ordered values. Index zero refers to the first item.Practice
  3. 03JavaScript basics: Array lengthlength counts the array slots; the last valid index is normally length minus one.Practice