Back

Shubham

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

Reply
1

More like this

Recommendations from Medial

Shubham

Fearless • 14d

Day 11/21 – JavaScript API Calls 🌐 Today I explored how to fetch data from APIs in JavaScript using async/await. Copy code Javascript async function getUsers() { try { let response = await fetch("https://jsonplaceholder.typicode.com/users");

See More
Reply
2

Sagar gupta

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 More
Reply
3
10

Inayat Hasan

Software engineer • 1y

[This post has been deleted by the creator]

Reply
1
3

Shubham

Fearless • 29d

Day 05/21 – JavaScript Functions & Methods Today I explored one of the most powerful concepts in JavaScript: Functions & Methods. 🚀 🔹 Functions are blocks of code designed to perform a specific task. They help in reusability and make code cleaner

See More
Reply
1

Download the medial app to read full posts, comements and news.