ES10: Symbol, A datatype

Arshad
3 min readMay 5, 2019

Symbol is the new datatype introduced in the Javascript ES10, it may be not available now in your browsers but it will be introduced before you know it.

What is Symbol?

Symbol is the datatype introduced in the ECMAScript 2019 (ES2019)/ES10. Symbol provides the unique key in the name of the variable you defined.

For example:

Let me surprise you with the new features of the Symbol datatype

So what’s happening above is when you call Symbol(‘s’), a unique symbol is created. Mainly the comparison is between two logically distinct ID’s and resultant value False.

Symbol is also used to differentiate between public and private properties. Let’s take an example to understand this.

So what we do here is, in the first three lines we created Symbol unique keys and from the fourth line we created an object using object literal symbol and every symbol property is assigned with some value. In the last line, we added property[one] directly to the object via obj[one].

So from which properties the Private properties of the Symbol are hidden are Object.entries, Object.keys, and also from literals like for..in loop.

Also in case of the JSON.stringify the properties are hidden.

The private properties of the Symbol can be exposed via Object.getOwnPropertySymbols method.

So the last and wonderful feature of the Symbol is that it creates a global registry for the symbols using methods Symbol.forKey and Symbol.for

This happens because of the variable properties of both sym and bol are sharing the same key ‘age’.

So hopefully you have a good understanding of the symbol now :)

Follow for more bleeding-edge updates on ES10.

Don’t forget to clap.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Arshad
Arshad

Responses (1)

Write a response