Underscore.js _.negate() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Function

Definition

Returns a new negated version of a predicate function (official Underscore docs). Stable Function helper — not deprecated.

Pass the required arguments shown below. Underscore function helpers usually return a new function — check timing and call-count behavior carefully.

Syntax

Call _.negate. Start with this line.

Underscore
_.negate(predicate)
CallWhat it does
_.negate(predicate)Primary signature.
_.negate(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.negate(predicate)

Parameters

ParameterDescription
predicateRequired. Function to invert

Return Value

Return ValueDescription
*New function → always boolean

Underscore.js Examples

Example 1 — negate(Boolean)

Official docs pattern — find the first falsy value.

Underscore
var isFalsy = _.negate(Boolean);

_.find([-2, -1, 0, 1, 2], isFalsy);
// → 0
Try It Yourself

How It Works

  1. Boolean(x) is truthy for non-zero numbers.
  2. Negate. isFalsy is true only for falsy inputs.
  3. Find. Walks until 0 matches.
  4. Reuse. Same helper works with filter or every.

Example 2 — Opposite of isEven

Reuse one predicate instead of writing two.

Underscore
var isEven = function (n) {
  return n % 2 === 0;
};
var isOdd = _.negate(isEven);

isEven(4);  // → true
isOdd(4);   // → false
isOdd(3);   // → true
Try It Yourself

How It Works

  1. One source of truth. Only isEven defines the rule.
  2. Flip. _.negate builds isOdd.
  3. Same args. Both take a number n.
  4. Boolean out. Negated calls always return true/false.

Example 3 — filter with Negate

Keep values that fail the original test.

Underscore
var isEven = function (n) { return n % 2 === 0; };

_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
// → [1, 3, 5]
Try It Yourself

How It Works

  1. Predicate. isEven describes what to drop conceptually.
  2. Negate for filter. Filter keeps where the negated test is true.
  3. Odds remain. Evens fail isOdd and are removed.
  4. Readable. You still name the original rule once.

Example 4 — negate vs reject

Same list, same idea — two APIs, one result.

Underscore
var isEven = function (n) { return n % 2 === 0; };
var nums = [1, 2, 3, 4, 5, 6];

_.filter(nums, _.negate(isEven));  // → [1, 3, 5]
_.reject(nums, isEven);            // → [1, 3, 5]
Try It Yourself

How It Works

  1. Same halves. Both keep odds here.
  2. negate. Builds a reusable opposite predicate.
  3. reject. Collection helper for “keep failures” directly.
  4. Pick. Need the flipped test elsewhere? Prefer negate.

Browser & Runtime Support

_.negate ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.negate()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.negate Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]). Native alternative: (...args) => !pred(...args).

Frequently Asked Questions

_.negate(predicate) returns a new function that is the logical opposite of the predicate — truthy results become false, falsy results become true.
The negated function forwards every argument (and this) to the original predicate, then returns !result.
Reuse one test for both sides. Given isEven, _.negate(isEven) is isOdd — handy with _.filter, _.find, and friends.
_.negate builds an opposite predicate. _.reject is a collection method that keeps failing items. _.filter(list, _.negate(fn)) matches _.reject(list, fn).
Yes. It uses the ! operator, so the result is always true or false.
No. It is a stable Underscore Function helper.

Next: _.compose()

Combine functions so the rightmost runs first.

_.compose() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful