本文档基于 CC协议(Creative Commons Share-Alike License)发布,是developer.mozilla.com, www.mozref.comwww.aptana.com共同劳动的成果。

if...else

If the expressionA is true, executes statementA. If the expression is false, evaluates expressionB. If expressionB is true, executes statementB. Otherwise, executes statementC.

Syntax

if (expressionA)
   statementA
[else if (expressionB)
   statementB]
 [else
   statementC] 

Example

if (myCat=="Jasmine")
   alert (myCat);
else if (myCat==" ")
   alert("No cat!");
else
   alert("Wrong cat!");  

Remarks

You can nest as many "else if" statements within the block as you need; however, if you use multiple "else if" statements, you might want to consider using a "switch" statement for cleaner code.