Symbol.prototype[Symbol.toPrimitive]()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2017.

The [Symbol.toPrimitive]() method of Symbol values returns this symbol value.

Syntax

js
symbolValue[Symbol.toPrimitive](hint)

Parameters

hint

A string value indicating the primitive value to return. The value is ignored.

Return value

The primitive value of the specified Symbol object.

Description

The [Symbol.toPrimitive]() method of Symbol returns the primitive value of a Symbol object as a Symbol data type. The hint argument is not used.

JavaScript calls the [Symbol.toPrimitive]() method to convert an object to a primitive value. You rarely need to invoke the [Symbol.toPrimitive]() method yourself; JavaScript automatically invokes it when encountering an object where a primitive value is expected.

Examples

Using [Symbol.toPrimitive]()

js
const sym = Symbol("example");
sym === sym[Symbol.toPrimitive](); // true

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-symbol.prototype-%symbol.toprimitive%

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
[Symbol.toPrimitive]
Chrome – Full support
Chrome 47 (Release date: 2015-12-01)
footnote Full support
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 34 (Release date: 2015-12-08)
footnote Full support
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 47 (Release date: 2015-12-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 34 (Release date: 2015-12-16)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10 (Release date: 2016-09-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 47 (Release date: 2015-12-02)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10 (Release date: 2016-09-13)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 6 (Release date: 2016-04-26)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also