Bayu files the same pairs twice, in the object cabinet and on the Map wall: what becomes of a number key, an object key and the order they came in, in each?…
Why it matters
"Object or Map?" comes up every time you build a cache, a lookup table, or count frequencies. Pick wrong and keys collide because they become text, the order shifts because of number keys, or the prototype’s built-in keys sneak in.
The key idea
Objects for fixed-shape records, Maps for dynamic dictionaries
Common mistakes
Non-text keys in an object silently collide Numbers, booleans and objects are turned into text. Use a Map when the keys are not text.
JSON.stringify(map) returns just {} A Map’s contents are not properties. Convert with Object.fromEntries(map) first.
An object’s key order changes by itself once keys are numbers Whole-number keys are always sorted to the front, ascending. Need a sure insertion order? Use a Map.
Try it in this playground
File the keys 1 and '1' Cabinet o has one drawer, wall m has two boxes.
Use an object as a key In o it becomes the drawer '[object Object]'; m keeps it by identity.
Mix number and text keys Object.keys(o) comes out in a different order from arrival; m keeps it.
Send a Map to the head office JSON.stringify(m) is just {}: convert with Object.fromEntries(m) first.