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
- If/else, switch, loops; truthiness & strict checks
- Functions: params, default/optional/rest; return types
- Arrow functions & contextual typing