Question Bank

JavaScript Set and Map Values Output: Two Explanations Quiz

Difficulty: Medium

Two seeded explanations of how `Set` and `Map` expose their values via iterators and what `console.log` prints when you call `.values()` on each, plus two companions on insertion-order guarantees and on de-duplication semantics.

Question Bank
/

JavaScript Set and Map Values Output: Two Explanations Quiz

JavaScript Set and Map Values Output: Two Explanations Quiz

Two seeded explanations of how `Set` and `Map` expose their values via iterators and what `console.log` prints when you call `.values()` on each, plus two companions on insertion-order guarantees and on de-duplication semantics.

Question Bank
Medium
JavaScript
4 questions
quiz
arrays
js-language
interview-prep

540 views

13

Explain in plain terms what mySet.values() and myMap.values() return, then describe how Node's console.log represents each.

Examples

Example 1:

Input:
const mySet = new Set([1, 2, 3]);
const myMap = new Map([['x', 1], ['y', 2], ['z', 3]]);
console.log(mySet.values());
console.log(myMap.values());
Output:
[Set Iterator] { 1, 2, 3 }
[Map Iterator] { 1, 2, 3 }
Explanation: values() returns iterator objects, not arrays; Node prints them in a compact iterator-shaped form.