[英]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 你会在这里找到解释
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.