I'm confused about why a function call returns an object but I can't access its properties

In this notebook I have a function which returns an object by means of a fetch. If I merely run the function it successfully returns the object.

However, if I try to access that property, it returns as undefined. Can someone explain what’s going on there?

The function return the fetch Promise, which will resolve asynchronously when the resource is actually downloaded and processed. Add await before the promise and you will get its resolved value.

const cn = await colorName(hex);

2 Likes