G
George Hester
In JavaScript we have the if then else which, if there is not more than one statement following we do not need to use {}. For example:
if ()
;
works fine and so does
if ()
if()
;
else
;
But what if we want the else to apply to the parent if?
if ()
if ()
;
else
;
Here we see that only one JavaScript statement follows after each if and else. But we are in a position that JavaScript is going to apply the else to the child if. We are required then to do this:
if (){
if ()
;
}
else
;
even though the parent if has only one JavaScript statement following. This is inconsistent isn't it? It's not a
problem it's just that I don't like inconsistency unless there is a valid explanation for the inconsistency based
on the rules of JavaSxript. Is there? Thanks.
if ()
;
works fine and so does
if ()
if()
;
else
;
But what if we want the else to apply to the parent if?
if ()
if ()
;
else
;
Here we see that only one JavaScript statement follows after each if and else. But we are in a position that JavaScript is going to apply the else to the child if. We are required then to do this:
if (){
if ()
;
}
else
;
even though the parent if has only one JavaScript statement following. This is inconsistent isn't it? It's not a
problem it's just that I don't like inconsistency unless there is a valid explanation for the inconsistency based
on the rules of JavaSxript. Is there? Thanks.