Creates a debounced version of the function that postpones execution until after wait milliseconds have elapsed since the last invocation (official Underscore docs). Useful after input stops (search, resize, Markdown preview). Pass true for immediate to fire on the leading edge. Stable Function helper — not deprecated.
Pass the required arguments shown below. Underscore function helpers usually return a new function — check timing and call-count behavior carefully.
Syntax
Call _.debounce. Start with this line.
Underscore
_.debounce(function, wait, [immediate])
Call
What it does
_.debounce(function, wait, [immediate])
Primary signature.
_.debounce(...)
Call with the arguments your case needs.
Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.
Library declarations
Underscore
_.debounce(function, wait, [immediate])
Parameters
Parameter
Description
function
Required. Function to debounce
wait
Required. Quiet period in milliseconds
immediate
Optional. true → leading edge instead of trailing
Return Value
Return Value
Description
*
Debounced function (+ .cancel())
Underscore.js Examples
Example 1 — Trailing (Default)
Many rapid calls → one run after quiet, with the last args.
Underscore
var log = [];
var save = _.debounce(function (q) {
log.push(q);
}, 50);
save("a");
save("ab");
save("abc");
// after ~50ms of quiet: log → ["abc"]
_.debounce ships with Underscore.js (1.x). It uses timers (setTimeout / clearTimeout) and runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.debounce()
Available in [email protected] (UMD / ESM). Supports immediate and .cancel(). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.debounceUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.debounce(function, wait, [immediate]) returns a wrapper that postpones running until wait milliseconds have elapsed since the last invocation. Official use: _.debounce(calculateLayout, 300) on resize.
Debounce waits for a quiet period, then runs once. Throttle runs at most once per wait while events keep coming. Use debounce for 'after typing stops'; throttle for continuous scroll/move updates.
Pass true to fire on the leading edge (first call), then ignore further calls until wait ms of quiet. Useful for preventing double-submit clicks.
At the end of the wait, the function is called with the arguments from the most recent invocation of the debounced wrapper.
Yes. Call .cancel() on the debounced function to clear any scheduled trailing invocation.
In trailing mode the real call is async, so you usually ignore the sync return. In immediate mode the leading call’s return value is available.