Page 196 - Web_Application_v2.0_C12_Fb
P. 196

Output:


















                           Notes


                          Comparison statements always return/output a Boolean value, that is true or false.




              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    Name                          Description                            Example       Output
                  &&      AND      It returns true if and only if both the operands return true, and  (a < 10 && b > 1)  True
                                   false if even one of the operands returns false.
                   ||     OR       It returns false if and only if both the operands return false, and  (a == 5 || b == 5)  False
                                   it returns true if any one of the operands returns true.
                   !      NOT      It  is used to  invert  the  value  of  a  boolean  condition,  which  !(a == b)   True
                                   means reversing the logical (true or false) state of the value.

              Example 7: To demonstrate the use of logical operator
                <!DOCTYPE HTML>

                <HTML>
                <HEAD>
                <TITLE> logical Operators </TITLE>
                </HEAD>
                <BODY>

                <SCRIPT>
                var x = 5;
                var y = 6;
                result = (x<y && x>!y);

                document.write( "And operator result is"+"="+result);
                document.write("<br>");
                result = (x<y || x>y);
                document.write("OR operator result is"+"="+result);
                document.write("<br>");

                result = (!(x && y));
                194   Touchpad Web Applications (Ver. 2.0)-XII
   191   192   193   194   195   196   197   198   199   200   201