Whenever you want to store unique elements in a container for which the order doesn't matter and you mainly want to use it to check for membership of different objects.
Sets are also useful when you want to perform operations like union, intersection, a difference like you do in mathematical sets.
Let's look at both how we can define our own set and use the existing one in ES6.
The ES6 set API provides some methods. We'll implement these methods in our implementation and also look at how to use them using the built-in class.