Special Well-Known Symbols

Get introduced to special well-known symbols in JavaScript and see them in action.

Why do we need special Symbols?

In languages like Java and C#, we expect classes to collaborate with each other through interfaces. For example, if a class expects another class to have a compare() method, it expects that the class will implement a Comparator interface. JavaScript does not follow such traditions or ceremonies. The contracts are rather informal and relaxed. If a class expects another class to have a method, it simply expects to find that method—as simple as that.

While there is merit to that simplicity, a Single Source of Truth principleSingleSourceOfTruth is still useful from the documentation point of view.

Furthermore, not having a clear way to specify that you expect a class to implement a particular method or a property can lead to errors.

An assumption

Get hands-on with 1400+ tech skills courses.