curriculum/challenges/english/blocks/quiz-javascript-maps-and-sets/67358be1c7903489c0a7db78.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
What is a Set in JavaScript?
A data structure that allows duplicate values.
A data structure that only stores strings and numbers.
A collection that does not allow deletion of its elements.
A collection in which a value can only occur once.
Which of the following methods is available in Maps but not in Sets?
has()
clear()
values()
set()
What method is used to add elements to a Set?
.push()
.append()
.insert()
.add()
How do you check if a Set contains a certain value?
.contains()
.hasValue()
.find()
.has()
Which of these is a great use case for Sets?
Managing key-value pairs in a database.
Creating ordered lists of items.
Storing hierarchical data structures in the browser local storage.
Eliminating duplicates from an array.
What is a WeakSet in JavaScript?
A Set-like collection that only allows primitive data types.
A Set-like collection that allows duplicate values.
A Set-like collection that prevents values from being removed.
A Set-like collection that only stores objects.
What is one difference between a Set and a WeakSet?
A WeakSet can store any type of value, including numbers.
A Set does not allow duplicate values, but a WeakSet does.
A Set allows garbage collection, whereas a WeakSet does not.
A Set can hold any type of value, while a WeakSet only holds objects.
What is a Map in JavaScript?
A collection that only allows unique values.
A collection that can only use strings as keys.
A collection that does not allow deletion of its items.
A collection of key-value pairs of any type.
What method is used to insert key-value pairs into a Map?
.append()
.add()
.insert()
.set()
What will the following code output?
const myMap = new Map();
myMap.set('a', 1);
myMap.set('a', 2);
console.log(myMap.get('a'));
1
undefined
null
2
How does a Map differ from an Object in JavaScript?
A Map only allows numbers as keys.
Objects allow any type as keys, while Maps only allow strings.
Maps do not support iteration, while Objects do.
Maps allow any type of key, but Objects only allow strings and symbols.
How can you remove a key-value pair from a Map?
.remove()
.deleteKey()
.erase()
.delete()
What does the size property of a Map return?
The number of indexes in the Map.
The number of unique values in the Map.
The total memory used by the Map.
The number of key-value pairs in the Map.
What is a WeakMap in JavaScript?
A Map-like collection that allows primitive values as keys.
A Map-like collection that blocks the deletion of items.
A Map-like collection that automatically sorts its keys.
A Map-like collection with weak references to the keys.
What is one difference between a Map and a WeakMap?
A Map allows only primitive types as keys, whereas a WeakMap only allows objects.
A Map allows garbage collection, whereas a WeakMap does not.
A WeakMap allows duplicate keys, whereas a Map does not.
A Map is iterable, whereas a WeakMap is not.
Which of the following methods does NOT exist on a WeakMap?
.has()
.set()
.delete()
.size()
What will be the output of the following code?
const set = new Set([1, 2, 3]);
set.delete(2);
console.log(set.has(2));
true
undefined
2
false
How can you iterate over the values in a Set?
By using the .map() method.
By using the .reduce() method.
By using the .filter() method.
By using the .forEach() method.
Which two methods of Sets return a SetIterator that contains the values of a certain Set?
entries() and values()
forEach() and values()
has() and add()
keys() and values()
What will be the output of the following code?
const map = new Map([["a", 1], ["b", 2]]);
map.clear();
console.log(map.size);
2
1
undefined
0