当前位置:网站首页>What is the difference between the three values of null Nan undefined in JS

What is the difference between the three values of null Nan undefined in JS

2022-07-07 22:03:00 Vayne's fat tiger

We are JS You will definitely encounter unfamiliar faces in data types , such as NaN and undefined, about null We are Java I've been in contact with you for a long time , Then let's look at the relationship and difference between these three things through the code ?

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>null NaN undefined What is the difference between these three values </title>
	</head>
	<body>
		<script type="text/javascript">
			// ==  Is the equivalence operator 
			alert(1 == true); // true
			alert(1 === true); // false
			
			// null NaN undefined  Inconsistent data types .
			alert(typeof null); // "object"
			alert(typeof NaN); // "number"
			alert(typeof undefined); // "undefined"
			
			// null and undefined Can be equivalent to .
			alert(null == NaN); // false
			alert(null == undefined); // true
			alert(undefined == NaN); // false
			
			//  stay JS There are two special operators 
			// ==( The equivalent operator : Only judge whether the values are equal )
			// ===( The congruent operator : Both judge whether the values are equal , And judge whether the data types are equal )
			alert(null === NaN); // false
			alert(null === undefined); // false
			alert(undefined === NaN); // false
		</script>
	</body>
</html>

原网站

版权声明
本文为[Vayne's fat tiger]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071415406138.html

随机推荐