JavaScript Resources
else Conditional Statement
Decision making:
The else conditional statement is always used in collaboration with the if conditional statement.
Think of using if/else when you have an either/or situation in mind: when you want a set of statements to execute when a condition is met and another set of statements to execute if that condition is not met.
The if/else structure is as follows:
if (some condition that evaluates to true) {
then execute this statement
and any other statements on additional lines
}
else {
then execute this statement
and any other statements on additional lines
}
Notice that the else conditional statement does not use a condition. These statements will execute only when the condition supplied to if is false.
Using the else conditional statement does not present an alternative path in your code. Instead, it presents a gateway through which all users must pass. Either the statements included within the curly braces {} of the if condition will execute, or the statements within the curly braces of the else condition will execute.
Next up ... the "else if" Conditional Statement