1.

What is the reason behind adding Symbol to ES6?

Answer»

Symbols are a new type of object that can be USED as distinct property names in objects. Using Symbols instead of strings allows separate modules to create properties that are not mutually exclusive. Symbols can also be KEPT private, preventing anyone who does not have direct access to the SYMBOL from accessing its properties.

Symbols are a brand-new kind of primitive. Symbols, like numbers, strings, and booleans, have a function that can be used to produce them. Symbols, unlike the other primitives, do not have a literal SYNTAX (similar to how strings have ") and can only be created using the Symbol constructor:

 let symbol = Symbol();

In truth, Symbols are only a little different means of attaching properties to an object; the well-known Symbols could easily be provided as standard methods, just like Object.prototype.has Own Property which APPEARS in anything that inherits from Object.



Discussion

No Comment Found