Last updated: August 26, 2026.
JavaScript uses if, else if, and switch to choose which code runs.
if and else
const score = 84;
if (score >= 90) {
console.log('A');
} else if (score >= 80) {
console.log('B');
} else {
console.log('Below B');
}switch
const status = 'pending';
switch (status) {
case 'pending':
console.log('Waiting for review');
break;
case 'approved':
console.log('Ready');
break;
default:
console.log('Unknown status');
}Use strict equality, remember that empty strings and zero are falsy, and include break unless intentional fall-through is clearly documented.