javascript中==,===,!=,!==的区别
javascript中比较运算符区别举例
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>比较运算符</title>
</head>
<body>
<script>
var owList=null;
if(owList!==null){
console.log(" 不绝对等于(值和类型有一个不相等,或两个都不相等)")
}
if(owList!=null){
console.log("不等于");
}
if(owList==null){
console.log("值为null")
}
</script>
</body>
</html>
效果图

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>比较运算符</title>
</head>
<body>
<script>
var owList=new Array();
if(owList!==null){
console.log(" 不绝对等于(值和类型有一个不相等,或两个都不相等)")
}
if(owList!=null){
console.log("不等于");
}
if(owList==null){
console.log("值为null")
}
</script>
</body>
</html>
效果图

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>比较运算符</title>
</head>
<body>
<script>
var temp="123";
var tempOne=123;
var tempTwo="12";
if(temp==tempOne){
console.log("值想等");
}
if(temp===tempOne){
console.log("类型和值都想等");
}
if(temp!=tempOne){
console.log("temp和tempOne值不相等");
}
if(temp!=tempTwo){
console.log("temp和tempTwo值不相等");
}
if(temp!==tempOne){
console.log("不绝对等于(值和类型有一个不相等,或两个都不相等)");
}
</script>
</body>
</html>

总结一下,两个等于是比较的只是值是否想等,三个等于号比较是两个方面,类型和值
浙公网安备 33010602011771号