DEV Community

Discussion on: What Javascript features are the most confusing to you?

Collapse
 
pris_stratton profile image
pris stratton

One thing I have never wrapped my head around is Symbols. I get that they’re unique objects and I understand some of the use cases I’ve seen.. but what are they under the surface?

Collapse
 
murkrage profile image
Mike Ekkel

Great question! I don't fully understand Symbols myself, but I do know that they are a primitive data type under the surface. This means they are, data wise, the same as numbers (int / float), booleans, strings, etc. They cannot be mutated (=ability to change) just like the other primitives.

From what I understand, their main use case is being an identifier for object properties.

Collapse
 
pris_stratton profile image
pris stratton

Yeah I think the time I saw them used that made sense was in the O’Reilly book Learning JavaScript where they were used to prevent an object property being accessed directly - they’d have to be accessed using get or set methods instead. But I think there are easier ways to achieve this like proxies.