valueOf() method returns the primitive value of a Symbol object.

句法

Symbol().valueOf()
					

返回值

The primitive value of the specified Symbol 对象。

描述

valueOf 方法为 Symbol returns the primitive value of a Symbol object as a Symbol data type.

JavaScript calls the valueOf method to convert an object to a primitive value. You rarely need to invoke the valueOf method yourself; JavaScript automatically invokes it when encountering an object where a primitive value is expected.

范例

Using valueOf

const sym = Symbol("example");
sym === sym.valueOf(); // true
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Symbol.prototype.valueOf' in that specification.

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
valueOf Chrome 38 Edge 12 Firefox 36 IE No Opera 25 Safari 9 WebView Android 38 Chrome Android 38 Firefox Android 36 Opera Android 25 Safari iOS 9 Samsung Internet Android 3.0 nodejs 0.12

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: