Lodash _.stubTrue() Method

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll use Lodash’s _.stubTrue() as a named “always true” function—for predicates, mocks, and _.cond default branches.

01

Core Syntax

_.stubTrue()

02

Always true

Any args ignored.

03

Fn reference

_.stubTrue

04

Predicates

Filter / some.

05

vs constant

constant(true)

06

vs stubFalse

Opposite stub.

What Is _.stubTrue()?

_.stubTrue is a zero-argument function that always returns true. It belongs to Lodash’s stub helper family alongside _.stubFalse() and _.stubString(). Under the hood it is equivalent to _.constant(true).

💡
Beginner tip — function vs boolean

_.stubTrue() gives you the value true. _.stubTrue (no parentheses) is the function itself—pass it when Lodash or your code expects a predicate callback.

Use it when you need a readable, reusable “always passes” check—clearer than sprinkling () => true through cond tables and filter pipelines.

📝 Syntax

Invoke with no arguments (they are ignored anyway):

javascript
_.stubTrue()

Syntax Rules

  • _.stubTrue — function reference for predicates and callbacks.
  • _.stubTrue() — call once to get boolean true.
  • Ignores arguments_.stubTrue(1, "x", {}) still returns true.
  • Cond default — in _.cond, pair _.stubTrue with a fallback handler.
  • Primitive true — returns the boolean true, not 1 or "yes".
javascript
import stubTrue from "lodash/stubTrue";



stubTrue();

// true

⚡ Quick Reference

TaskCode patternNotes
Get true now_.stubTrue()Boolean value
Pass predicate_.filter(arr, _.stubTrue)Keep all items
Enabled checkconst ok = _.stubTrueFn reference
Mock validatorvalidate: _.stubTrueAlways valid
Equivalent_.constant(true)Same behavior
Default in cond_.stubTrueCatch-all pair
Returns
true

Boolean

Type
Function

Zero-arg

Args
Ignored

Always true

Category
Util

Stub

🧰 Parameters

_.stubTrue accepts no meaningful parameters—callers may pass args, but stubTrue ignores them:

arguments Ignored

Any values passed when stubTrue is used as a callback are discarded.

_.stubTrue(1, 2, 3)
return true

Always the boolean primitive true.

true
reference Pattern

Pass _.stubTrue without () to APIs expecting a function.

_.some(arr, _.stubTrue)
call once Pattern

Use _.stubTrue() when you need the value—not a callable function reference.

return _.stubTrue()

Need always-false instead? See _.stubFalse()—the opposite stub for fail predicates and empty filters.

Examples Gallery

Practical _.stubTrue() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Call stubTrue and confirm the result.

Example 1 — Basic call returns true

The simplest use—evaluate to boolean true.

javascript
console.log(_.stubTrue());

console.log(typeof _.stubTrue());

console.log(_.stubTrue() === true);

// true

// "boolean"

// true
Try It Yourself

How It Works

Same result as writing true directly—stubTrue names the intent in Lodash-heavy code.

Example 2 — Arguments are ignored

Whether called with zero or many args, the answer is always true.

javascript
console.log(_.stubTrue());

console.log(_.stubTrue("anything"));

console.log(_.stubTrue(99, { ok: false }));

// true, true, true
Try It Yourself

How It Works

Like _.constant(true), stubTrue never inspects callback arguments from _.filter or _.some.

📈 Practical Patterns

Predicates, enabled features, and test mocks.

Example 3 — Keep everything with _.stubTrue

Pass the function reference—every element passes the predicate.

javascript
const nums = [1, 2, 3, 4, 5];



console.log(_.filter(nums, _.stubTrue));

console.log(_.some(nums, _.stubTrue));

// [1, 2, 3, 4, 5]

// true
Try It Yourself

How It Works

Useful as a no-op filter stage or when you want every item while keeping pipeline structure intact.

Example 4 — Enabled feature gate (function reference)

Store the stub as a callable check—not _.stubTrue() which is just the boolean.

javascript
const isFeatureEnabled = _.stubTrue;



if (isFeatureEnabled()) {

  console.log("Feature on");

} else {

  console.log("Feature off");

}

// Feature on

How It Works

Old tutorials wrote const f = _.stubTrue() then f()—that throws because true is not callable. Assign _.stubTrue instead.

Example 5 — Mock validator that always passes

Pass stubTrue where a validation function is expected.

