>,<,!=,===比较运算在比较运算中,先将两边的值转换为number再进行比较,最终得到的是boolean值
console.log(true>0);//number(true)>0console.log("11">0);console.log("9">10);//tips:=赋值,==相等console.log("9"==9)console.log("6"!=true);// 不仅要值相等,也要数据类型一样console.log("6"===6)console.log(5===5)
逻辑运算
/*&& 逻辑与两边都为true,结果才为true|| 逻辑或! 逻辑非*/
&&时的运算,console.log(10>8 && 12>5);//trueconsole.log(10>5 && 4>50);//false
||运算时只要有一边为true 结果一定为true两边都为true 结果都为trueconsole.log(10>4 || 0>1);console.log(0>10 || 9>20)
逻辑非 取反
console.log(!(5>4));//flase
特殊情况
//特殊情况/*逻辑运算可以参与非boolean的运算运算的时候,会将值转换为boolean 但返回值不一定是booleannumber 0string""*/
var a = 3 && 4;var b =3 && 0;var c =0 && 4;console.log(b);console.log(a);console.log(c);
总结:运算
1.算术运算
2.比较运算
>,<,==,===,!=tips:先将两边的值转为number,再比较 结果返回boolean
3.逻辑运算
tips:先将两边的值转换为boolean,在进行运算逻辑与,逻辑或,逻辑非
4
招式+口诀 8:30~9:00
4赋值运算
+=,-=,*=,/=,%=
5三目运算
var b =condition?exp: exp02condittion--true 输出expcondittion--false 输出exp02
var b =(4>3)?"大于":"小于";console.log(b);
