判断是否为布尔值的方法

   2025-07-19 admin00100

Boolean()构造函数可用于创建布尔对象以及布尔原始值,表示true或false值。

在下面的代码中,我详细介绍了JavaScript中布尔值的创建。

示例:sample52.html

cript;toolbal:false;"><!DOCTYPEhtml><htmllang="en"><body><script>//CreateaBooleanobjectusingthenewkeywordandtheBoolean()constructor.varmyBoolean1=newBoolean(false);//Usingnewkeyword.console.log(typeofmyBoolean1);//Logs'object'.//CreateaBooleanliteral/primitivebydirectlyusingthenumberconstructorwithoutnew.varmyBoolean2=Boolean(0);//Withoutnewkeyword.console.log(typeofmyBoolean2);//Logs'boolean'.//CreateBooleanliteral/primitive(constructorleveragedbehindthescenes).varmyBoolean3=false;console.log(typeofmyBoolean3);//Logs'boolean'.console.log(myBoolean1,myBoolean2,myBoolean3);//Logsfalsefalsefalse.</script></body></html>
 
举报收藏 0打赏 0评论 0
 
更多>同类资讯
推荐图文
推荐资讯
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  版权声明  |  网站地图  |  RSS订阅
Powered By DESTOON