Lodash _.stubString() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

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

Note: Arguments are ignored. Equivalent idea to _.constant(''), with a clearer name for empty-string stubs.

Syntax

Call _.stubString. Start with this line.

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

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

Library declarations
Lodash
_.stubString()

Parameters

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

Return Value

Return ValueDescription
*Always ''

Lodash Examples

Example 1 — Official: _.times + stubString

Build an array of empty strings.

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

How It Works

  1. Pass by reference. _.stubString — no trailing ().
  2. Invoke twice. _.times calls it for indexes 0 and 1.
  3. Each call. Returns ''.
  4. Collect. Result array is ['', ''].

Example 2 — Direct Call

Invoke the stub yourself when you need an empty string now.

Lodash
_.stubString();
// → ""

_.stubString().length;
// → 0
Try It Yourself

How It Works

  1. Call. Empty parentheses run the stub.
  2. Return. The empty string ''.
  3. Length. .length is 0.
  4. Use. Quick default for labels and template slots.

Example 3 — Arguments Are Ignored

Host APIs may pass indexes or values — the stub still returns ''.

Lodash
_.stubString("hello");
// → ""

_.stubString(1, 2, 3);
// → ""
Try It Yourself

How It Works

  1. Ignore input. Even "hello" does not pass through.
  2. Ignore extras. Multiple args still yield ''.
  3. Safe callback. Fits APIs that forward indexes or items.
  4. Contrast. Unlike _.identity, input never returns.

Example 4 — Placeholder Slots with join

Fill slots with empty strings, then join with a separator.

Lodash
_.times(3, _.stubString).join("-");
// → "--"
Try It Yourself

How It Works

  1. Fill. Three empty strings: ['', '', ''].
  2. Join. Separator "-" sits between empties.
  3. Result. "--" — two dashes, no text.
  4. Use. Skeleton placeholders before real values arrive.

Example 5 — stubString vs constant('')

Both return empty strings; naming differs.

Lodash
_.stubString();
// → ""

_.constant("")();
// → ""

_.times(2, _.constant(""));
// → ["", ""]
Try It Yourself

How It Works

  1. stubString. Named always-empty helper.
  2. constant(''). Same return via the general factory.
  3. times. Either works as an iteratee.
  4. Pick. Prefer stubString when intent is “empty string stub.”

Browser & Runtime Support

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

✓ Stable · Lodash 4.13.0+

_.stubString()

Available in [email protected] full builds and the lodash/stubString modular import. Works in evergreen browsers and current Node LTS when Lodash ≥ 4.13 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
_.stubString Lodash 4.13.0+

Bottom line: Safe for production once Lodash 4.13+ is loaded. Prefer import stubString from "lodash/stubString" for smaller bundles. Use it as a named always-empty-string callback.

Frequently Asked Questions

_.stubString() returns an empty string '' every time. Official: _.times(2, _.stubString) → ['', ''].
No. Arguments are ignored. _.stubString('hi') is still ''.
Same result for strings. stubString is a named util with nothing to configure. constant('') builds an equivalent function.
As a default empty-string callback, with _.times to fill an array of '', or anywhere an API expects a string-returning function.
Yes. Empty string is falsy in conditions and filters. That is normal JavaScript behavior, not a stubString quirk.
Use import stubString from "lodash/stubString" or require("lodash/stubString"). Full build: import _ from "lodash" then _.stubString.

Next: _.stubTrue()

Return true on every call — the opposite boolean stub.

_.stubTrue() 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