Exploring ES2018 and ES2019
Please support this book: buy it or donate
(Ad, please don’t block.)

16. Symbol.prototype.description

This chapter describes the ES2019 feature “Symbol.prototype.description” (by Michael Ficarra).

When creating a symbol via the factory function Symbol(), you can optionally provide a string as a description, via a parameter:

const sym = Symbol('The description');

Until recently, the only way to access the description was by converting the symbol to a string:

assert.equal(String(sym), 'Symbol(The description)');

The feature introduces the getter Symbol.prototype.description to access the description directly:

assert.equal(sym.description, 'The description');