CKTIS / JavaScript
Map.prototype.get: read a value by key
The get method returns the value stored under a matching Map key, or undefined when no such entry exists.
Version: ECMAScript 2015 onward; example target: Node.js 24.22.2
Syntax
map.get(key)map.get(key) looks up a key without type coercion and does not modify the Map or entry order. For a found key it returns the exact stored value, including the same object reference; for a missing key it returns undefined.
Keys use SameValueZero: NaN matches NaN and -0 matches +0; objects match only by reference identity. Because an existing entry can deliberately contain undefined, the get result alone cannot distinguish it from absence—use map.has(key) when that distinction matters.
The receiver must have Map internal data; a plain object, Set, or unhandled Proxy as this throws TypeError. The method has been standard since ECMAScript 2015. get does not run a value factory or create an entry, so get-or-create logic must explicitly use has/set and account for undefined.
Examples
const key = { id: 7 };
const stored = { enabled: true };
const map = new Map([[key, stored], ["empty", undefined], [NaN, "not a number"]]);
console.log(map.get(key) === stored);
console.log(map.get({ id: 7 }));
console.log(map.get(NaN));
console.log(map.get("empty"), map.has("empty"));
console.log(map.get("missing"), map.has("missing"));
try {
Map.prototype.get.call({}, "x");
} catch (error) {
console.log(error instanceof TypeError);
}Result
true undefined not a number undefined true undefined false true