Wednesday, September 1, 2010

If statements in Javascript must be enclosed in parentheses

  If statements in Javascript must be enclosed in parentheses and evaluation of the conditional stops once the condition can be ascertained as being either true or false. Thus all conditions may not be evaluated.

Also, the if statement can be written in shorthand

i.e.


value=(a==1) ? 1 : 0
which is equivalent to
if (a==1) then
    value=1;
else
    value=0;

No comments:

Post a Comment