MediumModern JS💻 Output Question

Map accepts any key type

💡

Hint

Map accepts any value as key. Object keys are always coerced to strings.

What does this output?

const map = new Map();
map.set('name', 'Alice');
map.set(42, 'answer');
map.set(true, 'yes');
console.log(map.size);
console.log(map.get(42));
console.log(map.has('missing'));

Correct Output

3
answer
false

Why this output?

Explanation: Map keys can be any type. size=3. get(42) retrieves by number key. has("missing") is false.

Key Insight: Map accepts any value as key. Object keys are always coerced to strings.

More Modern JS Output Questions

EasyDestructuring defaults apply only for undefinedEasyObject spread — later properties winMediumOptional chaining prevents TypeError on missing propertiesMediumNullish coalescing ?? vs OR ||

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz