Lodash _.isWeakMap() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is classified as a WeakMap object. Part of Lodash Lang since 4.3.0 (stable — not deprecated).

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.isWeakMap. Start with this line.

Lodash
_.isWeakMap(value)
CallWhat it does
_.isWeakMap(value)Primary signature.

Prefer import isWeakMap from "lodash/isWeakMap" when you want a smaller bundle.

Library declarations
Lodash
_.isWeakMap(value)

Parameters

ParameterDescription
valueRequired. The value to check

Return Value

Return ValueDescription
*true if WeakMap, else false

Lodash Examples

Example 1 — Official: new WeakMap

A real WeakMap instance is classified as a WeakMap.

Lodash
_.isWeakMap(new WeakMap);
// → true
Try It Yourself

How It Works

  1. Input. Official sample: new WeakMap (empty WeakMap).
  2. Brand. Engines tag it as [object WeakMap].
  3. Result. true — it is a WeakMap.
  4. Note. Emptiness does not matter; type does.

Example 2 — Official: new Map

Map is a different built-in — not a WeakMap.

Lodash
_.isWeakMap(new Map);
// → false
Try It Yourself

How It Works

  1. Input. Official sample: new Map.
  2. Different type. Brand is [object Map].
  3. Result. false.
  4. Related. Use _.isMap for Maps.

Example 3 — WeakMap With Entries

Populated WeakMaps still pass — contents are irrelevant.

Lodash
var key = {};
var wm = new WeakMap();
wm.set(key, "meta");

_.isWeakMap(wm);
// → true

_.isWeakMap(new WeakMap());
// → true
Try It Yourself

How It Works

  1. Key. WeakMap keys must be objects (primitives throw).
  2. Set. Store metadata keyed by that object.
  3. Check. _.isWeakMap(wm) looks at type, not entries.
  4. Empty too. new WeakMap() also returns true.

Example 4 — Plain Object Is Not a WeakMap

Objects and WeakMaps both store keys, but only WeakMap instances pass.

Lodash
_.isWeakMap({ get: function () {}, set: function () {} }); // → false
_.isWeakMap(Object.create(null));                         // → false
_.isWeakMap(new WeakMap());                                // → true
Try It Yourself

How It Works

  1. Duck type. Methods named get/set do not make a WeakMap.
  2. Null proto. Object.create(null) also fails.
  3. Real WeakMap. Built with new WeakMap() → true.
  4. Related. Use _.isPlainObject for {}.

Example 5 — WeakSet, Set, and Null

Other collections and nullish values are not WeakMaps.

Lodash
_.isWeakMap(new WeakSet()); // → false
_.isWeakMap(new Set([1]));   // → false
_.isWeakMap(null);           // → false
_.isWeakMap(undefined);      // → false
Try It Yourself

How It Works

  1. WeakSet. Weak membership set — use _.isWeakSet.
  2. Set. Strong unique values — use _.isSet.
  3. Nullish. null / undefined fail cleanly.
  4. Rule. Only values branded as WeakMap pass.

Browser & Runtime Support

_.isWeakMap is a Lodash Lang helper (available since 4.3.0, stable in 4.x). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. The host must also provide the ES WeakMap built-in (all evergreen engines do).

✓ Stable · Lodash 4.3.0+

_.isWeakMap()

Available in [email protected] full builds and the lodash/isWeakMap modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x + WeakMap
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.isWeakMap Lodash 4.3.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import isWeakMap from "lodash/isWeakMap" for smaller builds. Native alternative: value instanceof WeakMap (note iframe/realm caveats).

Frequently Asked Questions

_.isWeakMap(value) returns true if value is classified as a WeakMap object, otherwise false. Map, WeakSet, plain objects, and Sets all return false.
Map is a different built-in type with its own brand ([object Map]). Lodash exposes _.isMap for that check.
WeakMap holds keys weakly (entries can be GC’d when the key is unreachable), rejects primitive keys, and is not iterable — no .size, .keys(), or for…of.
Yes. _.isWeakMap(new WeakMap()) is true whether it has entries or not — the check is about type, not contents.
No. Duck-typed objects are not WeakMaps. Lodash looks for a real WeakMap classification, not method names.
Use import isWeakMap from "lodash/isWeakMap" or require("lodash/isWeakMap"). Full build: import _ from "lodash" then _.isWeakMap.

Next: _.isWeakSet()

Check whether a value is classified as a WeakSet.

_.isWeakSet() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful