Friday, October 17, 2025
HomeLanguagesJavascriptUnderscore.js _.negate() Function

Underscore.js _.negate() Function

Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc even without using any built-in objects.

The _.negate() function is an inbuilt function in Underscore.js library of JavaScript which is used to find a new negated version of the stated predicate function.

Syntax:

_.negate(predicate)

Parameters: It accepts a single parameters which is specified below:

  • predicate: It is the stated predicate function.

Return Value: This method returns a new negated version of the stated predicate function.

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body>
    <script>
        var isNaN = _.negate(Boolean);
          
        console.log(_.find(
            [3, -11, undefined, 41, 0], isNaN));
    </script>
</body>
  
</html>


Output:

undefined

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body>
    <script>
        function isCSportal(character) {
            return character === "neveropen";
        }
  
        var isNotCSportal = _.negate(isCSportal);
        console.log(isNotCSportal("neveropen"));
        console.log(isNotCSportal("GfG"));
    </script>
</body>
  
</html>


Output:

false
 true

Reference: https://underscorejs.org/#negate

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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS