自增自减

终于搞懂了自增自减运算符

var a = 10;
var b = 20 + a++;   //先取出变量a的值与20求和后赋给变量b,之后a自增1
console.log(b);     //30
console.log(a);     //11
var a = 10;
var b = 20 + ++a;   //先将变量a自增1,再与20求和结果赋给变量b
console.log(b);     //31
console.log(a);     //11
var a1 = 10;
console.log(a1 + ++a1);     //10+11=21

var a2 = 10;
console.log(a2 + a2++);     //10+10=20

var a3 = 10;
console.log(a3++ + ++a3);   //10+12=22

var a4 = 10;
console.log(a4++ + a4++);   //10+11=21

var a5 = 10;
console.log(++a5 + ++a5);   //11+12=23

var a6 = 10;
console.log(++a6 + a6++);   //11+11=22

var b1 = 10;
console.log(b1 + --b1);     //10+9=19

var b2 = 10;
console.log(b2 + b2--);     //10+10=20

var b3 = 10;
console.log(b3-- + --b3);   //10+8=18

var b4 = 10;
console.log(b4-- + b4--);   //10+9=19

var b5 = 10;
console.log(--b5 + --b5);   //9+8=17

var b6 = 10;
console.log(--b6 + b6--);   //9+9=18

你可能感兴趣的:(前端,javascript)