Although there is no 'else if' keyword, because the if follows the else and is separated by a space, the if block is treated as if it were a single statement. Here we omit the braces surrounding the statement executed in the else condition of a leading if block. We then place another in its else statement and so on. Like this:
if(aCondition) { some code } else if(aCondition) { some code } else if(aCondition) { some code } else { some code }
By putting in the braces, it becomes clearer. Actually, what we have really done is this:
if(aCondition) { some code } else { if(aCondition) { some code } else { if(aCondition) { some code } else { some code } } }
It is really just a plain old if() else block nested several times. By leaving off the braces (against our recommendations otherwise), in this circumstance it actually makes the code clearer.
Prev | Home | Next |
else ... | Up | EM object |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |