JavaScript IF Else - Conditional Statements in JavaScript: if, else, and else if
JavaScript if, else, and else if
- Conditional statements are used to perform different type of action is based on the different conditions.
- In JavaScript we have the following conditional statements.
- Use
if
to specify a block of code to be executed, if a specified condition is true - Use
else
to specify a block of code to be executed, if the same condition is false - Use
else if
to specify a new condition to test, if the first condition is false - Use
switch
to specify many alternative blocks of code to be executed
The if Statement
Sample Code
Output
The else Statement
- Use the else statement to specify a block of code to be executed if the condition is false.