๐——๐—ฎ๐˜† ๐Ÿฎ๐Ÿด ๐—ผ๐—ณ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐— ๐—˜๐—ฅ๐—ก ๐—ฆ๐˜๐—ฎ๐—ฐ๐—ธ

I completed four weeks of consistent learning today.

I moved past callback hell. I mastered JavaScript Promises.

Callbacks make code hard to read when you nest them. Promises solve this problem. A promise is an object. It represents the result of an asynchronous task.

A promise has three states:

โ€ข Pending: The task is still running. โ€ข Fulfilled: The task finished successfully. โ€ข Rejected: The task failed.

You use two main methods to handle these states:

โ€ข .then(): This runs when the promise succeeds. โ€ข .catch(): This runs when the promise fails.

In real apps, you often consume promises from APIs.

The best part of today was learning promise chaining. You return a new promise inside a .then() block. You link the next .then() directly below it. This turns messy nested code into a clean vertical line.

Example:

getData(1) .then((res) => getData(2)) .then((res) => getData(3)) .then((res) => console.log("All data loaded!"));

This structure keeps your code readable and organized.

Source: https://dev.to/ali_hamza_589ec7b3eb6688d/day-28-of-learning-mern-stack-3h8m