Lesson content
Read, practise, then check your understanding
if branches on truthiness. An else-if chain tests in order and runs the first matching branch. Guard clauses keep invalid paths short.
Explicit decisions
function classify(score) {
if (!Number.isFinite(score) || score < 0 || score > 100) return "invalid";
if (score >= 80) return "excellent";
if (score >= 50) return "pass";
return "retry";
}
switch matches cases using strict comparison. End cases with break, return, or throw unless fallthrough is intentional and documented. Empty arrays and objects are truthy; zero, NaN, empty string, null, undefined, and false are falsy. Use lookup maps or polymorphic handlers when a large switch becomes hard to extend.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.