Skip to content
Nicholas Berlette edited this page Jun 19, 2025 · 1 revision

@nick/is/map

isMap

Signature

function isMap<K = unknown, V = unknown>(it: unknown): it is Map<K, V>;

Checks if a given value is a Map instance. This is a more reliable check than it instanceof Map because it works across different realms, and it does not require the Map constructor to be the same as the one in the current environment that the code is running in.

It also is more strict than it instanceof Map, and does not consider any objects created via Object.create(Map.prototype) (or similar constructs) as valid Map instances, while they would pass the instanceof check.

Parameters
Name Info
it The value to check.
Returns

true if the value is a Map instance, false otherwise.

Category

Keyed Collections

Examples

import { isMap } from "jsr:@nick/is/map";

isMap(new Map()); // true
isMap(new WeakMap()); // false
isMap({}); // false
isMap(new Set()); // false
import { isMap } from "jsr:@nick/is/map";

const fakeMap = Object.create(Map.prototype);
console.log(isMap(fakeMap)); // false
console.log(fakeMap instanceof Map); // true (?!)

Clone this wiki locally