I suspect this is very trivial but I have this code:
var latestMth;
d3.csv("data/blah.csv", function(rows) {
    x = rows.map(function(d) {
        return parseDate(d.dt)
    });
    latestMth = formatDateOutputMTH(d3.max(d3.values(x)));
});
...
...
.text("Month is " + latestMth);
It works ok displaying "Month is Mar17".
I've attempted to make the above a function but the result now comes through as "Month is undefined". Why is this happening:
var latestMth = function() {
    d3.csv("data/blah.csv", function(rows) {
        x = rows.map(function(d) {
            return parseDate(d.dt)
        });
        return formatDateOutputMTH(d3.max(d3.values(x)));
    });
}
...
...
.text("Month is " + latestMth());
 
    