Lodash _.delay() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How to run callbacks after explicit wait times with _.delay.
  • How argument forwarding works.
  • How delay differs from defer and plain timers.
  • How to inspect return timer ids.

Prerequisites

Optional read: _.defer() and the Function hub.

  • Timers: know the basics of milliseconds and async callbacks.
  • Callback args: passing values into delayed functions.

Overview

_.delay(func, wait, ...args) schedules func after a chosen wait period. It forwards args and returns a timer id, giving a small wrapper around setTimeout.

Syntax

javascript
_.delay(func, wait, ...args)
  • func: function to run later.
  • wait: milliseconds before invocation.
  • args: optional values forwarded to func.
  • returns: timer id number.
1

Basic delayed call

Runs callback after a known wait.

javascript
import delay from "lodash/delay";

delay(() => console.log("later"), 400);
// logs after ~400ms
2

Pass arguments

Arguments after wait are provided to callback on execution.

javascript
import delay from "lodash/delay";

delay(function (text) {
  console.log(text);
}, 300, "later");
// "later"
3

Inspect timer id

Delay returns timer id values like setTimeout.

javascript
import delay from "lodash/delay";

const id = delay(() => {}, 100);
console.log(typeof id);
// "number"

📋 _.delay vs _.defer

HelperTimingUse case
_.delayCustom wait in msScheduled callbacks with explicit delay
_.deferNext tick styleRun after current synchronous stack

Pitfalls to avoid

Units

Milliseconds confusion

Wait values are ms, not seconds.

Lifecycle

Forgotten cleanup

Pending delayed work can fire after component teardown.

Coercion

Invalid waits

Non-numeric waits coerce to 0 and still defer asynchronously.

❓ FAQ

It invokes func after the specified wait milliseconds and forwards any additional arguments to func.
It returns a timer id number, similar to setTimeout.
delay accepts a custom wait duration; defer always schedules after the current stack with a tiny fixed delay.
Yes. A 0 wait still defers execution asynchronously to the timer queue.
Use delay for consistency when a codebase already uses Lodash wrappers and you want variadic arg forwarding in the same API style.

Summary

Did you know?

Lodash implements _.delay with baseDelay(func, toNumber(wait) || 0, args), so non-numeric waits coerce to 0 and still schedule asynchronously with passed arguments.

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