var o = new Object(123) var o1 = new Object("123) o.valueOf()//123 o.toString()//"123" o1.valueOf()//"123" o1.toString()//"123" var o2 = [1,2,3] o2.valueOf()//[1, 2, 3] o2.toString()//"1,2,3" var o3 = {name:"teren",age:18} o3.valueOf()//Object {name: "teren", age: 18} o3.toString()//"[object Object]"
Number对象是数值对应的包装对象,String对象是字符串对应的包装对象,Boolean是布尔值对应的包装对象
var num = 123//type of num -> "number" var num = new Number(123) //type of num -> "object" var str = "hello" var str = new String("hello") var bool = true; var bool = new Boolean(true)
【注】本笔记的资料大部分参考阮一峰的JavaScript标准参考教程
您可能感兴趣的文章: