📜  JavaScript-布尔对象

📅  最后修改于: 2020-12-18 05:01:49             🧑  作者: Mango


布尔对象表示两个值,“ true”或“ false”。如果省略value参数或为0,-0,null,false, NaN, undefined或空字符串(“”),则对象的初始值为false。

句法

使用以下语法创建一个布尔对象。

var val = new Boolean(value);

布尔属性

这是布尔对象的属性的列表-

Sr.No. Property & Description
1 constructor

Returns a reference to the Boolean function that created the object.

2 prototype

The prototype property allows you to add properties and methods to an object.

在以下各节中,我们将通过一些示例来说明布尔对象的属性。

布尔方法

这是布尔对象的方法及其说明的列表。

Sr.No. Method & Description
1 toSource()

Returns a string containing the source of the Boolean object; you can use this string to create an equivalent object.

2 toString()

Returns a string of either “true” or “false” depending upon the value of the object.

3 valueOf()

Returns the primitive value of the Boolean object.

在以下各节中,我们将通过一些示例来演示布尔方法的用法。