Answers for "try catch with await javascript"

1

try catch async await

async function getData() {
    try {
        const response = await fetch('https://jsonplaceholder.typicode.com/todos/1')
        const data = await response.json();
      	const { userId, id, title, completed } = data;
      	console.log(userId, id, title, completed);
    } catch(err) {
      alert(err)
    }
}
getData();
Posted by: Guest on January-04-2022
-1

await and catch javascript

var response = await promisedFunction().catch((err) => { console.error(err); });
// response will be undefined if the promise is rejected
// this will work instead of using try...catch...
Posted by: Guest on May-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language