in conclusion:
- Pre-addition: ++ a == a + = 1 == a = a + 1
- Add after adding: a++, keep itself unchanged, let the following element with the same name perform +1 operation.
- For a, whether it is pre-addition or post-addition, it is the number of operators plus the initial value. There are x operators that are x+initial value
- The principle of subtraction is the same as addition
example
- Plus plus
var a = 1;
b = ++a + ++a +3 + ++a;
console.log(a);//a等于4
console.log(b);//b等于12
Analysis of calculation process
2. Post-addition
var a = 1;
var b = a++ + a++ +3 + a++;
console.log(b);//b等于9
Operational process analysis
3. Pre-addition and post-addition mixing
var a = 1;
var b = a++ + ++a + ++a -2 + a++ +1 + a++ + ++a ;
console.log(b);//b等于23
The principle of subtraction and subtraction is the same as that of addition and addition in the calculation process .
If there is an error, please feel free to correct it; if you have any questions, please leave a message for discussion.