Control Flow: if else switch for while
Branch with if/else and switch, loop with for and while, and use break and continue to control iteration.
What Is Control Flow?
Control flow determines which code runs and how many times. JavaScript provides conditionals (if/else, switch) and loops (for, while, do/while) to direct the execution path based on conditions and data.
if / else if / else
The most fundamental conditional. The condition in parentheses is evaluated as truthy/falsy. Multiple conditions chain with else if. The final else is a catch-all fallback.
const score = 75;
if (score >= 90) {
console.log('A');
} else if (score >= 80) {
console.log('B');
} else if (score >= 70) {
console.log('C');
} else {
console.log('F');
}All lessons in this course
- Variables: let const var and Scope
- Data Types: string number boolean null undefined
- Functions: declarations expressions arrow functions
- Control Flow: if else switch for while