As the name suggest these operators are used to assign values to variables. The right hand value or variable is assigned to the left hand variable. Different assignment operators are listed below with these use. | |||||||||||||||||||||
|
|||||||||||||||||||||
Example | |||||||||||||||||||||
<html>
<head> </head> <body> <script type=”text/javascript”> var a,b a=5 b = 6 document.write(“<br>Value of a : “+a); document.write(“<br>Value of b : “+b); a+=b; document.write(“<br>Value of a after a+=b : “+a); a-=b document.write(“<br>Value of a after a-=b : “+a); a*=b document.write(“<br>Value of a after a*=b : “+a); a/=b document.write(“<br>Value of a after a/=b : “+a); a%=b document.write(“<br>Value of a after a%=b : “+a); </script> </body> </html> |
|||||||||||||||||||||
Output: | |||||||||||||||||||||
Value of a : 5 Value of b : 6 Value of a after a+=b : 11 Value of a after a-=b : 5 Value of a after a*=b : 30 Value of a after a/=b : 5 Value of a after a%=b : 5 |