I have a problem with my Javascript code. It causes an error when using it.
async function request() {
let res = await fetch('https://jsonplaceholder.typicode.com/posts/1') .then(data => data.json());
return data;
}
The return function is causing a “not defined” error.
main.js:4 data is not defined
I am trying to get a response from an API to use in my project but I am unable to get the response.
I expected the function to return the data so I can process the data in my project.