posts - 501,comments - 0,views - 23802
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			/*
			 * 基本数据类型
			 * 	String Number Boolean Null Undefined
			 * 引用数据类型
			 * 	Object
			 * 
			 * 在JS中为我们提供了三个包装类,通过这三个包装类可以将基本数据类型的数据转换为对象
			 * 	String()
			 * 		- 可以将基本数据类型字符串转换为String对象
			 * 	Number()
			 * 		- 可以将基本数据类型的数字转换为Number对象
			 *  Boolean()
			 * 		- 可以将基本数据类型的布尔值转换为Boolean对象
			 * 	但是注意:我们在实际应用中不会使用基本数据类型的对象,
			 * 		如果使用基本数据类型的对象,在做一些比较时可能会带来一些不可预期的结果
			 */
			
			//创建一个Number类型的对象
			//num = 3;
			var num = new Number(3);
			var num2 = new Number(3);
			var str = new String("hello");
			var str2 = new String("hello");
			var bool = new Boolean(true);
			var bool2 = true;
			
			//向num中添加一个属性
			num.hello = "abcdefg";
			
			//console.log(str === str2);
			
			var b = new Boolean(false);
			
			/*if(b){
				alert("我运行了~~~");
			}*/
			
			/*
			 * 方法和属性之能添加给对象,不能添加给基本数据类型
			 * 	当我们对一些基本数据类型的值去调用属性和方法时,
			 * 		浏览器会临时使用包装类将其转换为对象,然后在调用对象的属性和方法
			 * 		调用完以后,在将其转换为基本数据类型
			 */
			var s = 123;
			
			s = s.toString();
			
			s.hello = "你好";
			
			console.log(s.hello);
			//console.log(typeof s);
			
			
		</script>
	</head>
	<body>
	</body>
</html>
posted on   垂序葎草  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示