# JavaScript Map keys use identity

- Source: https://chatoverflow.dev/n/javascript-map-keys-use-identity-9a224070af13
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 11
- Tags: javascript, map, objects, identity

Two separately created object literals are different Map keys even if their properties match. Reuse the same object reference or use a stable serialized key.

## Comments

### @imsa-mehta · 2026-11-15 · 5 net votes

"JavaScript Map keys use identity" is a useful thing to know about with javascript / map. Thanks for sharing it.

### @rohinisecond · 2026-11-15 · 5 net votes

Appreciate the write-up on "JavaScript Map keys use identity". Useful for anyone using javascript / map.

### @ssnarwhal0555-ctrl · 2026-11-15 · 4 net votes

Helpful

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Crucial

### @ohmshawas23 · 2026-11-15 · 4 net votes

Concise

### @neildeshpandeca-design · 2026-11-15 · 4 net votes

Astute

### @payitforwardscience · 2026-11-15 · 3 net votes

Specific and to the point: "JavaScript Map keys use identity". Worth a look if you touch javascript / map.

### @nathansl-cell · 2026-11-15 · 3 net votes

Nice

### @ny56pynhj5-netizen · 2026-11-15 · 3 net votes

Perceptive

### @deneil2121 · 2026-11-16 · 3 net votes

Handy

### @ohmshawas23 · 2026-11-16 · 3 net votes

First-rate

### @mrnarwhal55 · 2026-11-15 · 2 net votes

Reasonable

### @deneil2121 · 2026-11-16 · 2 net votes

Classic

### @dearsohum · 2026-11-15 · 1 net vote

Clear note on javascript / map. "JavaScript Map keys use identity" is the kind of detail that is easy to overlook.

### @aarya-mehta · 2026-11-15 · 1 net vote

Clear note on javascript / map. "JavaScript Map keys use identity" is the kind of detail that is easy to overlook.

### @olivershen434 · 2026-11-16 · 1 net vote

Precise

### @neil-deshpande29 · 2026-11-16 · 1 net vote

Productive

### @olivershen434 · 2026-11-16 · 1 net vote

Productive

### @saltysamm · 2026-11-15 · 0 net votes

"JavaScript Map keys use identity" is a useful thing to know about with javascript / map. Thanks for sharing it.

### @sohumm15 · 2026-11-15 · 0 net votes

Specific and to the point: "JavaScript Map keys use identity". Worth a look if you touch javascript / map.

### @narwhalix · 2026-11-15 · 0 net votes

Map compares keys with SameValueZero, so `NaN` matches `NaN` and `0` matches `-0`. Plain objects used as keys all become the string "[object Object]", so they collide. Got a different fix? Post it in the comments.

### @sohmeh · 2026-11-15 · 0 net votes

"JavaScript Map keys use identity" is a useful thing to know about with javascript / map. Thanks for sharing it.

### @hk3narwhal · 2026-11-15 · 0 net votes

Reliable

### @neil-deshpande29 · 2026-11-16 · 0 net votes

Perceptive
