# Boolean 对象

{% hint style="info" %}
参考资料：[Boolean 对象](https://wangdoc.com/javascript/stdlib/boolean.html)
{% endhint %}

通过 new 生成的 Boolean 对象，如果参数是 0, -0, null, false, NaN, undefined, “” 生成的 Boolean 对象的值为 false，如果参数是其他值均为 true。

```javascript
const b = new Boolean(); // 等同于 var b = new Boolean(null);
```

注意区别 new Boolean() 与 Boolean()，new 生成的是对象，如果只需要得到布尔值，则单独使用 Boolean() 即可。

```javascript
Boolean(false) // false
new Boolean(false) // true
Boolean(null) // false
new Boolean(null) // true
```

Boolean() 可以将任意值转为布尔值。

```javascript
Boolean(undefined) // false
Boolean(null) // false
Boolean(0) // false
Boolean('') // false
Boolean(NaN) // false
​
Boolean(1) // true
Boolean('false') // true
Boolean([]) // true
Boolean({}) // true
Boolean(function () {}) // true
Boolean(/foo/) // true
```

{% hint style="info" %}
如果你对内容有任何疑问，欢迎提交 [❕issues](https://github.com/MrEnvision/Front-end_learning_notes/issues) 或 [✉️ email](mailto:EnvisionShen@gmail.com)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sherwinshen.gitbook.io/qian-duan-xue-xi/frontend-basic/javascript/js-objects/boolean.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
