<script>// 1. 想要一个变量自己加1 num = num + 1 比较麻烦var num =1;
num = num +1;// ++num
num = num +1;
console.log(num);// 3// 2. 前置递增运算符 ++ 写在变量的前面var age =10;++age;// 类似于 age = age + 1
console.log(age);// 3. 先加1 后返回值var p =10;
console.log(++p +10);</script>
4. 后置递增运算符
<script>var num =10;
num++;// num = num + 1 ++num;
console.log(num);// 1. 前置自增和后置自增如果单独使用 效果是一样的// 2. 后置自增 口诀:先返回原值 后自加1 var age =10;
console.log(age+++10);
console.log(age);</script>
5. 递增运算符练习
<script>var a =10;++a;// ++a 11 a = 11var b =++a +2;// ++a 12 a = 12
console.log(a);// 12
console.log(b);// 14var c =10;
c++;// c++ 11 c = 11var d = c+++2;// c++ = 11 c = 12
console.log(d);// 13var e =10;var f = e+++++e;// 1. e++ = 10 e = 11 2. e = 12 ++e = 12
console.log(f);// 22// 后置自增 先表达式返回原值 后面变量再自加1</script>
<script>var num =10;// num = num + 1; num++// num = num + 2; // num += 2;// num += 2;
num +=5;
console.log(num);var age =2;
age *=3;
console.log(age);</script>
11. 运算符优先级
<script>// ++num !num 2 + 3
console.log(4>=6||'人'!='阿凡达'&&!(12*2==144)&&true)var num =10;
console.log(5== num /2&&(2+2* num).toString()==='22');
console.log('-------------------');var a =3>5&&2<7&&3==4;
console.log(a);var b =3<=4||3>1||3!=2;
console.log(b);var c =2==="2";
console.log(c);var d =!c || b && a;
console.log(d);</script>