JavaScript门道之标准库(4)

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标准参考教程

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ac0d3a2521b3856e9740116cca280010.html