What is the Set object used for in JavaScript?

What is the Set object used for in JavaScript?

a) To store unique values of any type
b) To create a collection of key-value pairs
c) To perform mathematical operations on arrays
d) To sort the elements in an array

Answer:

a) To store unique values of any type

Explanation:

The Set object in JavaScript allows you to store unique values of any type, whether primitive values or object references. A value in a Set may only occur once, making it useful for filtering duplicates.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top