Friday, September 19, 2025
HomeLanguagesJavascriptUnderscore.js _.isWeakSet() Function

Underscore.js _.isWeakSet() Function

Underscore.js is a JavaScript library that makes operations on arrays, string, objects much easier and handy.
he _.isWeakSet() function is used to check whether the given object is JavaScript weakset or not. When linking the underscore.js CDN, the “_” is attached to the browser as global variable.

Syntax :

_.isWeakSet( object );

Parameters:

  • object: It is any JavaScript object such as array, string, maps, set etc.

Return Value: It returns the boolean value. If the set is a weak set it returns true otherwise returns false.

Example 1: When a weak set is given it returns true.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
  
    <script src=
    </script>
</head>
  
<body>
    <script>
  
        // Creating a weak set using
        // constructor
        var obj = new WeakSet();
  
        // Using the _.weakSet() function
        var isWeakSet = _.isWeakSet(obj);
        console.log(isWeakSet)
  
        // If the given object is weakset 
        // it prints the object is weak set.
        if (isWeakSet)
            console.log(`The ${obj} is the 
                    WeakSet of Javascript.`)
        else
            console.log(`The ${obj} is not 
                the WeakSet of Javascript.`)
    </script>
</body>
  
</html>


Output:

Example 2: When an array is given the output is false.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
  
    <script src=
    </script>
</head>
  
<body>
    <script>
  
        // Creating a array of size 
        // 2 using constructor
        var obj = new Array(2);
  
        // Filling value 10in the array
        obj.fill(10)
  
        // Using the _.weakSet() function
        var isWeakSet = _.isWeakSet(obj);
        console.log(isWeakSet)
  
        // If the given object is weakset 
        // it prints the object is weak set
        if (isWeakSet)
            console.log(`The ${obj} is the
                WeakSet of Javascript.`)
        else
            console.log(`The ${obj} is not 
                the WeakSet of Javascript.`)
    </script>
</body>
  
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6666 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS