CodesJava

Easy learning with example program codes

javascript assignment operators tutorial

JavaScript Assignment Operators:

JavaScript assignment operators are used to assign the values to the operands.

JavaScript Assignment Operators List:

OperatorDescriptionExample
=Assigna = 10 + 10; Result into a = 20
+=Add and assignvar a=10; a+=20; Result into a = 30
-=Subtract and assignvar a=20; a+=10; Result into a = 10
*=Multiply and assignvar a=10; a*=20; Result into a = 200
/=Divide and assignvar a=10; a/=2; Result into a = 5
%=Modulus and assignvar a=10; a%=2; Result into a = 0

JavaScript Assignment Operators Example:

<html>
<head>
<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>
</head>
   <body>
   </body>
</html>

Try it:

JS Bin on jsbin.com
 

Please follow and like us:








Copyright © 2019 CodesJava DMCA.com Protection Status