Conditional
ELI5 — The Vibe Check
A conditional is an if/else decision in your code — 'if this is true, do this; otherwise, do that.' It is how your program makes choices. Is the user logged in? If yes, show the dashboard. If no, redirect to login. Conditionals are the backbone of any logic.
Real Talk
A conditional is a control flow statement that executes different code blocks based on whether a boolean expression evaluates to true or false. Types include if/else, else if chains, switch/case statements, ternary operators (condition ? a : b), and nullish coalescing (?? for null/undefined). Conditionals are how programs express branching logic.
Show Me The Code
// Standard if/else:
if (user.isLoggedIn) {
showDashboard();
} else if (user.isPending) {
showPendingScreen();
} else {
redirectToLogin();
}
// Ternary (one-liner for simple conditions):
const label = isActive ? 'Active' : 'Inactive';
// Nullish coalescing (null or undefined fallback):
const name = user.name ?? 'Anonymous';
When You'll Hear This
"Add a conditional to handle the case where the list is empty." / "That nested conditional is unreadable — simplify it."
Related Terms
Boolean
A boolean is the simplest value in programming — it is either true or false. On or off. Yes or no. 1 or 0. Named after mathematician George Boole.
Logic Error
A logic error is the sneakiest kind of bug — the code runs perfectly fine, no crashes, no errors, but it does the WRONG thing.