Symbol.prototype.description

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.

La propriété en lecture seule description est une chaîne de caractères qui renvoie la description optionnelle de l'objet Symbol.

Exemple interactif

console.log(Symbol("desc").description);
// Expected output: "desc"

console.log(Symbol.iterator.description);
// Expected output: "Symbol.iterator"

console.log(Symbol.for("foo").description);
// Expected output: "foo"

console.log(`${Symbol("foo").description}bar`);
// Expected output: "foobar"

Syntaxe

js
Symbol("maDescription").description;
Symbol.iterator.description;
Symbol.for("toto").description;

Description

Les objets Symbol peuvent être créés avec une description facultative qui peut être utilisée pour du débogage mais sans accéder au symbole. La propriété Symbol.prototype.description peut être utilisée afin de lire cette description. Cette propriété est différente de Symbol.prototype.toString() car elle ne contient pas la chaîne de caractères "Symbol()" autour de la description (voir les exemples qui suivent).

Exemples

js
Symbol("desc").toString(); // "Symbol(desc)"
Symbol("desc").description; // "desc"
Symbol("").description; // ""
Symbol().description; // undefined

// symboles connus
Symbol.iterator.toString(); // "Symbol(Symbol.iterator)"
Symbol.iterator.description; // "Symbol.iterator"

// symboles globaux
Symbol.for("toto").toString(); // "Symbol(toto)"
Symbol.for("toto").description; // "toto"

Spécifications

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

Compatibilité des navigateurs

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
description

Legend

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

Full support
Full support
Partial support
Partial support
Has more compatibility info.

Voir aussi