javascript
function submitForm(data, validate = _.stubTrue) {

  return validate(data);

}



console.log(submitForm({ name: "Ada" }));

// true — validation always passes

How It Works

Default parameter uses the function reference so callers can swap in a real validator later.

🚀 Beyond the Basics

stubTrue vs constant, arrow, and stubFalse.

Example 6 — stubTrue vs alternatives

Pick the right always-true tool—and know when stubFalse is the opposite.

javascript
console.log(_.stubTrue());

console.log(_.constant(true)());

console.log((() => true)());



console.log(_.stubTrue === _.constant(true)); // often true in Lodash



// cond default — stubTrue is the catch-all pair:

// _.cond([[_.stubTrue, () => "default"]])

// true, true, true

When to use which

stubTrue for always-pass predicates and cond catch-alls; stubFalse for never-pass filters; plain true when a function is not required.

🧠 How _.stubTrue() Works

1

Invoke stub

Call directly or pass _.stubTrue as a callback.

Call
2

Skip logic

No conditionals—implementation always yields true.

Evaluate
3

Ignore args

Elements, indexes, or user data passed by iteratees are unused.

Ignore
=

true

Boolean primitive—passes every truthiness check and filter predicate.

📝 Notes

  • _.stubTrue() returns true—do not call the result again as a function.
  • For callable enabled gates, assign const fn = _.stubTrue (reference).
  • Use stubTrue as the default branch in _.cond—not _.stubFalse.
  • Setting object fields with isAdmin: _.stubTrue() stores boolean true—same as true, not a function.
  • Equivalent to _.constant(true) for behavior; stubTrue is more readable in stub-family code.
  • Next in the series: _.times()—invoke iteratees n times.

Conclusion

_.stubTrue() is a small named helper for “always true”—whether you need a boolean now or a predicate callback that always passes. Pair it with the rest of the stub family for consistent functional style.

Remember the parentheses rule: reference for callbacks, call when you want the value. For catch-all _.cond branches, stubTrue is the idiomatic choice.

💡 Best Practices

✅ Do

  • Pass _.stubTrue to filter/some when everything should match
  • Use as a default validator that always passes in tests
  • Prefer stubTrue over () => true in Lodash cond/filter tables
  • Use _.stubTrue for cond default branches
  • Return true or _.stubTrue() directly when no callback is needed

❌ Don’t

  • Assign const f = _.stubTrue() then call f()
  • Use stubFalse as a cond catch-all—stubFalse is for fail predicates, not defaults
  • Expect stubTrue to return truthy non-booleans like 1 or "yes"
  • Put stubTrue in object literals expecting a function property without noticing ()
  • Confuse with _.noop—noop returns undefined, not true

Key Takeaways

Knowledge Unlocked

Five things to remember about _.stubTrue()

Use these points for always-true predicates and mocks.

5
Core concepts
🔄 02

Fn vs ()

Ref vs value.

Pitfall
03

Filter all

Predicate.

Usage
📝 04

constant

Same idea.

Related
🛠 05

stubFalse

Opposite.

Compare

❓ Frequently Asked Questions

_.stubTrue is a zero-argument function that always returns true. Call _.stubTrue() when you need the boolean true immediately, or pass _.stubTrue (no parentheses) when an API expects a function that always passes its check.
true is a value. _.stubTrue is a function—useful when something expects a callback or predicate. _.stubTrue() evaluates to true, same as calling the function once.
_.stubTrue is sugar for _.constant(true). Both always return true and ignore arguments. stubTrue reads clearer in Lodash stub/cond style code.
Pass _.stubTrue to _.filter, _.some, or _.cond handlers that want a function. Use _.stubTrue() when you need the boolean value right now—like return true or assign a flag. Do not call it then try to invoke the result as a function.
stubTrue always returns true—common as the default branch in _.cond and for keep-all filter predicates. stubFalse always returns false—useful for disabled checks or empty filter results.
Use it for always-pass predicates, _.cond default branches, test mocks that always succeed, and anywhere () => true reads well but you prefer a named Lodash helper.
Did you know?

Lodash pairs _.stubTrue with _.cond for default branches because it always passes—use _.stubFalse when you need the opposite: predicates that never pass, like empty filters or failed validation mocks.

Practice _.stubTrue() in the Live Editor

Try basic true returns, ignored arguments, and keep-all filter predicates.

Open Try It editor →

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.

6 people found this page helpful