if, else if, and else branch execution based on boolean expressions.
Style
Keep conditions readable—extract complex checks to named booleans. Prefer early returns to deep nesting.
Guard clauses
Validate inputs at top of function and return early—reduces indentation in real codebases.
Important interview questions and answers
- Q: Truthy guard?
A: if (value) skips null/undefined/''—explicit checks clearer for APIs. - Q: else if chain?
A: Order matters—first true branch wins.
Self-check
- When use early return?
- Why explicit null check?
Tip: Re-run the playground code for conditionals-if-else and tweak one line before the MCQs.
Interview prep
- Early return?
Flattens logic and clarifies happy path.