Fearless • 23d
Day 10/21 – JavaScript: Callback, Promise & Async/Await Today I learned how JavaScript handles asynchronous tasks like API calls, file loading, or timers. ⚡ 🔹 Callback – a function passed into another function function fetchData(cb) { setTimeout(() => cb("Data received!"), 1000); } fetchData(msg => console.log(msg)); 🔹 Promise – cleaner way to handle async let data = new Promise((res) => { setTimeout(() => res("Promise resolved!"), 1000); }); data.then(msg => console.log(msg)); 🔹 Async/Await – modern & readable syntax async function getData() { let result = await data; console.log(result); } getData(); 👉 Callback = nesting 👉 Promise = chaining 👉 Async/Await = clean & readable This is the heart of modern JS development 🚀 #21DayJavaScript #JavaScript #WebDevelopment #CodingJourney #LearnInPublic
Full-time Freelancer... • 1y
Most Javascript Questions Asked in Interview | PART 2 1. What is difference between a for loop and for Each loop Ans: A for loop is traditional loop that uses a counter variable to iterate over an array. ForEach loop is a method that iterate over a
See MoreDownload the medial app to read full posts, comements and news.