0Pricing
TypeScript Academy · Lesson

If/else, switch, loops; truthiness & strict checks

Use if/else, switch, and loop patterns effectively; avoid pitfalls with truthiness and prefer strict checks.

Overview

Goal: Build confidence with if/else, switch, and loops. You will also learn when a value is merely truthy versus strictly equal, so your branches reflect intent.

If/else basics

If/else branches on boolean expressions. Prefer explicit comparisons over loose checks to avoid surprises.

const n: number = 3;

if (n > 0) {
  console.log("positive");
} else if (n === 0) {
  console.log("zero");
} else {
  console.log("negative");
}

All lessons in this course

  1. If/else, switch, loops; truthiness & strict checks
  2. Functions: params, default/optional/rest; return types
  3. Arrow functions & contextual typing
← Back to TypeScript Academy