Question 23
Question
Answer
function fetchData(url, callback) { setTimeout(() => { if (Math.random() < 0.8) { // Simulate success callback(null, "Data fetched!"); } else { callback("Network error"); } }, 1000); } fetchData('https://example.com/api', (error, data) => { if (error) { console.error(error); } else { console.log(data); } });
Last updated