Conditionals: if, else, switch
Use if/else for most branches. switch is fine for many discrete cases. Ternary ? : is for short expressions.
- Braces {} keep blocks clear.
- switch needs break (or return) to avoid fall-through.
- Prefer early returns over deep nesting.
const score = 85;
if (score >= 80) {
console.log("pass");
} else {
console.log("retry");
}
After you read this chapter, use Write (when available) and Quiz on this page to lock it in.