What is a Promise in JavaScript?
Options
- A guaranteed value that is available right away
- An object for a value that arrives later, or an error (Correct option)
- A special type of loop that is used for async code
- A CSS animation that waits for events on the page
Answer
An object representing a value that will be available later (or an error), from an async operation like a network request
Why
Operations like fetch(url) take time. Instead of freezing the page, they immediately return a Promise: a placeholder for the future result.
A promise is pending, then becomes fulfilled (with a value) or rejected (with an error).
You handle it with .then(...) / .catch(...) or, more readably, with await inside an async function.
Remember
Promise = placeholder for a future result.