Previous Operators |
ABC of JavaScript : A JavaScript Tutorial If Condition |
Next Switch Case |
if (CONDITION) {
STATEMENT 1
}
else if (ALTERNATE CONDITION) {
STATEMENT 2
}
else {
STATEMENT 3
}
The if condition will check the given condition and if it is true, it will execute the statements within the first set of braces(from '{' to the next '}'). If the condition is not true, it will check the next condition and so on. If no given condition is true, the 'else' statements are executed.
The 'else if' and 'else' conditions are optional - you don't have to type it if you don't have any need for it. Now for an example...
Previous Operators |
Contents | Next Switch Case |