let groupedWishlistProducts;
(async function () {
groupedWishlistProducts = await fetchGroupedWishlistProducts();
console.log(groupedWishlistProducts); // logs returned value properly
})();
console.log(groupedWishlistProducts); // logs undefined
Why is groupedWishlistProducts
undefined on global, even if I have initialized in global scope?
It's undefined because you havn't assigned anything to it (yet).
The order that things get executed is:
await
, the IIFE now returns to the outer code.