Page 186 - Web Applications (803) Class 12
P. 186

The comparison operators are explained in the table below, assuming p = 6.

                          Operator               Description            Comparison             Return Value
                             ==            equal to                        p == 8          false

                                                                           p == 6          true
                              !=           not equal                        p != 8         true
                              >            greater than                     p > 8          false

                              <            less than                        p < 7          true
                             >=            greater than or equal to        p >= 10         false

                             <=            less than or equal to           p <= 8          true
                            ===            equal  value  and  equal      30 === “30”       false
                        (Triple Equals)    datatype

              Logical Operators
              The logic between variables or values is determined using logical operators. The table below explains the
              logical operators given a = 6 and b = 3:

                                    Operator                Description                 Example

                                       &&                        and            (a < 10 && b > 1) is true
                                        ||                       or             (a == 5 || b == 5) is false

                                        !                        not            !(a == b) is true
              Conditional (Ternary) Operator (? :)

              The conditional operator in JavaScript assigns a value to a variable based on some condition. This operator
              examines an expression for a true or false value before executing one of the two specified statements based
              on the evaluation result. Example:
                     a=12;
                     result    =    (a>0)?          “Positive Number”:            “Negative Number“;


                                                      Executed when                 Executed when
                                 Condition
                                                     condition is True             condition is False
              Bitwise Operators

              Bitwise operators deal with bits and perform operations on them one by one.

                           Operator                Name                           Description
                               &            AND                  If both bits are 1, sets each bit to 1.

                                |           OR                   If one of two bits is 1, sets each bit to 1.
                               ^            XOR                  If just one of two bits is 1, sets each bit to 1.
                               ~            NOT                  All bits are inverted

                               <<           Zero fill left shift  Shifts left by bringing zeros in from the right
                                                                 and dropping the leftmost bits.




                184   Touchpad Web Applications-XII
   181   182   183   184   185   186   187   188   189   190   191