In code1, it outputs undefined as expected. However code2 outputs the array already with the "hello" pushed inside. I don't understand why it didn't run the code in order.
function drawChart(chart) {
console.log(chartData) //code1
var chartData = [];
console.log(chartData) //code2
chartData.push("hello")
}