JavaScript 2025 · Promises and fetch
Debounce a function
Run a function only after calls stop for a moment, for example on search input.
function debounce(fn, delay) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};
}
Official JavaScript 2025 documentation
More promises and fetch commands
- Fetch JSON
- POST JSON
- Time out a request
- Handle errors in async code
- Run promises in parallel
- Wait for all promises, whatever happens
All promises and fetch commands · JavaScript 2025 cheatsheet