1-1、 算术运算
+,-,*,/,%,()先将值转换为number(Number),再进行计算。
Tips: +特殊,如何有一边为字符串,那么+起拼接符作用,结果一定是字符串。
1. true->1,false->0 null->0 "123" -->123console.log(true+10) //11;console.log("123"-1) //122;总结a、任何数字和NaN运算,得到都是NaN。b、其他的字符作除加运算以为的运算,先将值转换为number(Number),再进行计算。
1-2、 比较运算(关系)
将值转换为number,再进行比较,返回的是boolean==,等于,判断两边关系的时候,它会尽可能去判断两边相等。===,全等于,不仅值要相等,类型也要相等。
1-3、 逻辑运算
&& 与 两边都为true,结果就为true|| 或 只要有一边为true,结果就为true! 非 取反两边都先转换为boolean,再判断// && 逻辑与 两个为true,结果才为true// || 或 只要有一个为true,结果就为true// ! 非
console.log(3>2 && 4>3) // true && true 结果为trueconsole.log(3>2 && 4<3) // true && false 结果为falseconsole.log(11>5 || 3<4) // true || false 结果为trueconsole.log(!(3>4)) //!false 结果为true
var a = false;console.log(!a); //console.log(!!0) //falseconsole.log(!0) //true
逻辑运算符常用于布尔值之间;当操作数都是布尔值时,返回值也是布尔值。
特殊情况:
其他非布尔值也可以参与逻辑运算,参与的时候,会自动转换成布尔值进行运算。返回结果不一定就是布尔值。
例如console.log(3 && 4) //4Tips: && 优先级高于 ||例如console.log( false || 3 &&4); //4
1-3-1、 或运算的注意点
|| 有一边为true,结果就为 true,遇到true就会返回var b = 0 || "abc"var c = "abc" || 1;var d = 0 || NaNconsole.log(b) // abcconsole.log(c) // abcconsole.log(d) // NaN
1-3-2、 与运算的注意点
两边都为true,结果才为true 遇到false的情况,直接返回console.log("abc" && 10) // 10console.log(0 && "abc") // 0
1-4、 赋值运算
+=,-=,*=,/=,%=var a = 2;//a=a+4;a+=4;var b = 4;b-=4; // b=b-4;console.log(a) // 6console.log(b) // 0
1-5、 三元表达式
var a=(condition)?语句01:语句02;条件为true --输出语句01条件为false --输出语句02
1-6、 ++,—
a++ 与 ++aI ++单独运算不管在前在后,都会自增II ++混合运算++在前先自增后运算,++在后先运算后自增。

