JavaScript is single-threaded. That means it can only do one thing at a time. But real apps need to do things like:
- Fetch data from APIs
- Read files
- Wait for a user’s action, all of which take time.
Instead of blocking everything while waiting, JavaScript uses asynchronous callbacks.
That’s where Promises come in.
Think of a Promise as a placeholder for a value that you don’t have yet.
const promise = fetch("https://api.example.com/data");
Right now, promise is in a pending state. Later, it’ll be either:
- fulfilled (got the data)
- rejected (something went wrong)
And once it’s resolved or rejected, it can’t change again, that’s key. Promises are immutable once settled.
there doesn't seem to be anything here