← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

_.debounce()

Creates a debounced version of a function that only runs after a pause in calls — ideal for search inputs and resize handlers.

import debounce from 'lodash/debounce';

const onSearch = debounce((query) => {
  fetch(`/api/search?q=${query}`);
}, 300);

input.addEventListener('input', (e) => onSearch(e.target.value));
  • Delays execution until `wait` ms have passed with no new calls
  • Supports { leading, trailing } options for fine control
  • Prefer this over hand-rolled debounce for production code — it's battle-tested