What you're seeing here is a standard d3 pattern where all of the variables are declared first. Check out this basic bar chart example: http://bl.ocks.org/mbostock/3885304