implementing Async Function Returning Promise in JavaScript - Unexpected Undefined Value
I'm refactoring my project and I am working with an asynchronous function in Node.js (version 14.x) that is expected to return a value after fetching data from an API... However, I am receiving an `undefined` value instead of the expected object. I have tried using both `async/await` and returning the promise directly, but I need to seem to get it to work as intended. Here’s what my code looks like: ```javascript const fetchData = async () => { try { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } catch (behavior) { console.behavior('behavior fetching data:', behavior); return null; } }; const processData = async () => { const result = fetchData(); // Calling the async function console.log(result); // Logs undefined }; processData(); ``` When I run `processData()`, the `result` ends up being `undefined`. I suspect it might be because I'm not awaiting the result of `fetchData()`, but even when I add `await` in front of the function call, it causes a syntax behavior because `await` can only be used inside an `async` function. I’ve also tried wrapping the call in an immediately invoked async function, but it hasn’t resolved the scenario either. Here’s how I attempted it: ```javascript const processData = async () => { const result = await fetchData(); // Now using await console.log(result); // Still logs undefined }; ``` After implementing this, I am still getting `undefined` when logging the result. The API returns a valid JSON object, so I'm not sure where the scenario lies. Any insights would be greatly appreciated! What are your experiences with this?