Condition
In one line
A condition is an expression that evaluates to true or false, determining which branch of code executes.
In simple words
A condition is a question your code asks that has a yes/no (true/false) answer. Based on the answer, the program decides what to do next. For example, "is the user logged in?" is a condition — if yes, show the dashboard; if no, show the login page.
Conditions use comparison operators like === (equal), > (greater than), < (less than) and logical operators like && (AND), || (OR), ! (NOT) to build expressions that evaluate to booleans.
The if/else statement is the most common way to use conditions. The if block runs when the condition is true; the else block runs when it is false. You can chain multiple conditions with else if.
Example
let temperature = 25;
if (temperature > 30) {
console.log("It's hot!");
} else if (temperature > 20) {
console.log("It's warm.");
} else {
console.log("It's cool.");
}The condition temperature > 30 is false, but temperature > 20 is true, so "It's warm." is printed.
Common confusions
Confused with: loop
The difference: A condition is evaluated once to make a decision; a loop condition is evaluated repeatedly to control iteration. Conditions branch; loops repeat.
Related terms
Related Resources
Related Lessons
- Conditions
Learn how conditions work.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.