Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

try catch js

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();
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #catch #js
ADD COMMENT
Topic
Name
9+9 =