Skip to content
Related Articles

Related Articles

Node.js | util.types.isWeakSet() Method
  • Last Updated : 21 Jan, 2020

The util.types.isWeakSet() method is an inbuilt application programming interface of util module which is primarily designed to support the needs of Node.js own internal APIs.

The util.types.isWeakSet() method is used to determine whether the value is a built-in WeakSet instance or not.

Syntax:

util.types.isWeakSet( value )

Parameters: This method accepts a single parameters value which holds any valid JavaScript data types like Boolean, Null, Number, Object, etc.

Return value: It returns a Boolean value i.e. returns true if it is an instance of built-in WeakSet, otherwise it returns false.



Below examples illustrate the use of util.types.isWeakSet() method in Node.js:

Example 1:




// Node.js program to demonstrate the 
// util.types.isWeakSet() method 
  
// Using require to access util module 
const util = require('util');
  
// Using util.types.isWeakSet() method
console.log(util.types.isWeakSet(true));
  
// Using util.types.isWeakSet() method
console.log(util.types.isWeakSet("set"));
  
// Using util.types.isWeakSet() method
console.log(util.types.isWeakSet(new WeakSet()));

Output:

false
false
true

Example 2:




// Node.js program to demonstrate the 
// util.types.isWeakSet() method 
  
// Using require to access util module 
const util = require('util');
  
// Creating a WeakSet Object
const a = new WeakSet();
  
// Add values
a.add(new Boolean(true));
  
// Creating a WeakSet Object
const b = new WeakSet();
  
// Using util.types.isWeakSet() method
console.log(util.types.isWeakSet(a));
  
// Using util.types.isWeakSet() method
console.log(util.types.isWeakSet(b));

Output:

true
true

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/dist/latest-v13.x/docs/api/util.html#util_util_types_isweakset_value

My Personal Notes arrow_drop_up
Recommended Articles
Page :