Exercise on Symbols
Explore how to use Symbols in JavaScript for creating unique and private object keys. Learn to compare the underscore prefix approach with Symbols and understand how to simulate private fields in classes for better code privacy and structure.
We'll cover the following...
We'll cover the following...
Exercise 1:
What are the pros and cons of using an underscore prefix for expressing our intention that a field is private? Compare this approach with symbols!
Solution 1:
Pros:
-
Notation and developer experience is simple, provided that your team spreads this practice
-
It does not result in a hard-to-read code structure, all you need is one more character ...