AbortController in JavaScript
From the Async JavaScript cheat sheet · Abort & Error Handling · verified Jul 2026
AbortController
Cancel ongoing asynchronous operations like fetch requests or long-running tasks
javascript
// Basic abort
const controller = new AbortController();
const signal = controller.signal;
fetch('/api/data', { signal })
.catch(err => {
if (err.name === 'AbortError') {
console.log('Aborted');
}
});
// Abort after timeout
setTimeout(() => controller.abort(), 5000);
// Multiple operations
const controller = new AbortController();
Promise.all([
fetch('/api/1', { signal: controller.signal }),
fetch('/api/2', { signal: controller.signal })
]);
controller.abort(); // Cancels all💡 Allows you to cancel fetch requests and other async operations
⚡ Prevents unnecessary work when user navigates away
✅ Essential for cleaning up long-running operations
🔄 Can be reused by creating new controller instances