Lodash _.debounce() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that delays invoking func until after wait milliseconds have passed since the last call. Great for resize, search typing, and click spam. Includes cancel and flush. Part of Lodash 4.x Function (since 0.1.0).

Pass the required arguments shown below. Most helpers return a new function you call later.

Syntax

Call _.debounce. Start with this line.

Lodash
_.debounce(func, [wait=0], [options={}])
CallWhat it does
_.debounce(func, [wait=0], [options={}])Primary signature.
_.debounce(func)Wrap or transform a function.

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

Library declarations
Lodash
_.debounce(func, [wait=0], [options={}])

Parameters

ParameterDescription
funcRequired. Function to delay
waitOptional. Quiet-time delay in ms (default 0)
options.leadingOptional. Invoke on the start of a burst (default false)
options.trailingOptional. Invoke after quiet time (default true)
options.maxWaitOptional. Maximum delay before a forced invoke

Return Value

Return ValueDescription
*Debounced function with cancel / flush

Lodash Examples

Example 1 — Default Trailing Debounce

Many rapid calls collapse into one run after quiet time.

Lodash
var runs = 0;
var save = _.debounce(function () {
  runs += 1;
}, 120);

save();
save();
save();

// after ~120ms of quiet time → runs === 1
Try It Yourself

How It Works

  1. Burst. Three calls arrive inside the wait window.
  2. Reset. Each call restarts the 120 ms timer.
  3. Trailing. After quiet time, func runs once.
  4. Use. Same idea as official resize debouncing.

Example 2 — Leading Edge (Official Click Style)

Run immediately, ignore the rest of the burst.

Lodash
var runs = 0;
var send = _.debounce(function () {
  runs += 1;
}, 300, { leading: true, trailing: false });

send();
send();
send();

// runs === 1 right away; no trailing call later
Try It Yourself

How It Works

  1. Leading. First call in a burst invokes func immediately.
  2. Trailing off. Later quiet-time call is skipped.
  3. Spam safe. Extra clicks in the window do nothing.
  4. Docs. Matches the official sendMail click pattern.

Example 3 — Cancel a Pending Call

Drop a scheduled trailing invocation (e.g. on navigation).

Lodash
var runs = 0;
var log = _.debounce(function () {
  runs += 1;
}, 200);

log();
log.cancel();

// after wait → runs still 0
Try It Yourself

How It Works

  1. Schedule. log() starts a trailing timer.
  2. Cancel. log.cancel() clears that timer.
  3. Result. func never runs.
  4. Docs. Same idea as cancelling on popstate.

Example 4 — Flush a Pending Call

Force the pending trailing invoke to run now.

Lodash
var runs = 0;
var log = _.debounce(function () {
  runs += 1;
}, 500);

log();
log.flush();

// runs === 1 immediately (does not wait 500ms)
Try It Yourself

How It Works

  1. Pending. log() schedules a trailing call.
  2. Flush. Runs that pending call right away.
  3. Return. flush() returns the result of func when applicable.
  4. Use. Handy on form submit before navigation.

Example 5 — maxWait (Official Stream Style)

Guarantee a call even when events never fully stop.

Lodash
var runs = 0;
var batchLog = _.debounce(function () {
  runs += 1;
}, 250, { maxWait: 1000 });

// continuous calls every 100ms for 1.2s
// → func still runs (at least) because of maxWait

// EventSource / stream pattern from the docs:
// source.onmessage = batchLog;
Try It Yourself

How It Works

  1. Problem. Without pauses, trailing debounce may never fire.
  2. maxWait. Caps how long func can be delayed.
  3. Docs. Same idea as batchLog on a message stream.
  4. vs throttle. maxWait still “waits for quiet” when quiet exists.

Browser & Runtime Support

_.debounce is a Lodash 4.x Function helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Uses timers under the hood (setTimeout); not a native language feature.

✓ Stable · Lodash 0.1+

_.debounce()

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

100% With Lodash 4.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
_.debounce Lodash 0.1+

Bottom line: Safe for production once Lodash is loaded. Prefer import debounce from "lodash/debounce" for smaller builds. Cancel pending calls on page/component teardown.

Frequently Asked Questions

_.debounce(func, wait, options) returns a function that delays calling func until wait ms have passed since the last wrapper call. Rapid calls reset the timer.
cancel() clears a pending trailing call. flush() runs a pending trailing call immediately and returns its result.
leading runs at the start of a burst. trailing (default true) runs after the burst ends. If both are true, trailing only fires when there was more than one call in the wait window.
When events never fully pause (continuous streams). maxWait guarantees func still runs at least that often.
debounce waits for quiet time. throttle caps how often func runs during ongoing activity.
The last arguments passed to the debounced wrapper.

Next: _.defer()

Schedule a function to run after the current call stack.

_.defer() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful