An If... Then... Else... statement executes a statement if the specified condition is true; if it is false, a second statement can be executed. Example, assuming that testNum(a) = 5:
function testNum(a) {
if (a > 0) {
return "positive";
} else {
return "NOT positive";
}
}
In this case, the returned string is "NOT positive."
Multple If...Else statement can be nested. There is no "ElseIf" statement in JavaScript. Example, using (as is recommended) curly brackets to delineate blocks of code:
if (condition1) {
statement1
} else {
if (condition2)
statement2
} else {
if (condition3)
}...
It is permissible to use else if (with a space between words):
if (x > 5) {
/* do the right thing */
} else if (x > 50) {
/* do the right thing */
} else {
/* do the right thing */
}
Also see Comparison & Logical Operators for additional types of tests for true/false conditions.