[X]

Every Key Is A String

luljs still works

Use objects as keys and they all collide into one.

In 2026: Still works. A plain object turns every key into a string. So obj[true] and obj["true"] are the same slot, obj[1] and obj["1"] collide, and any object used as a key becomes "[object Object]", so two different objects overwrite each other. Use a Map when you need real keys.

Where it came from: Plain object keys are coerced to strings, so non-string keys collide; MDN's property accessors page covers the conversion. MDN

<script>
var cache = {};
cache[{ id: 1 }] = "first";
cache[{ id: 2 }] = "second";
document.write('<p>Stored under two different objects. <code>cache[{ id: 1 }]</code> is <b>' + cache[{id:1}] + '</b></p>');
document.write('<p>Both became the key <b>"[object Object]"</b>, so the second overwrote the first.</p>');
document.write('<p><code>Object.keys(cache)</code> is <b>' + JSON.stringify(Object.keys(cache)) + '</b></p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›