Page 299 - Web Applications (803) Class 11
P. 299

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  (a < 10 && b > 1)   True
                                          true, and false if even one of the operands returns false.

                      ||      OR           It returns false if and only if both the operands return  (a == 5 || b == 5)   False
                                          false,  and  it  returns  true  if  any  one  of  the  operands
                                          returns true.
                      !       NOT           It  is  used  to  invert  the  value  of  a  boolean  condition,   !(a == b)   True
                                          which means reversing the logical (true or false) state of
                                          the value.
                 Example:

                   <!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));
                   document.write( " NOT operator result is"+"="+result);
                   </SCRIPT>
                   </BODY>
                   </HTML>
                 Output of the above code is as follows:



















                                                                      Introduction to Dynamic Websites Using JavaScript  297
   294   295   296   297   298   299   300   301   302   303   304