Method chaining calls several methods on the same object in sequence. Each call passes an updated object to the next, keeping code concise and readable. section 1.2.5 section 1.4
The assembly-line analogy
A car assembly line adds a hood, wheels, tires, and lights in order: let car = new Car().putOnHood().putOnWheels().putOnTires().putOnLights(); Each method receives the updated car, and call order matters. section 1.2.5
In D3, chaining can select every div, append paragraphs, set a class and text, append spans, and apply bold styling without storing every intermediate selection. section 1.2.5
d3.selectAll("div")
.append("p")
.attr("class", "my-class")
.text("Wow")
.append("span")
.text("Even More Wow")
.style("font-weight", "900");
Read the indentation as a visual sequence: each method continues operating on the current selection, while nested calls make the resulting DOM structure easier to follow. section 1.2.5


