Programs do not only run statements in order. They often need to check whether a condition is true, then choose what to do next. A condition usually produces a Boolean value: true or false.
Relational operators
Relational operators compare two values. The result of a comparison is a Boolean value, not another number.
Common JavaScript relational operators:
<: less than>: greater than<=: less than or equal to>=: greater than or equal to===: equal to!==: not equal to
Important: one equals sign = means assignment. Two equals signs === mean comparison.
let age = 17;
console.log(age < 18) // true;
console.log(age === 18) // false;
console.log(age !== 18) // true;age = 17 stores 17 in the variable age. age === 18 checks whether the current value of age equals 18.
KNOWLEDGE QUIZ
Logical operators
Logical operators combine multiple conditions. Their result is still a Boolean value.
&&: the whole expression istrueonly when every condition istrue.||: the whole expression istruewhen at least one condition istrue.!: turnstrueintofalse, andfalseintotrue.
let age = 20;
let hasTicket = true;
console.log(age >= 18 && hasTicket) // true;
console.log(age < 18 || hasTicket) // true;
console.log(!hasTicket) // false;It helps to read conditions like plain language: age >= 18 && hasTicket means “the age is at least 18, and the person has a ticket.”
Stadium Smart Gate
Choose a visitor, then scan their ID and ticket. The gate opens only when both checks are true.
Age check20 >= 18 → ?
Ticket checkhasTicket → ?
Gate resultWaiting
KNOWLEDGE QUIZ
Combining conditions
JavaScript combines range checks with &&. Write both comparisons explicitly:
let age = 16;
console.log(age > 0 && age < 18) // true;This is equivalent to:
console.log(age > 0 && age < 18);When a condition becomes complex, use parentheses or meaningful variable names to keep the logic readable.
let score = 85;
let attendance = 92;
let passed = score >= 60 && attendance >= 80;
let excellent = score >= 90 || attendance >= 95;
console.log(passed) // true;
console.log(excellent) // false;Do not rush to squeeze every condition into one line. Naming smaller conditions makes the program easier to read and debug.
KNOWLEDGE QUIZ