JavaScript if/else Statement
Syntax
The if statement specifies a block of code to be executed if a condition is true:
if (condition) {
// block of code to be executed if the condition is true
}
The else statement specifies a block of code to be executed if the condition is false:if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
The else if statement specifies a new condition if the first condition is false:if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
Comments
Post a Comment