23-包装类
包装类
包装类的介绍
var num = new Number(3);
var str = new String("hello");
var bool = new Boolean(true);
console.log(typeof num); // 打印结果:object基本数据类型不能添加属性和方法
我的公众号

Last updated
var num = new Number(3);
var str = new String("hello");
var bool = new Boolean(true);
console.log(typeof num); // 打印结果:object
Last updated
var boo1 = new Boolean(true);
var boo2 = new Boolean(true);
console.log(boo1 === boo2); // 打印结果竟然是:falsevar boo3 = new Boolean(false);
if (boo3) {
console.log('qianguyihao'); // 这行代码竟然执行了
} var str = 123;
str = str.toString(); // 将 number 类型转换为 string 类型
str.hello = "千古壹号"; // 添加属性
console.log(typeof str); // 打印结果:string
console.log(str.hello); // 打印结果:undefined