JavaScript AsyncIterator

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

An async iterator implements next() returning a Promise of { value, done }. Async iterables expose Symbol.asyncIterator and are consumed with for await...of.

TopicSummary
basicscore AsyncIterator usage.

JavaScript Syntax

JavaScript
const asyncIterable = {
  [Symbol.asyncIterator]() {
    let i = 0;
    return {
      async next() {
        if (i >= 2) return { done: true, value: undefined };
        return { done: false, value: ++i };
      }
    };
  }
};
(async () => {
  for await (const n of asyncIterable) console.log(n);
})();
Try it Editor

How It Works

  1. Symbol.asyncIterator. Returns an async iterator.
  2. next(). Resolves to { value, done }.
  3. for await...of. Consumes values.

Examples

Example 1 — Quick demo

Core AsyncIterator idea.

JavaScript
const asyncIterable = {
  [Symbol.asyncIterator]() {
    let i = 0;
    return {
      async next() {
        if (i >= 2) return { done: true, value: undefined };
        return { done: false, value: ++i };
      }
    };
  }
};
(async () => {
  for await (const n of asyncIterable) console.log(n);
})();
Try it Editor

How It Works

  1. Symbol.asyncIterator. Returns an async iterator.
  2. next(). Resolves to { value, done }.
  3. for await...of. Consumes values.

Frequently Asked Questions

An async iterator implements next() returning a Promise of { value, done }. Async iterables expose Symbol.asyncIterator and are consumed with for await...of.
Open the basics page, then related topics linked from this hub.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful