Page 21 - LoudOffice_Guide-to-HTML_Part-II_Advanced.PDF
P. 21

=            Assigns the value of the righthand operand to the variable on the
                                        left.

                                        Example: t o t a l = 1 0 0 ;
                                        Example: t o t a l = ( p r i c e + t a x + s h i p p i n g ) ;
                          +=            Adds the value of the righthand operand to the lefthand variable.
                  (also -=, *=, /=)     Example: t o t a l + = s h i p p i n g ;
                                        (adds value of shipping to total and assigned result to total)
                          &=            Assigns result of (lefthand operand && righthand operand) to
                       (also |=)        lefthand operand






               Statements
               Statements define the flow of a script, known as "program flow." A statement, like a fully
               grammatical English sentence, is made up of smaller expressions that, altogether, evaluate
               into a cogent meaning. In JavaScript, statements are       organized as conditionals, loops,
               object manipulations, and comments.

               Good practice suggests that each JavaScript statements should be terminated with a
               semicolon (;). This is often not strictly necessary, as a new line also serves to separate
               statements, but when multiple statements reside on the same line the semicolon delimiter is
               mandatory.

               A set of statements that is surrounded by braces is called a block. Blocks of statements are
               used, for example, in functions and conditionals.

                                                                                                 y ;  but this
               Normally statements are executed sequentially: x      =  1 ;  y  =  2 ;  z  =  x  +
               can be altered by some statements that test a condition and branch or loop according to the
               result.




               Conditionals
               Conditional statements direct program flow in specified directions depending upon the
               outcomes of specified conditions. These tests are a major influence on the order of
               execution in a program.


               if...else
               As seen in many programming languages, if the condition evaluates to true then the block
               of statements1 is executed. Optionally, an else clause specifies a block of statements2
               which are executed otherwise. You may omit the else clause if there are no statements
               which need to be executed if the condition is false.
                       i f  ( c o n d i t i o n )
                        {  s t a t e m e n t s 1 ;  }

                       e l s e
                        {  s t a t e m e n t s 2 ;  }






               LoudOffice.com Guide to HTML – Part II                                               Page 21
   16   17   18   19   20   21   22   23   24   25   26