黄子涵

3.5 布尔型

3.5.1 布尔值

// 布尔型也被称为逻辑值类型或者真假值类型。
// 布尔型只能够取真(true)和假(false)两种数值。
// 除此以外,其他的值都不被支持。
var hzh1 = true;
console.log("它们是true还是false?");
console.log("hzh1?" + hzh1);
console.log("(!hzh1)?" + (!hzh1)); // true的否定为false
console.log("(!!hzh1)?" + (!!hzh1)); // 否定的否定为肯定
console.log("**************************************************");
// 对布尔值进行 typeof 运算的话,得到的结果为 "Boolean"。
console.log("它们是什么数据类型?");
console.log("true?" + true);
console.log("false?" + false);
console.log("hzh1?" + hzh1);
console.log("(!hzh1)?" + (!hzh1)); // true的否定为false
console.log("(!!hzh1)?" + (!!hzh1)); // 否定的否定为肯定

image

3.5.2 布尔类(Boolean 类)

// 布尔类(Boolean 类)是一种布尔型的包装类型。
// 其地位以及使用方法和 String 类以及 Number 类相同。
// 像下面这样对布尔值使用点运算符的话,
// 就能够对布尔值进行隐式数据类型转换,将其转为布尔对象。
// 但是,布尔类中并没有什么实用的方法,所以基本上也很少会去使用
console.log("隐式数据类型转换为了Boolean对象:");
console.log(true.toString());

image

3.5.3 Boolean 类的功能

Boolean 类的函数以及构造函数调用

image

Boolean 类的属性

image

Boolean.prototype 对象的属性

image

Boolean 类的实例属性

image

posted @   黄子涵  阅读(218)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示