Lodash _.stubTrue() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

This method returns true. Part of Lodash Util since 4.13.0 (stable — not deprecated).

Note: Pass the function reference (for example to _.times), not _.stubTrue(), unless you want the boolean immediately.

Syntax

Call _.stubTrue. Start with this line.

Lodash
_.stubTrue()
CallWhat it does
_.stubTrue()Primary signature.
_.stubTrue(...)Call the util helper.

Prefer import stubTrue from "lodash/stubTrue" when you want a smaller bundle.

Library declarations
Lodash
_.stubTrue()

Parameters

This method has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*Always true

Lodash Examples

Example 1 — Official: _.times

Invoke _.stubTrue twice and collect the results.

Lodash
_.times(2, _.stubTrue);
// → [true, true]
Try It Yourself

How It Works

  1. Pass reference. _.times receives _.stubTrue, not true.
  2. Index 0. Calls stubTrue(0) → true.
  3. Index 1. Calls stubTrue(1) → true.
  4. Array. Results are [true, true].

Example 2 — Direct Call

Calling the stub returns the boolean immediately.

Lodash
console.log(_.stubTrue());
// → true

console.log(typeof _.stubTrue);
// → "function"
Try It Yourself

How It Works

  1. Call. _.stubTrue() runs the function.
  2. Return. Always true.
  3. Type. _.stubTrue itself is a function.
  4. Rule. Use () for the value; omit () to pass the stub.

Example 3 — Arguments Are Ignored

Any inputs still yield true.

Lodash
console.log(_.stubTrue(0));
console.log(_.stubTrue('x', false));
console.log(_.stubTrue(null));
// → true
// → true
// → true
Try It Yourself

How It Works

  1. Inputs. Numbers, strings, and null are passed in.
  2. Ignore. The stub does not read them.
  3. Same result. Every call returns true.
  4. Use. Safe as a “always accept” predicate.

Example 4 — Default Branch in _.cond

End a cond table with _.stubTrue like else.

Lodash
var grade = _.cond([
  [function (n) { return n >= 90; }, _.constant('A')],
  [function (n) { return n >= 70; }, _.constant('B')],
  [_.stubTrue, _.constant('C')]
]);

console.log(grade(95)); // 'A'
console.log(grade(75)); // 'B'
console.log(grade(40)); // 'C'
Try It Yourself

How It Works

  1. Specific first. High scores match earlier pairs.
  2. Miss. 40 fails both range checks.
  3. Default. _.stubTrue is always truthy → runs last handler.
  4. Result. Returns 'C'.

Example 5 — stubTrue vs stubFalse

Opposite stubs for always-true and always-false.

Lodash
console.log(_.times(2, _.stubTrue));
// → [true, true]

console.log(_.times(2, _.stubFalse));
// → [false, false]

console.log(_.stubTrue() === _.constant(true)());
// → true
Try It Yourself

How It Works

  1. stubTrue. Fills an array with true.
  2. stubFalse. Fills an array with false.
  3. constant. _.constant(true)() equals _.stubTrue().
  4. Pick. Prefer stubs for booleans; constant for any value.

Browser & Runtime Support

_.stubTrue is a Lodash Util helper since 4.13.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash (4.13+).

✓ Stable · Lodash 4.13.0+

_.stubTrue()

Available in [email protected]+ full builds and the lodash/stubTrue modular import. Works in evergreen browsers and current Node LTS when a recent Lodash is installed.

100% With Lodash 4.13+
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
_.stubTrue Lodash 4.13.0+

Bottom line: Safe for production on Lodash 4.13+. Prefer import stubTrue from "lodash/stubTrue" for smaller bundles. Use it for default cond branches and simple always-true iteratees.

Frequently Asked Questions

_.stubTrue() is a function that always returns true. Official example: _.times(2, _.stubTrue) → [true, true].
It is a shared, named stub from Lodash—handy as a default predicate in _.cond, or as an iteratee for _.times, without writing a new arrow each time.
Yes. Any arguments are ignored; the return value is always true.
Both return true. _.constant(true) is a factory for any fixed value; _.stubTrue is a ready-made always-true function with no setup.
As the last pair’s predicate: [_.stubTrue, handler] acts like else / default because stubTrue is always truthy.
Use import stubTrue from "lodash/stubTrue" or require("lodash/stubTrue"). Full build: import _ from "lodash" then _.stubTrue.

Next: _.times()

Invoke an iteratee n times and collect the results.

_.times() tutorial →

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