The assignment operations in JavaScript can be divided into simple assignment operations and compound assignment operations. The simple assignment operation is to save the value of the expression on the right of the assignment operator (=) to the left variable, while the compound assignment operation mixes other operations (such as arithmetic operations) and assignment operations. For example:
sum+=i; //等同于sum=sum+i;
The assignment operators in JavaScript are shown in the following table.
For example, an employee's monthly salary of 5000 yuan, deduction of the total insurance costs of 500 yuan, the personal income tax threshold is 3500 yuan, the tax rate is 3%, calculate the actual income of the employee is how much. The code is as follows:
01 <script type="text/javascript">02 var salary = 5000;03 var insurance = 500;04 var threshold = 3500;05 var tax = 0.03;06 salary-=insurance;07 var salary1=salary;08 salary1-=threshold;09 salary1*=tax;10 salary-=salary1;11 document.write("该员工的实际收入为"+salary+"元");12 </script>
The result of the operation is:
该员工的实际收入为4470元
Use of assignment operators in JavaScript