AbortController

AbortController

Creates a new AbortController instance that can be used to abort one or more web requests as and when desired

Syntax

JavaScript
new AbortController()

Return Value

A new AbortController instance with a signal property

Examples

Basic Usage
const controller = new AbortController()
fetch('/api/data', { signal: controller.signal })
  .catch(() => console.log('Aborted'))
controller.abort()
Practical Example
function fetchWithTimeout(url: string, ms: number) {
  const controller = new AbortController()
  const timer = setTimeout(() => controller.abort(), ms)
  return fetch(url, { signal: controller.signal })
    .finally(() => clearTimeout(timer))
}
Advanced Usage
const controller = new AbortController()
const { signal } = controller

window.addEventListener('resize', () => console.log('resize'), { signal })
window.addEventListener('scroll', () => console.log('scroll'), { signal })

// Remove all listeners at once:
controller.abort()

Understanding AbortController

The AbortController method in JavaScript creates a new AbortController instance that can be used to abort one or more web requests as and when desired. It belongs to the AbortController object and is one of the most widely used methods for working with abortcontroller values in modern JavaScript and TypeScript applications.

The method signature is new AbortController(). When called, it returns a new abortcontroller instance with a signal property. Understanding when and how to use AbortController() helps you write more expressive, readable code.

Common use cases for AbortController include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-abortsignal, event-addeventlistener, event-removeeventlistener, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for AbortController is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More AbortController Methods

Other methods in the AbortController object

Related Tools

More AbortController Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.