# displaying Generators

**URL:** <https://talk.observablehq.com/t/displaying-generators/10942>\
**Category:** Help\
**Created:** [October 27, 2026, 6:44pm UTC](https://talk.observablehq.com/t/displaying-generators/10942 "2026-10-27T18:44:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akrawitz](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/akrawitz/32/4375_2.png) [@akrawitz](https://talk.observablehq.com/u/akrawitz)\
**Post date:** [October 27, 2026, 6:44pm UTC](https://talk.observablehq.com/t/displaying-generators/10942/1 "2026-10-27T18:44:17Z")

</div>

For a cell evaluating to a typical value, as an _expression_ cell, its value gets displayed _implicitly_:

```javascript
html`count = 12`

```

If I want to assign it to a variable, then it will be a _program_ cell, and I need to use `display` to display it _explicitly_:

```javascript
const c = display(html`count = 12`);

```

For a cell evaluating to a Generator, as an _expression_ cell, it gets consumed and it’s value gets displayed _implicitly_:

```javascript
(async function*() {
  let c = 0;
  while (true) {
    yield html`c = ${c++}`;
    await Promises.delay(1000);
  }
})()

```

If I want to assign it to a variable, then it will be a _program_ cell, and… well, I don’t think I can display it in place without additional “machinery”:

```javascript
const counter = (async function*() {
  let c = 0;
  while (true) {
    yield html`c = ${c++}`;
    await Promises.delay(1000);
  }
})()

```

If I wrap the whole thing in `display`:

```javascript
const counter = display((async function*() {
  let c = 0;
  while (true) {
    yield html`c = ${c++}`;
    await Promises.delay(1000);
  }
})())

```

then I get `async Generator {}` as the displayed value.

If I push `display` inside the `yield`:

```javascript
const counter = (async function*() {
  let c = 0;
  while (true) {
    yield display(html`c = ${c++}`);
    await Promises.delay(1000);
  }
})()

```

then I get:

> c = 0c = 1c = 2c = 3c = 4c = 5c = 6c = 7

as the displayed value, with each `yield` adding a new value instead of replacing the old one.

It is true that I can add an _additional_ cell:

```javascript
counter

```

and it will _implicitly_ display the value of my generator. But that isn’t as clean and elegant as displaying the value in place.

Is this asymmetry between assigned and unassigned Generators (versus assigned and unassigned values) just baked into Observable 2.0?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [October 27, 2026, 7:08pm UTC](https://talk.observablehq.com/t/displaying-generators/10942/2 "2026-10-27T19:08:00Z")

</div>

It’s not so much whether the generator is assigned; it’s whether you’re looking at the value _within_ the cell versus _across_ cells (and of course you can only look at a value across cells if the value has been assigned a name).

The same principle applies to promises, which if displayed within a cell will show as `Promise {}`, but across cells you will see the implicitly awaited resolved value.

One of the design decisions for the upcoming automatic inspection of top-level variables work is whether `counter` above should show the yielded value (the value across cell boundaries) or the generator (the value within the declaring cell). I’d guess we want to show the former, which would be more consistent with what we show in the expression cell case, and hence you’d be able to name things without losing implicit inspection.
