Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Underscore.js _.negate() Function

  • Last Updated : 25 Nov, 2021

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.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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 === "GeeksforGeeks";
        }
  
        var isNotCSportal = _.negate(isCSportal);
        console.log(isNotCSportal("GeeksforGeeks"));
        console.log(isNotCSportal("GfG"));
    </script>
</body>
  
</html>

Output:

false
 true

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :