5-1 算术运算符( + - * / % )
两边都先转换为number,再运算// + - * / %var a =3;var b = 3.3;var c = 4;console.log(a*b) // 9.899999999999999console.log(b/a) // 1.0999999999999999console.log(c%a) // 1
5-2 比较运算符( >,<,==,>=,<=,!= )
两边都先转换为number,再比较,返回的是 booleanvar a = truevar b = 1;console.log(a==b) // trueconsole.log(a=="1") //true 两边都先转为number
注意: null == undefined
null 和 undefined 不能转化为其他值** Number(""),Number(" "),Number(null) => 输出 0**
// Number(""),Number(" "),Number(null) => 输出 0console.log(false == ""); // trueconsole.log(true == 1); // trueconsole.log(null == undefined); // trueconsole.log(undefined == false); // falseconsole.log(1 == "1"); // trueconsole.log(null == false); // false/* 1.只有有一边为 boolean 先两边转为number2.一边为string,一边为number,先将两遍转为number// 两边都先转为number3. null == undefined4. null 和 undefined 不能转化为其他值*/
5-3 逻辑运算符( &&,||,! )
两边都先转换为boolean,再判断,返回的是 boolean值```javascript // && 逻辑与 两个为true,结果才为true // || 或 只要有一个为true,结果就为true // ! 非
console.log(3>2 && 4>3) // true && true 结果为true console.log(3>2 && 4<3) // true && false 结果为false
console.log(11>5 || 3<4) // true || false 结果为true
console.log(!(3>4)) //!false 结果为true
<a name="wYA0B"></a>### 5-3-1 或运算的注意点- **`|| 有一边为true,结果就为 true,遇到true就会返回`**```javascriptvar b = 0 || "abc"var c = "abc" || 1;var d = 0 || NaNconsole.log(b) // abcconsole.log(c) // abcconsole.log(d) // NaN
5-3-2 与运算的注意点
**两边都为true,结果才为true 遇到false的情况,直接返回**console.log("abc" && 10) // 10 console.log(0 && "abc") // 05-4 三元运算符
// true 输出问号后面的第一段语句 // false 输出问号后面的第二段语句 var a = (4>5)?"4大于5":"4小于5"; console.log(a)5-5 赋值运算(+=,-=)
// +=,-= var a = 2; //a=a+4; a+=4; var b = 4; b-=4; // b=b-4; console.log(a) // 6 console.log(b) // 0
