Глобальные переменные js ошибка
Есть код, в котором я создаю переменную price, но не могу ее использовать ниже, так как получаю ошибку Cannot access 'price' before initialization, что сделано не так?
async function getCart() {
var price = 0;
fetch(base_api_path + '/cart/getAllOrders', {
method: 'GET'
})
.then(res => res.json())
.then(res => {
res.forEach(income => {
price += income.price;
....
})
})
}