From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Learn about JavaScript’s Symbol type

Learn about JavaScript’s Symbol type

- The very last data type that we're going to look at in this course is something called symbols. Symbols are probably one of the least self-explanatory data types, but they're still extremely useful in many cases. Before we go into some of the use cases of symbols, let's discuss how to create them and some of their basic properties. The main way to define a symbol is like this, using the symbol constructor. The string that we pass to the constructor is called the description of the symbol, and we can always just leave that argument out entirely if we want to. Now, the whole idea of symbols is that no two distinct symbols will ever be equal to each other. So even if we create two symbols with the exact same description when we test if they're equal, and equality testing, by the way, is something we'll talk about shortly. JavaScript will tell us that they're not equal. In fact, the only way that two symbols will ever be equal is if we either compare the same symbol to itself or if we…

Contents