Page 342 - Webapplication11_C11_Flipbook
P. 342

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:















              Ternary Operator (? :)

              A ternary operator (? :) determines whether a condition is true or false and then executes a block of code based on a
              specified statement. The syntax of the ternary operator is as follows:

              Condition ? expression1 : experience2
              The ternary operator evaluates the test condition.

              Ð ÐIf the condition is true, expression1 is executed.
              Ð ÐIf the condition is false, expression2 is executed.
              The ternary operator takes three operands, hence, the name ternary operator. It is also known as a conditional operator.
              Let us create a JavaScript program to use the ternary operator.

                 <HTML>
                 <HEAD>
                340     Touchpad Web Applications-XI
   337   338   339   340   341   342   343   344   345   346   347