Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 74 - 2609_Logicode
P. 74

    Example
                       Operator       Name                         Description                                    Output
                                                                                                  (a = 11, b = 4)
                           /      Division         Divides numerator by denominator.                   a / b       2.75
                           %      Modulus          Divides  numerator  by  denominator  and           a % b          3

                                                   returns the remainder.
                           **     Exponent         Calculates base raised to the exponent.            b**2          16

                           ++     Increment        Used to increase the value of a variable by 1.      ++a           12
                           --     Decrement        Decreases a variable’s value by 1.                  --a          10

                      Assignment Operators
                      Assignment operators assign the right-hand operand’s value to the left-hand operand. JavaScript
                      has one assignment operator (=), while others combine it with arithmetic operators, known as

                      shorthand or compound assignment operators.
                      JavaScript provides the following assignment operators:

                       Operator        Name                        Description                   Example (a=3)  Output
                            =      Assignment      Assigns right operand value to left operand.       a = 3          3
                           +=      Addition        Adds  right  operand  to  left  operand  and       a += 3         6
                                   assignment      assigns the result.

                           –=      Subtraction     Subtracts right operand from left operand          a –= 3         0
                                   assignment      and assigns the result.
                           *=      Multiplication  Multiplies right operand with left operand         a *= 3         9
                                   assignment      and assigns the result.
                           /=      Division        Divides left operand by right operand and          a /= 3         1
                                   assignment      assigns the result.
                           %=      Remainder       Divides left operand by right operand and         a %= 3          0

                                   assignment      assigns the remainder to the left operand.
                          **=      Exponent        Raises the value of a variable to the power       a **= 3         27
                                   assignment      of the right operand.

                      Comparison Operators

                      To  determine  equality  or difference  between  variables  or values, comparison  operators  are
                      used  in  logical  statements.  The comparison  operators  are  explained  in  the  table  below,
                      assuming x = 8.
                       Operator         Name                         Description                    Example      Output

                           ==      equal to         Compares a variable’s value with another.         x == 8       true
                           !=      not equal        Checks if two operands are not equal.             x != 8      false
                           >       greater than     Checks if one value is greater than another.       x > 8      false
                           <       less than        Checks if one value is less than another.          x < 8      false

                       72   Premium Edition-VIII

| 69 70 71 72 73 74 75 76 77 78 79 |