★数字和字符串转完之后为true。
★undefined、null、0转完之后为false.
var n1=123; var n2="345" var n3; var n4=null; var n5=Infinity; var n1=Boolean(n1); var n2=Boolean(n2); var n3=Boolean(n3); var n4=Boolean(n4); var n5=Boolean(n5); document.write("n1的值是:" + n1+ "<br>" + "n1的类型是:"+typeof(n1) + "<br>"); document.write("n2的值是:" + n2+ "<br>" + "n2的类型是:"+typeof(n2) + "<br>"); document.write("n3的值是:" + n3+ "<br>" + "n3的类型是:"+typeof(n3) + "<br>"); document.write("n4的值是:" + n4+ "<br>" + "n4的类型是:"+typeof(n4) + "<br>"); document.write("n5的值是:" + n5+ "<br>" + "n5的类型是:"+typeof(n5) + "<br>"); /*页面输出结果为: n1的值是:true n1的类型是:boolean n2的值是:true n2的类型是:boolean n3的值是:false n3的类型是:boolean n4的值是:false n4的类型是:boolean n5的值是:true n5的类型是:boolean*/
原文地址:https://www.cnblogs.com/EricZLin/p/8597372.html
时间: 2024-10-04 13:36:00