Skip to main content

2 docs tagged with "conditionals"

View all tags

Conditionals

Best practices for conditional branching in TypeScript. A guide to keeping nesting shallow with early returns, discriminated unions and exhaustiveness checks, and reducing if statements with polymorphism, explained with Bad / Good comparisons.

Conditionals

An explanation of branching with if statements, the ternary operator, and switch statements. Covers truthy / falsy and the 6 falsy values, short-circuit evaluation of logical operators, and choosing between the nullish coalescing operator ?? and ||, all with practical examples.