什么是布尔对象,并在JavaScript中的布尔数据类型之间的区别?

什么是布尔对象,并在JavaScript中的布尔数据类型之间的区别?

问题描述:

布尔类型有两个字面
  值:true和false

The Boolean type has two literal values: true and false.

不要混淆原始的布尔
  值true和与真实假的
  布尔的假值
  目的。布尔对象是
  包装器的原始布尔
  数据类型。有关详情,请Boolean对象
  信息。

Do not confuse the primitive Boolean values true and false with the true and false values of the Boolean object. The Boolean object is a wrapper around the primitive Boolean data type. See Boolean Object for more information.

这是什么意思?什么是布尔对象和布尔数据类型??之间的差异

What does this mean? What's the difference between the Boolean object and the Boolean data type??

这是一个布尔值:

true

这是一个Boolean对象包裹值:

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.

另请参阅: