Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the description of a ES6 Symbol

I wonder if there is a nice way to get the descriptions of a Symbol.

For example,

var s = Symbol(5);

The default implementation of the toString will simply print Symbol(5)

I would like to find a way to extract the actual description i.e. 5

like image 867
ppoliani Avatar asked May 18 '15 11:05

ppoliani


People also ask

Which primitive retrieve a property value to a symbol?

Symbol Methods Returns the primitive value of the Symbol object.

What is the at symbol in JavaScript?

The @ symbol in javascript stands for a decorator. Decorators are not present in ES6 so the in code you are working with the decorator is probably transpiled to an version of javascript which can be run in any browser.

What is symbol type in ES6?

Symbols are new primitive type introduced in ES6. Symbols are completely unique identifiers. Just like their primitive counterparts (Number, String, Boolean), they can be created using the factory function Symbol() which returns a Symbol.


1 Answers

Symbol.description returns description of the symbol. Simply do s.description in your case.

like image 149
Rushi patel Avatar answered Oct 09 '22 06:10

Rushi patel