I have a very simple question that someone who's much more experienced at JS will be able to answer in a couple of seconds.
I'm wondering why when I declare a variable (dataset1
) with the let
-keyword, I can't then reassign later. It's strange to me because I can modify dataset
within the scope of the promise...
let dataset = [];
d3.json("foo.json").then((data) => {
data.map((d) => {
d.date = parseDate(d.date);
d.adjclose = +d.adjclose;
dataset.push(d);
});
});
console.log(dataset); // prints out the parsed data
let dataset1;
d3.json("foo.json").then((data) => {
dataset1 = data.map((d) => {
d.date = parseDate(d.date);
d.adjclose = +d.adjclose
return d;
});
});
console.log(dataset1); // prints undefined... :(