The meaning is, if the first of the two expressions returns false , then the
second expression will not be evaluated, so any data modifications performed in the second expression
will not happen. For example:
var myInt = 3;
if ( 4 == 3 & & ++myInt == 4 )
{
// do code
}
trace( myInt );
Here, one would expect myInt to equate to the value 4 as it is pre - incremented. However, because the
expression 4 = = 3 returned false , the second part of the expression was never evaluated, so myInt is
traced as the value 3.
Nesting if statements are often preferential, though there are times when it is a necessity because of
logic flow. However, by combining conditional expressions into a single if statement, there will be a
slight performance increase as only one expression is validated, not two. However, this increase is
negligible, and so should not affect your decision.
When nesting an if statement in an else block, you are in effect supplying a new branch for testing an
expression ??™ s equality. Continual nesting of if statements in the parents else clause will thereby provide
a chain of equality expressions offering numerous chances for an expression to return true :
if ( myVar == 1 )
// do this.
Pages:
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183