JavaScript学习与实践(4)
JS Boolean对象,用于转换非布尔型到布尔型,
例子:
<html> <body> <script type="text/javascript"> var b1=new Boolean( 0) var b2=new Boolean(1) var b3=new Boolean("") var b4=new Boolean(null) var b5=new Boolean(NaN) var b6=new Boolean("false") document.write("0 is boolean "+ b1 +"<br />") document.write("1 is boolean "+ b2 +"<br />") document.write("An empty string is boolean "+ b3 + "<br />") document.write("null is boolean "+ b4+ "<br />") document.write("NaN is boolean "+ b5 +"<br />") document.write("The string 'false' is boolean "+ b6 +"<br />") </script> </body> </html>
大家可以去运行以下
下面是一个比较全面的参考
Boolean Object Methods
FF: Firefox, N: Netscape, IE: Internet Explorer
Method | Description | FF | N | IE |
---|---|---|---|---|
toSource() | Represents the source code of an object | 1 | 4 | – |
toString() | Converts a Boolean value to a string and returns the result | 1 | 4 | 4 |
valueOf() | Returns the primitive value of a Boolean object | 1 | 4 | 4 |
Boolean Object Properties
Property | Description | FF | N | IE |
---|---|---|---|---|
constructor | A reference to the function that created the object | 1 | 2 | 4 |
prototype | Allows you to add properties and methods to the object | 1 | 2 | 4 |
原文链接:https://www.cnblogs.com/jiayong/articles/637206.html
本文来源 爱码网,其版权均为 原网址 所有 与本站无关,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源。
© 版权声明
文章版权归作者所有,未经允许请勿转载。