Conditions: if, switch and the Ternary
Learn Conditions: if, switch and the Ternary (Phase 2 · Conditions, Loops, Functions (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Making decisions • if / else if / else runs the first branch whose condition is truthy. • The ternary cond ? a : b is an expression; use it for simple value choices, not for side effects. • switch compares with === . Each case must end with break (or return ) or execution falls through into the next case.