<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var state = 1==1;//true
console.log(state);
var state = 1=="1";//true,会先将"1"转为数字1
console.log(state);
var state = 1==true;//true,会先将true转为数字1——关系运算符中如果数值型数据与非数值型数据进行比较,则会true隐式转换为1,false隐身转换为0
console.log(state);
</script>
</body>
</html>
输出结果
2、===:用于严格比较,只有数据类型相同且值相等的两个数据才会返回true。
示例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var state = 1===1;//true
console.log(state);
var state = 1==="1";//false
console.log(state);
var state = 1===true;//false
console.log(state);
</script>
</body>
</html>