Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
If-else statements let your code make choices. Like saying "IF it's raining, bring an umbrella. ELSE, wear sunglasses." Your program decides what to do based on conditions!
If the condition is true, the code inside the curly braces runs. If false, it's skipped.
Run code only when a condition is true
Take different actions based on a condition
if (first condition)← Check this firstelse if (second condition)← If first is falseelse if (third condition)← If both falseelse← If all falseMultiple conditions checked in order
Different access levels based on user role
if (age = 18) // ❌ Wrong! This assigns, not comparesif (age === 18) // ✅ Correct! Use === to compareAlways use { } even for single lines - it prevents bugs and makes code clearer
if (condition) {
doSomething(); // ✅ Safe!
}Run code only when a condition is true
Runs when the condition is false
Check multiple conditions in order
=== compares, = assigns values