score:4

yep, as the commenters have suggested, this is a syntax that's particular to observable. what you're seeing a cell that uses a block, as mentioned in the introduction to code.

how you can think of this relative to other javascript is that it's kind of like an iife, but with the added consideration that, if it references other cells, it automatically resolves them. so in vanilla javascript, this would be like:

chart = (() => {
    const svg = d3.select(dom.svg(width, height));

    const g = svg.append("g")
        .selectall("g")
        .data(bins)
        .join("g");

    // [...]

    return svg.node();
})()

in fact, that's roughly what they compile to. the particular syntax is that way because it's meant to be clear that it's code that runs when references change - see how observable runs for details on that. unlike an iife, a cell in observable might run multiple times, if something that it references, like a generator or promise, changes.


Related Query