A program constantly makes decisions: « if this is the case, then do that ». Those are conditions.
Useful operators
- Arithmetic:
+,-,*,/. - Comparison:
===(equal to),!==(not equal to),>,<. - Logical:
&&(and),||(or).
The if / else structure
let age = 18;
if (age >= 18) {
console.log("Majeur");
} else {
console.log("Mineur");
}
The condition in brackets is evaluated: if it is true, the first block runs, otherwise the else block does. Watch out: you compare with three equals signs (===), whereas a single one (=) assigns a value.
Key takeaway:
if / elselets a program respond to different situations. Compare with===, never with a single=.