Underscore.js _.throttle() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Function

Definition

Creates a throttled version of a function that, when invoked repeatedly, only actually calls the original at most once every wait milliseconds — useful for rate-limiting fast events (official Underscore docs). 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 _.throttle. Start with this line.

Underscore
_.throttle(fn, wait, [options])
CallWhat it does
_.throttle(fn, wait, [options])Primary signature.
_.throttle(...)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
_.throttle(fn, wait, [options])

Parameters

ParameterDescription
functionRequired. Function to rate-limit
waitRequired. Minimum ms between runs
options.leadingOptional. Run on first call (default true)
options.trailingOptional. Run once after the window (default true)

Return Value

Return ValueDescription
*The value returned by _.throttle().

Underscore.js Examples

Example 1 — Basic Throttle

Rapid calls: one leading run, then a trailing run after wait.

Underscore
var count = 0;
var bump = _.throttle(function () {
  count++;
}, 400);

bump(); bump(); bump(); bump();
// count becomes 1 immediately, then 2 after ~400ms
Try It Yourself

How It Works

  1. First call. Leading edge runs right away → count = 1.
  2. More calls. Inside the wait window they are coalesced.
  3. Trailing. One more run fires when the window ends.
  4. Result. Four calls → two real executions (default options).

Example 2 — leading: false

Skip the immediate call; only the trailing edge runs.

Underscore
var log = [];
var save = _.throttle(function () {
  log.push("saved");
}, 400, { leading: false });

save(); save(); save();
// log stays [] until ~400ms, then ["saved"]
Try It Yourself

How It Works

  1. No leading. First call does not run the body.
  2. Window. Further calls refresh the trailing schedule.
  3. After wait. One trailing run executes.
  4. Use case. Prefer “final update after activity,” still on a throttle clock.

Example 3 — trailing: false

Only the leading call runs; no final catch-up.

Underscore
var log = [];
var ping = _.throttle(function () {
  log.push("ping");
}, 400, { trailing: false });

ping(); ping(); ping();
// log → ["ping"]  (no second run later)
Try It Yourself

How It Works

  1. Leading only. First call runs immediately.
  2. No trailing. Extra calls inside the window are dropped.
  3. Next window. A new leading run can happen after wait.
  4. Use case. Cheap “sample now,” ignore intermediate noise.

Example 4 — cancel() a Trailing Call

Clear a pending trailing invocation during teardown.

Underscore
var log = [];
var tick = _.throttle(function () {
  log.push("tick");
}, 400);

tick();          // leading → ["tick"]
tick();          // schedules trailing
tick.cancel();   // clears trailing
// log stays ["tick"] after wait
Try It Yourself

How It Works

  1. Leading. First tick() runs.
  2. Second call. Would schedule a trailing run.
  3. Cancel. Pending timer is cleared.
  4. Teardown. Useful when leaving a page or removing a listener.

Browser & Runtime Support

_.throttle ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.throttle()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded. Relies on timers (setTimeout).

100% With Underscore 1.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
_.throttle Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]). Native alternative: a timestamp + setTimeout wrapper, or requestAnimationFrame for paint-tied updates.

Frequently Asked Questions

_.throttle(function, wait, [options]) returns a version of the function that runs the original at most once every wait milliseconds — ideal for scroll, resize, and mousemove.
Throttle fires on a steady schedule while events keep coming. Debounce waits for a quiet gap, then runs once. Use throttle for continuous updates; debounce for settled actions like search.
By default both are on: run immediately (leading) and once more at the end of the wait (trailing). Pass {leading: false} or {trailing: false} to disable one edge. Do not set both to false.
Yes. The throttled function has .cancel() to clear a waiting trailing invocation.
The result of the most recent actual invocation of the original function — which may be from an earlier call within the window.
No. It is a stable Underscore Function helper.

Next: _.debounce()

Wait until calls settle, then run the function once.

_.debounce() →

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