Javascript - Operators


Arithmetic Operators
Comparison Operators
Logical orRelationalorRelational Operators
Assignment Operators
Conditional orternaryorternary Operators

<html>
   <body>
 
      <script type = "text/javascript">
         <!--
            var a = 33;
            var b = 10;
            var c = "Test";
            var linebreak = "<br />";
       
            document.write("a + b = ");
            result = a + b;
            document.write(result);
            document.write(linebreak);
       
            document.write("a - b = ");
            result = a - b;
            document.write(result);
            document.write(linebreak);
       
            document.write("a / b = ");
            result = a / b;
            document.write(result);
            document.write(linebreak);
       
            document.write("a % b = ");
            result = a % b;
            document.write(result);
            document.write(linebreak);
       
            document.write("a + b + c = ");
            result = a + b + c;
            document.write(result);
            document.write(linebreak);
       
            a = ++a;
            document.write("++a = ");
            result = ++a;
            document.write(result);
            document.write(linebreak);
       
            b = --b;
            document.write("--b = ");
            result = --b;
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
     
      Set the variables to different values and then try...
   </body>
</html>

a + b = 43
a - b = 23
a / b = 3.3
a % b = 3
a + b + c = 43Test
++a = 35
--b = 8
Set the variables to different values and then try...

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var a = 10;
            var b = 20;
            var linebreak = "<br />";
     
            document.write("(a == b) => ");
            result = (a == b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a < b) => ");
            result = (a < b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a > b) => ");
            result = (a > b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a != b) => ");
            result = (a != b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a >= b) => ");
            result = (a >= b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a <= b) => ");
            result = (a <= b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      Set the variables to different values and different operators and then try...
   </body>
</html>

(a == b) => false
(a < b) => true
(a > b) => false
(a != b) => true
(a >= b) => false
a <= b) => true
Set the variables to different values and different operators and then try...

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var a = true;
            var b = false;
            var linebreak = "<br />";
     
            document.write("(a && b) => ");
            result = (a && b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a || b) => ");
            result = (a || b);
            document.write(result);
            document.write(linebreak);
       
            document.write("!(a && b) => ");
            result = (!(a && b));
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>

(a && b) => false
(a || b) => true
!(a && b) => true
Set the variables to different values and different operators and then try...

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var a = 2; // Bit presentation 10
            var b = 3; // Bit presentation 11
            var linebreak = "<br />";
       
            document.write("(a & b) => ");
            result = (a & b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a | b) => ");
            result = (a | b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a ^ b) => ");
            result = (a ^ b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(~b) => ");
            result = (~b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a << b) => ");
            result = (a << b);
            document.write(result);
            document.write(linebreak);
       
            document.write("(a >> b) => ");
            result = (a >> b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>
(a & b) => 2
(a | b) => 3
(a ^ b) => 1
(~b) => -4
(a << b) => 16
(a >> b) => 0
Set the variables to different values and different operators and then try...

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var a = 33;
            var b = 10;
            var linebreak = "<br />";
       
            document.write("Value of a => (a = b) => ");
            result = (a = b);
            document.write(result);
            document.write(linebreak);
       
            document.write("Value of a => (a += b) => ");
            result = (a += b);
            document.write(result);
            document.write(linebreak);
       
            document.write("Value of a => (a -= b) => ");
            result = (a -= b);
            document.write(result);
            document.write(linebreak);
       
            document.write("Value of a => (a *= b) => ");
            result = (a *= b);
            document.write(result);
            document.write(linebreak);
       
            document.write("Value of a => (a /= b) => ");
            result = (a /= b);
            document.write(result);
            document.write(linebreak);
       
            document.write("Value of a => (a %= b) => ");
            result = (a %= b);
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>

Value of a => (a = b) => 10
Value of a => (a += b) => 20
Value of a => (a -= b) => 10
Value of a => (a *= b) => 100
Value of a => (a /= b) => 10
Value of a => (a %= b) => 0
Set the variables to different values and different operators and then try...

<html>
   <body> 
      <script type = "text/javascript">
         <!--
            var a = 10;
            var b = 20;
            var linebreak = "<br />";
       
            document.write ("((a > b) ? 100 : 200) => ");
            result = (a > b) ? 100 : 200;
            document.write(result);
            document.write(linebreak);
       
            document.write ("((a < b) ? 100 : 200) => ");
            result = (a < b) ? 100 : 200;
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>

((a > b) ? 100 : 200) => 200
((a < b) ? 100 : 200) => 100
Set the variables to different values and different operators and then try...

<html>
   <body>     
      <script type = "text/javascript">
         <!--
            var a = 10;
            var b = "String";
            var linebreak = "<br />";
       
            result = (typeof b == "string" ? "B is String" : "B is Numeric");
            document.write("Result => ");
            document.write(result);
            document.write(linebreak);
       
            result = (typeof a == "string" ? "A is String" : "A is Numeric");
            document.write("Result => ");
            document.write(result);
            document.write(linebreak);
         //-->
      </script>     
      <p>Set the variables to different values and different operators and then try...</p>
   </body>
</html>

Result => B is String
Result => A is Numeric
Set the variables to different values and different operators and then try...

No comments:

Post a Comment

Welcome

Lets learn java script