Page 90 - DCAP202_Fundamentals of Web Programming
P. 90

Unit 7: Operators in JavaScript




          var  d  =  c;                                                                         Notes
          c += 1; // c = 2, d = 1;

          7.1.5 Comparison Operators

          There are following comparison operators supported by JavaScript language
          Assume variable A holds 10 and variable B holds 20 then, see Table 7.4:

                                   Table  7.4: Comparison  Operators

              Operator                   Description                    Example
                        Checks if the value of two operands are equal or not,  (A == B) is not
             ==
                        if yes then condition becomes true.         true.
                        Checks if the value of two operands are equal or not,
             !=                                                     (A != B) is true.
                        if values are not equal then condition becomes true.
                        Checks if the value of left operand is greater than
             >          the value of right operand, if yes then condition   (A > B) is not true.
                        becomes true.
                        Checks if the value of left operand is less than the
             <          value of right operand, if yes then condition   (A < B) is true.
                        becomes true.
                        Checks if the value of left operand is greater than or
                                                                    (A >= B) is not
             >=         equal to the value of right operand, if yes then
                                                                    true.
                        condition becomes true.
                        Checks if the value of left operand is less than or
             <=         equal to the value of right operand, if yes then   (A <= B) is true.
                        condition becomes true.

          7.1.6 Logical Operators


                  Operator                             Description
                    &&                                    and
                     ||                                    or
                      !                                    not

          7.1.7 Other Operators

          The Conditional Operator (? :)

          There is an operator called conditional operator. This first evaluates an expression for a true or
          false value and then execute one of the two given statements depending upon the result of the
          evaluation. The conditional operator has this syntax:

            Operator            Description                      Example
                                                     If Condition is true ? Then value X :
           ? :        Conditional Expression
                                                     Otherwise value Y

          The typeof Operator

          The typeof is a unary operator that is placed before its single operand, which can be of any type.


                                           LOVELY PROFESSIONAL UNIVERSITY                                   83
   85   86   87   88   89   90   91   92   93   94   95