JavaScript

Map basics in JavaScript

JavaScriptMapMap basicsbeginner

What this snippet does

Unlike plain objects, Maps accept any value as a key (including objects and numbers) and maintain insertion order.

Expected output

Alice
a number key
3
true
name => Alice
42 => a number key
true => a boolean key

Why practise typing this

Typing map code builds muscle memory for the symbols and indentation JavaScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More JavaScript practice

Browse all JavaScript snippets →