Table of contents
1.
Introduction
2.
Why This Function is Used
3.
Syntax, Parameter and Return Value
3.1.
Syntax: 
3.2.
Parameters:
3.3.
Return Value:
4.
Examples 
4.1.
Throttling Scroll Event Handler:
4.2.
Throttling a Resize Event Handler:
4.3.
Throttling Button Clicks:
4.4.
Rate-Limiting API Calls:
5.
Frequently Asked Questions 
5.1.
What is the difference between throttling and debouncing?
5.2.
Can the throttle interval be changed after creation?
5.3.
Does _.throttle() affect the original function?
6.
Conclusion
Last Updated: Aug 13, 2025
Easy

Lodash _.throttle() Method

Author Riya Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In web development, managing the rate at which a function can be executed is crucial, especially for events that can fire at a high frequency, such as scrolling, resizing, or key pressing. Lodash provides a solution for this with the _.throttle() method. 

Lodash _.throttle() Method

This function creates a throttled version of a function that only allows the function to be called at most once in a specified time frame. This is particularly useful for optimizing performance and resource usage.

Why This Function is Used

The _.throttle() function is used to control how often a function can be executed, irrespective of how many times it is triggered. This technique is beneficial for rate-limiting events that occur more frequently than needed, preventing performance issues such as sluggish user interfaces or overloaded servers. Throttling ensures that the function is executed in a controlled manner, optimizing efficiency while maintaining functionality.

Syntax, Parameter and Return Value

Syntax: 

_.throttle(func, [wait=0], [options={}])

Parameters:

  • func (Function): The function to throttle.
     
  • [wait=0] (number): The number of milliseconds to throttle invocations.
     
  • [options={}] (Object): The options object.
     
  • leading (boolean): Specify invoking on the leading edge of the timeout.
     
  • trailing (boolean): Specify invoking on the trailing edge of the timeout.

Return Value:

 (Function) - Returns the new throttled function.

Examples 

Throttling Scroll Event Handler:

var _ = require('lodash');
function onScroll() {
  console.log('Scrolled!');
}
var throttledScroll = _.throttle(onScroll, 200);
window.addEventListener('scroll', throttledScroll);
You can also try this code with Online Javascript Compiler
Run Code


// 'onScroll' will be called at most every 200ms during scrolling.

Demonstrates using _.throttle() to optimize a scroll event handler.

Throttling a Resize Event Handler:

function onResize() {
  console.log('Window resized');
}
var throttledResize = _.throttle(onResize, 250);
window.addEventListener('resize', throttledResize);
You can also try this code with Online Javascript Compiler
Run Code


// 'onResize' will be called at most every 250ms during window resizing.

Shows throttling a resize event handler to improve performance.

Throttling Button Clicks:

function handleClick() {
  console.log('Button clicked');
}
var throttledClick = _.throttle(handleClick, 1000);
document.getElementById('myButton').addEventListener('click', throttledClick);
You can also try this code with Online Javascript Compiler
Run Code


// Prevents multiple rapid clicks from triggering the handler more than once every second.

An example of using _.throttle() to prevent rapid repeated clicks.

Rate-Limiting API Calls:

function fetchData() {
  console.log('Fetching data');
  // API call logic
}
var throttledFetch = _.throttle(fetchData, 5000);
// Usage in a context where frequent triggers are possible
throttledFetch(); // 'fetchData' is called, subsequent calls within 5 seconds are ignored.
You can also try this code with Online Javascript Compiler
Run Code


Demonstrates throttling API call function to prevent excessive requests.

Frequently Asked Questions 

What is the difference between throttling and debouncing?

Throttling limits the function execution to once every specified time interval, whereas debouncing delays the function execution until a certain period of inactivity.

Can the throttle interval be changed after creation?

Once a throttled function is created, the interval is fixed. To change the interval, you would need to create a new throttled function.

Does _.throttle() affect the original function?

No, _.throttle() does not modify the original function. It creates a new function that limits the rate of the original function's execution.

Conclusion

Lodash's _.throttle() method is a valuable tool for controlling the execution rate of functions, especially in response to high-frequency events. It helps optimize performance and resource usage by preventing excessive or unnecessary executions of functions.

You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. 

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Live masterclass