Accepted answer

This is due to the asynchronous nature of javascript. The blocks of code you write do not get evaluated "in order" as you might expect. Basically, anything that uses the d3.csv call HAS to be within that block:

d3.csv("epochStats.csv", function(d) {
        maxEpochs = d.length;
        // anything else that uses the value of maxEpochs, or reads the file data, etc....
console.log(maxEpochs);  <-- This could be evaluated before the above csv block.

Related Query

More Query from same tag