JavaScript assignment operators are used to assign the values to the operands.
JavaScript Assignment Operators List:
Operator | Description | Example |
= | Assign | a = 10 + 10; Result into a = 20 |
+= | Add and assign | var a=10; a+=20; Result into a = 30 |
-= | Subtract and assign | var a=20; a+=10; Result into a = 10 |
*= | Multiply and assign | var a=10; a*=20; Result into a = 200 |
/= | Divide and assign | var a=10; a/=2; Result into a = 5 |
Modulus and assign | var a=10; |
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 result = (a document.write(result); document.write(linebreak); </script> </head> <body> </body> </html>