Symbol.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 September 2015.

Die valueOf()-Methode von Symbol-Werten gibt diesen Symbolwert zurück.

Probieren Sie es aus

const symbol1 = Symbol("foo");

console.log(typeof Object(symbol1));
// Expected output: "object"

console.log(typeof Object(symbol1).valueOf());
// Expected output: "symbol"

Syntax

js
valueOf()

Parameter

Keine.

Rückgabewert

Der primitive Wert des angegebenen Symbol-Objekts.

Beschreibung

Die valueOf()-Methode von Symbol gibt den primitiven Wert eines Symbol-Objekts als Symbol-Datentyp zurück.

JavaScript ruft die valueOf()-Methode auf, um ein Objekt in einen primitiven Wert zu konvertieren. Es ist selten notwendig, dass Sie die valueOf()-Methode selbst aufrufen; JavaScript ruft sie automatisch auf, wenn es auf ein Objekt trifft, wo ein primitiver Wert erwartet wird.

Beispiele

Verwendung von valueOf()

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

Spezifikationen

Specification
ECMAScript® 2025 Language Specification
# sec-symbol.prototype.valueof

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
valueOf

Legend

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

Full support
Full support

Siehe auch