简体   繁体   English

JavaScript中的Boolean对象和Boolean数据类型有什么区别?

[英]What is the difference between the Boolean object and the Boolean data type in JavaScript?

The Boolean type has two literal values: true and false. Boolean类型有两个文字值:true和false。

Do not confuse the primitive Boolean values true and false with the true and false values of the Boolean object. 不要将原始布尔值true和false与Boolean对象的true和false值混淆。 The Boolean object is a wrapper around the primitive Boolean data type. Boolean对象是原始布尔数据类型的包装器。 See Boolean Object for more information. 有关更多信息,请参阅Boolean对象。

What does this mean? 这是什么意思? What's the difference between the Boolean object and the Boolean data type?? 布尔对象和布尔数据类型之间有什么区别?

This is a boolean value: 这是一个布尔值:

true

This is a Boolean object wrapping the value: 这是一个包装值的布尔对象:

new Boolean(true);

Having the object adds a level of indirection. 让对象增加一个间接级别。 Try this to see the difference: 试试这个看看差异:

var a = true;
var b = true;
var c = new Boolean(true);
var d = new Boolean(true);

alert(a == b); // true - two `true` values are equal.
alert(c == d); // false - they are not the same object.

See also: 也可以看看:

我想添加其他答案,布尔对象也可以为null ,但布尔值不能。

The boolean data type is a value that can only be true or false. 布尔数据类型是一个只能为true或false的值。 The Boolean object is an object that represents a boolean value. Boolean对象是表示布尔值的对象。

The Boolean Data Type is the 'boolean' (TRUE or FALSE) whereas the Boolean Object is an object that translates values INTO boolean data 布尔数据类型是'布尔'(TRUE或FALSE),而布尔对象是转换值INTO布尔数据的对象

You'll find an explanation here 你会在这里找到解释

w3schools W3Schools的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 作为原始对象的布尔值和作为对象属性的布尔值之间有什么区别? - What's the difference between a boolean as primitive and a boolean as property of an object? 使用布尔构造函数的类型强制和内部if有什么区别 - what is the difference between type coercion using Boolean constructor function and inside if VBA和Javascript布尔表达式之间有什么区别? - What's the difference between VBA and Javascript boolean expressions? Boolean('')为false和Boolean(new String(''))有什么区别? - what is the difference between Boolean('') is false and Boolean(new String(''))? 布尔文字和布尔值之间有什么区别? - What's the difference between a boolean literal and a boolean value? (typeof variable ==='boolean')和(typeof variable =='boolean')之间有什么区别? - What's the difference between (typeof variable === 'boolean') and (typeof variable == 'boolean')? Javascript定制数据类型和对象之间有什么区别? - What is the difference between a Javascript custom data type and an object? 这两个javascript布尔表达式之间有什么区别吗? - Is there any difference between these two javascript boolean expressions? Javascript中的布尔对象有什么实际用途? - What practical use is a Boolean object in Javascript? addEventListener() 中的布尔值“usecapture”参数和替代选项对象的“capture”属性有什么区别? - What is the difference between the boolean “usecapture” argument in addEventListener() and the “capture” property of the alternative options object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM