I loaded a json object using d3.json and assigning the loaded json file to a global variable but when I print the global variable to the console it returns undefined, but when i type in the global variable in the chrome console it returns what I need it to. Essentially, I am just looking to load the json object be able to use it outside the d3.json function. This seems like a relatively simple task but I am a js/d3 newby so any help is greatly appreciated!
Thanks!
Code is provided below
<script type = "text/javascript" source='https://d3js.org/d3.v4.min.js'>
var gapminder;
d3.json("D3_jsondata.json", function(data){
gapminder = data;
});
//above prints in console when i type in gapminder
console.log(gapminder);//prints as 'undefined' in Chrome's console
</script>