Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


I am a bit confused

var mySet = new Set();

mySet.delete('bar'); // Returns false. No "bar" element found to be deleted.
mySet.delete('foo'); // Returns true.  Successfully removed.

mySet.has('foo');    // Returns false. The "foo" element is no longer present.

What does var mySet = new Set(); mean?

1 Answer

Steven Parker
Steven Parker
221,292 Points

It creates a new, empty set object in the variable mySet.

It's necessary to be able to call the .add method to give it items.

Thank you again Steven, you are always here for me and you are so kind, I hope everything in your life goes as expected.