Javascript Variable Scope

Javascript Variable Scope

Hello Guys, 

I am trying to get the value of the variable "mthitems" out the function defined to retrieve the record data and run the for loop as shown below. But somehow it does not return me any value for the variable in the console if I print the values outside of the function, but inside the function when i try to it does return the proper values.

Can someone help?

mtconfig = {
reportName: 'Match_Stats_View',
criteria: 'Parent_Season==' + ssitem.ID,
}
var mthtitems = '';
let mtdet = ZOHO.CREATOR.API.getAllRecords(mtconfig).then(function(mtrecords) {
var mtrecordArr = mtrecords.data;
mtrecordArr.forEach(mtitems => {
mthtitems += `<tr>
<td>${mtitems.Match_Name}</td>
<td>${mtitems.Points}</td>
<td>${mtitems.Fouls}</td>
<td>${mtitems.Rebounds}</td>
<td>${mtitems.Assists}</td>
<td>${mtitems.Steals}</td>
<td>${mtitems.Blocks}</td></tr>`
}) //match for loop
});
console.log('match'+mthtitems);