Boolean.prototype.valueOf()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
尝试一下
const x = new Boolean();
console.log(x.valueOf());
// Expected output: false
const y = new Boolean("Mozilla");
console.log(y.valueOf());
// Expected output: true
语法
js
valueOf()
参数
无。
返回值
给定 Boolean
对象的原始值。
描述
Boolean
的 valueOf()
方法以布尔数据类型返回 Boolean
对象或 Boolean
字面量的原始值。
该方法通常在 JavaScript 内部调用,而不是在代码中显式调用。
示例
使用 valueOf()
js
const x = new Boolean();
const myVar = x.valueOf(); // 给 myVar 赋值 false
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-boolean.prototype.valueof |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
valueOf |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.