In this code , The main countries console.log( ) is always becoming null
but "countries in csv" console.log( ) is always turning out to be good. What is that I am missing here ? In the console , why am I am seeing that console.log("main countries:",cn) is being printed first rather than console.log("countries in csv")?
//in csv.js file :
var rpc_csv = function()
{
var countries = null;
d3.csv("data/rpc_stas.csv", function(rpc_data)
{
//rpc_data is an array of json objects containing the data in from the csv
//console.log("rpc_data:", rpc_data)
countries = rpc_data.columns;
console.log("countries in csv ", countries)
return countries;
});
return countries;
}
// in script.js file :
var cn = rpc_csv()
console.log("main contries:",cn);
<script src="https://d3js.org/d3.v4.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/d3.v4.js"></script>
<script type="text/javascript" src="js/underscore-min.js"> </script>
<script type="text/javascript" src="js/csv.js"></script>
</head>
<body>
<div id="ratiopercountry"></div>
<script src="js/script.js"></script>
</body>
</html>