Web APIs

Listener signal option

Try the free JavaScript compiler

Associates listener removal with an AbortSignal. Already aborted signals do not register the listener.

Formal Syntax & Structure

javascript syntaxjavascript
target.addEventListener(type, callback, { signal })

Parameters & Attributes

NameTypeDescription
typestringEvent type.
callbackfunction | EventListener objectListener.
signalAbortSignalListener lifetime signal.

Working Example

Example Snippetjavascript
const b=document.createElement("button"),c=new AbortController();let n=0;b.addEventListener("click",()=>n++,{signal:c.signal});b.click();c.abort();b.click();console.log(n,c.signal.aborted);
JavaScript Reference