So, if you keep variables around that point to selections (such as circle, above), you’ll probably want to reselect after adding or removing elements. The enter, update and exit selections are computed by the data operator, and don’t change when you append or remove elements-at least until you call selectAll again. The exit selection is the opposite of the enter selection: it contains all elements for which there is no corresponding data. You can select nodes and remove them, but more commonly, you’ll use the exit selection to let D3 determine which elements are exiting the stage.
Sometimes you have the opposite problem from creation: you have too many existing elements, and you want to remove them. This technique of plugging in reusable functions to compute attribute values is used extensively in D3, particularly in conjunction with scales and shapes.
Similarly, we can plug in Math.sqrt to set the radius attribute as the square root of the associated data. The built-in String method, for example, is a shorthand way of using JavaScript’s default string conversion to compute the attribute value from the associated data. As you can see, the code is made even smaller using built-in JavaScript functions, rather than defining anonymous ones.