iterator[Symbol.dispose]() implements the disposable protocol for iterators. On Iterator.prototype, it simply calls the iterator's return() method when that method exists, so cleanup can run early.
Language using declarations call this for you at the end of a block. In everyday try-it code you can call iterator[Symbol.dispose]() yourself, or call return() directly on a generator — both close the iterator when return is present.
Remember
iterator[Symbol.dispose]()
calls return() if it exists
used by: using / await using
generators: finally { ... } runs on close
you can also call iterator.return()
returns undefined
Syntax
Call it with square brackets on the symbol. Most cleanup examples work by showing that return() runs.
// Explicit Resource Management (newer)
Iterator.prototype[Symbol.dispose]()
// (no parameters)
// effect : calls this.return() if it is a function
// returns: undefined
Parameters
Parameter
Description
(none)
This method takes no parameters. Call it as iterator[Symbol.dispose]().
Return Value
Return Value
Description
undefined
Nothing useful is returned. The point is the side effect: closing the iterator so cleanup can run.
JavaScript Examples
Example 1 — Call Dispose on a Generator
Start a generator, read one value, then call [Symbol.dispose]() so the finally block runs.
The Try It page first checks that iterator[Symbol.dispose]() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Read one value.next() yields 1 and pauses inside the generator.
Dispose early.[Symbol.dispose]() calls return(), which runs the finally block and prints cleaned up.
Iterator is finished. Another next() reports done: true.
Example 2 — Dispose Calls return() on a Custom Iterator
Build a tiny iterator with a return() method and show that dispose closes it.
The Try It page first checks that iterator[Symbol.dispose]() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Custom iterator. It has next() and return(), plus a closed flag.
Use Iterator.prototype. Setting the prototype gives it the shared [Symbol.dispose] method.
Dispose closes it. Dispose calls return(), which logs and sets closed to true.
Example 3 — Feature-Detect Symbol.dispose
Check that the symbol and the prototype method exist before you call them.
The Try It page first checks that iterator[Symbol.dispose]() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Check the symbol. Older engines may not define Symbol.dispose at all.
Check the method. Confirm Iterator.prototype[Symbol.dispose] is a function.
Only then dispose. When both exist, dispose closes the generator and prints closed.
Compatibility
Browser & Runtime Support
Iterator.prototype[Symbol.dispose]() comes with the Explicit Resource Management proposal (using / await using). Support is still rolling out across engines.
✓ Newer · Explicit Resource Management
iterator[Symbol.dispose]()
Supported in Chrome 134+, Edge 134+, Firefox 141+, Safari 26+, Opera 119+ and Node.js 24+. Internet Explorer never got it.
RecentStandard since
Google Chrome134+ · Desktop & Mobile
Full support
Microsoft Edge134+ · Chromium based
Full support
Mozilla Firefox141+ · Desktop & Mobile
Full support
Apple Safari26+ · macOS & iOS
Full support
Opera119+ · Chromium based
Full support
Samsung InternetRecent · Android
Supported
Android WebView134+ · Chromium based
Supported
Node.js24+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
iterator[Symbol.dispose]()Recent engines
Bottom line: Feature-detect Symbol.dispose and the using syntax. Calling iterator.return() by hand is the classic way to close an iterator early.
Frequently Asked Questions
It closes the iterator for cleanup. On Iterator.prototype it calls return() when that method exists, then returns undefined.
No for learning. using calls dispose for you where the syntax is supported. You can also call iterator[Symbol.dispose]() or iterator.return() by hand.
Use square brackets with the symbol: iterator[Symbol.dispose](). Do not write iterator.Symbol.dispose() or quote the name as a normal string key.
Then dispose has nothing useful to call and cleanup is a no-op. Generators always provide return(), which runs finally blocks.
Check typeof Symbol.dispose !== "undefined" and typeof Iterator.prototype[Symbol.dispose] === "function" before calling it.