Lodash Throttle Leading False vs Trailing False

In the Lodash library, _.throttle limits the execution rate of a function over a specified wait period, with both leading and trailing options enabled by default. Setting leading: false prevents the throttled function from firing immediately on the first trigger, deferring execution until the wait period has passed. Conversely, setting trailing: false ensures the function executes immediately on the initial trigger but prevents it from executing once more at the end of the wait period if it was called again during that timeframe.

Default Throttle Behavior

By default, _.throttle(fn, wait, { leading: true, trailing: true }) monitors calls across fixed time windows:

Behavior with { leading: false }

When configured with { leading: false }, the initial call does not trigger immediate execution. Instead, the timer starts, and the function execution is delayed until the end of the wait window (the trailing edge).

Note: You cannot set both leading: false and trailing: false simultaneously, as this would result in the function never executing.

Behavior with { trailing: false }

When configured with { trailing: false }, the behavior shifts exclusively to the start of the throttling window:

Summary Comparison

Setting First Invocation Intermediate Invocations Post-Wait Execution
leading: false No execution Queues trailing run Executes once after wait
trailing: false Executes immediately Ignored No execution