score:7

Accepted answer

When this is called the first time, there's no SVG and therefore the .enter() selection will contain the data passed to it. On subsequent calls, the .enter() selection will be empty and therefore nothing new added.

Concerning the specific questions:

  • .selectAll() returns an array which can then be matched to the array passed to .data().
  • .empty() could be used, but it's not necessary -- if the selection is empty, nothing happens. Checking .empty() would add an if statement and have exactly the same effect.
  • Yes. Have a look this tutorial for example for some more detail on selections.

Related Query