CKTIS / JavaScript
Symbol.asyncIterator — the asynchronous iteration protocol
Symbol.asyncIterator is a built-in symbol identifying the method that supplies an object's async iterator. It lets for await...of retrieve successive values while awaiting the results of next().
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
Symbol.asyncIterator
object[Symbol.asyncIterator]()
async *[Symbol.asyncIterator]() { /* yield values */ }Symbol.asyncIterator is a well-known symbol used as a property key, not a function to call directly. The method object[Symbol.asyncIterator]() returns an async iterator—the iterator object itself, not a promise for an iterator. This mechanism has been part of ECMAScript since ECMAScript 2018 (ES2018); it is not a Web API.
An async iterable supplies this method, whereas an async iterator supplies next(), which returns a promise for a result object. An absent done property is treated the same as done: false. A result with done: true signals completion and can omit the value property. The syntax async *[Symbol.asyncIterator]() defines an async generator method, which handles this protocol automatically.
The for await...of loop first looks for Symbol.asyncIterator. If the method is absent or has the value null, it uses Symbol.iterator and adapts the synchronous iterator. Ordinary for...of does not use Symbol.asyncIterator. Do not declare the iterator factory as a plain async method: it would return a promise instead of an iterator.
In the example, each method call creates a fresh generator, and the loop collects values in order. Check syntax and symbol support in the target environment; neither the presence of Symbol.asyncIterator alone nor the repository's use of Node 24 proves browser compatibility.
Examples
const numbers = {
async *[Symbol.asyncIterator]() {
yield 1;
yield 2;
yield 3;
}
};
async function main() {
const values = [];
for await (const value of numbers) {
values.push(value);
}
console.log(values.join(', '));
}
main().catch(console.error);Result
1, 2, 3
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.