The Boolean type has two literal
values: true and false.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.
这是什么意思?布尔对象和布尔数据类型有什么区别?
解决方法:
这是一个布尔值:
true
这是一个包装值的布尔对象:
new Boolean(true);
具有对象会增加一个间接级别.尝试看一下区别:
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.
也可以看看:
> What is the purpose of new Boolean() in Javascript?