Lodash _.isWeakSet() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is classified as a WeakSet 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 _.isWeakSet. Start with this line.

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

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

Library declarations
Lodash
_.isWeakSet(value)

Parameters

ParameterDescription
valueRequired. The value to check

Return Value

Return ValueDescription
*true if WeakSet, else false

Lodash Examples

Example 1 — Official: new WeakSet

A real WeakSet instance is classified as a WeakSet.

Lodash
_.isWeakSet(new WeakSet);
// → true
Try It Yourself

How It Works

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

Example 2 — Official: new Set

Set is a different built-in — not a WeakSet.

Lodash
_.isWeakSet(new Set);
// → false
Try It Yourself

How It Works

  1. Input. Official sample: new Set.
  2. Different type. Brand is [object Set].
  3. Result. false.
  4. Related. Use _.isSet for Sets.

Example 3 — WeakSet With Members

Populated WeakSets still pass — contents are irrelevant.

Lodash
var obj = {};
var ws = new WeakSet();
ws.add(obj);

_.isWeakSet(ws);
// → true

_.isWeakSet(new WeakSet());
// → true
Try It Yourself

How It Works

  1. Member. WeakSet members must be objects (primitives throw).
  2. Add. Mark the object as seen / tagged.
  3. Check. _.isWeakSet(ws) looks at type, not members.
  4. Empty too. new WeakSet() also returns true.

Example 4 — Plain Object Is Not a WeakSet

Objects with add/has methods still fail the brand check.

Lodash
_.isWeakSet({ add: function () {}, has: function () {} }); // → false
_.isWeakSet(Object.create(null));                         // → false
_.isWeakSet(new WeakSet());                               // → true
Try It Yourself

How It Works

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

Example 5 — WeakMap, Array, and Null

Other collections and nullish values are not WeakSets.

Lodash
_.isWeakSet(new WeakMap()); // → false
_.isWeakSet([{}]);          // → false
_.isWeakSet(null);          // → false
_.isWeakSet(undefined);     // → false
Try It Yourself

How It Works

  1. WeakMap. Key/value store — use _.isWeakMap.
  2. Array. Indexed list of objects — not a WeakSet.
  3. Nullish. null / undefined fail cleanly.
  4. Rule. Only values branded as WeakSet pass.

Browser & Runtime Support

_.isWeakSet 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 WeakSet built-in (all evergreen engines do).

✓ Stable · Lodash 4.3.0+

_.isWeakSet()

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

100% With Lodash 4.x + WeakSet
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
_.isWeakSet Lodash 4.3.0+

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

Frequently Asked Questions

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

Next: _.lt()

Check whether a value is less than another.

_.lt() tutorial →

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