<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>隐式转换</title>
</head>
<body>
<script>
console.log(1+’true’); // 1true String(1) + ‘true’ = ‘1true’
console.log(1+true); // 2 1+Number(true) = 1+1 = 2
console.log(1+undefined); // NaN 1+Number(undefined) = 1 + NaN = NaN
console.log(1+null); // 1 1+Number(null) = 1+0 =1
// 关系运算符
// 当有一边是数值则会通过Number将另一边转为数值
// 当两边都不是数值 则按照字符窜unicode编码转换
console.log(“2” > 10); // false
console.log(“2” > “10”); // true
// 多个字符从左往右依次比较
console.log(“abc” > “b”); //false
console.log(“abc” > “aad”); //true
console.log(undefined == undefined); //true
console.log(undefined == null); //true
console.log(null == null); //true
console.log(NaN == NaN); //false
// 1、关系运算符 将其他类型数据转换成数字
// 2、逻辑非 将其他数据类型用Boolean()转换
// 3、逻辑非优先级高于关系运算符
// 4、布尔值转换为false:0 NaN undefined Null ” false
console.log([] == 0); // true Number([].valueOf().toString()) = 0
console.log(![] == 0); // true Boolean([]) = true !true = false = 0
console.log([] == ![]); // true [] ” [].valueOf().toString()
// Number(”) = 0 Number(false) = 0
console.log([] == []); //false 两个空间
console.log({} == !{}); // false {}.valueOf().toString = ‘[object Object]’
console.log({} == {}); //false
</script>
</body>
</html>