Skip to content
Justice Tech School

if, else if and else

Use if to run code when a condition is true, else if for more checks and else for the default. Early returns keep chains flat and readable.

Example
const score = 72;
if (score >= 90) console.log("A");
else if (score >= 70) console.log("B");
else console.log("C");

Exercise

Alternative branch.

if (x) {}  {}

Quiz Test

What does else run?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.