Day 2: Switch, Ternary & Truthy/Falsy
Daily Objective
Section titled “Daily Objective”Use switch for discrete equality branching, ternary operators for concise inline assignments, and understand truthy/falsy values.
1. The Ternary Operator
Section titled “1. The Ternary Operator”const age = 20;const status = age >= 18 ? 'Adult' : 'Minor';2. The switch Statement
Section titled “2. The switch Statement”const day = 'Monday';switch (day) { case 'Monday': case 'Tuesday': console.log('Weekday'); break; case 'Saturday': case 'Sunday': console.log('Weekend'); break; default: console.log('Midweek');}3. Truthy vs Falsy
Section titled “3. Truthy vs Falsy”The 6 standard falsy values in JavaScript:
false,0,""(empty string),null,undefined,NaN. Everything else is truthy!
Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Refactor an
if/elsevariable assignment into a one-line ternary operator. - Test truthiness of values like
[](empty array: truthy!),0, and"0".