Conditions and branching
Conditions and branching
if and else handle conditional paths. switch is useful when comparing one expression with multiple cases. Keep conditions readable, use braces and handle unexpected values with a default branch.
Try it yourself
Change the example, run it, and explain the result in your own words. Then create one variation of your own.
Key idea
Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.
Code example
const mark = 76;
if (mark >= 70) console.log("Excellent");
else if (mark >= 50) console.log("Pass");
else console.log("Try again");