Conditional statements let your code make decisions based on logic or values. They control flow by deciding
what code runs and when. They key conditionals are
if,
else if,
and
else.
if (condition) {
// code to execute if true
} else if (condition) {
// code to execute if first condition is false but this condition is true
} else {
// code to execute if other conditions are false
}
You can chain multiple else if blocks, but only the first true block will run.
There is a shorthand for checking for truthiness (Values like 0, "", null, undefined, and NaN are all falsy. Everything else is truthy).
if (variable) {};