++放前面先自增,后运算
++放后面先运算,再自增
var a = 3;
var b = ++a +4 + a++;
/*a=4 b = 8
a=5 b=12
*/
console.log(a); //5
console.log(b); //12
<script>
var i = 10;
var b = 5 + i++;
console.log('b=',b); // 15
console.log('i=',i); // 11
</script>
<script>
var i = 10;
var b = 5 + ++i;
console.log('b=',b); // 16
console.log('i=',i); // 11
</script>
<script>
// 求b的值
var i = 16;
var j = 20;
// 20 16 18
var b = j + i++ + ++i; // 包含了5步运算
console.log(b); // 54
</script>
<script>
var i = 1;
var j = 1;
var a = 10;
var b = a + i++;
// b = 11; i = 2;
// 11 3 3 2
// var c = b + ++i + i++ + ++j;
// 求b和c的值
// b=11, c=19
</script>
<script>
var sum = 10;
sum += 5;
console.log(sum); // 15
</script>
-- 放前面先自减,后运算
-- 放后面先运算,再自减
var a = 12;
// a--;
a=a-1;
console.log(a);
<script>
var i = 1;
var j = 1;
// () => 自加和自减 => 算术运算 => 关系运算(比较运算) => 逻辑运算 => 赋值运算
var sum = 20 + i++ + 'abc' || 123 - ++i + ++j + ++j + '123' == 123 * 2/4; // '21abc'
</script>