Node.js | util.types.isWeakMap() Method

The util.types.isWeakMap() 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.isWeakMap() method is used to determine whether the value is a built-in WeakMap instance or not.

Syntax:



util.types.isWeakMap( value )

Parameters: This method accepts a single parameter 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 WeakMap, otherwise it returns false.

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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

false
false
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the 
// util.types.isWeakMap() method 
   
// Using require to access util module 
const util = require('util');
   
// Creating a Boolean Object
const a = new Boolean(true);
   
// Creating a Boolean Object
const b = new Boolean(false);
   
// A boolean type variable
const c = new WeakMap();
   
// Using util.types.isWeakMap() method
console.log(util.types.isWeakMap(a));
   
// Using util.types.isWeakMap() method
console.log(util.types.isWeakMap(b));
   
// Using util.types.isWeakMap() method
console.log(util.types.isWeakMap(c));

chevron_right


Output:

false
false
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_isweakmap_value



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.