Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Logo of newsletter “ES.next news”
Newsletter (free)

ES proposal: Symbol.prototype.description

[2019-01-29] dev, javascript, es2019
(Ad, please don’t block)

The proposal “Symbol.prototype.description” (by Michael Ficarra) is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how it works.

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 proposal introduces the getter Symbol.prototype.description to access the description directly:

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