The basic conditional test in JavaScript is done with the if keyword. It test a condition for a boolean (true/false) value. So if a condition is met(true) the script does something. But what do we do if the condition is not met...or we want to check if another condition is met?
​
This is where else is coming to our rescue. If the condition is not met we can do something else.
Let's look at the basic if statement.
What can we do to change the behavior when the condition is not met by adding else at the end of the if statement.
Now our code does two things. One for if the condition we test and another one if the condition is not met.
By mixing if and else we can have multiple branches of conditions. When adding if before else statement blocks the code can have as many conditions as we like.
Using else with our if statements makes the code able to handle many more conditions, which makes the code better to handle real world problems.