Skip to main content
Object Calisthenics 60 XP · 6 min

Don't Use the Else Keyword

Replace if/else with guard clauses and early returns — else is usually a sign of unclear flow that can be simplified into a straightforward sequence.

Showing
Ad (728×90)

Why this matters

Every else branch creates a parallel path through your code. The reader must track both the "normal" and "alternative" flows simultaneously. Guard clauses and early returns collapse these parallel paths: handle the edge case first, then write the happy path straight down the page — no branching required.

Code Challenge

Study the messy code, try to refactor it, then reveal the clean version.

Key takeaway

Return or throw early for every special case, then write the normal path without any branches. Your readers will thank you — they only have to follow one path at a time.

Done with this lesson?

Mark it complete to earn XP and track your progress.