Promises, async/await, arrow functions, and other modern ES6+ JavaScript features.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a Promise in JavaScript?
Show answer
An object representing the eventual completion or failure of an asynchronous operation and its resulting value.
- What are the three states a Promise can be in?
Show answer
Pending, fulfilled (resolved), or rejected.
- How do you create a new Promise?
Show answer
Use the Promise constructor: new Promise((resolve, reject) => { ... })
- What does the .then() method return?
Show answer
A new Promise that resolves with the return value of the callback.
- How do you handle Promise rejection with .catch()?
Show answer
.catch(error => { ... }) runs if the Promise rejects, and receives the rejection reason.
- What does .finally() do?
Show answer
Runs code after a Promise settles, whether fulfilled or rejected, and returns a new Promise.
- What does Promise.all() do?
Show answer
Takes an array of Promises and returns a single Promise that resolves when all Promises resolve, or rejects if any reject.
- What does Promise.race() do?
Show answer
Takes an array of Promises and returns a Promise that resolves or rejects with the result of the first to settle.
- What does Promise.resolve() do?
Show answer
Returns a Promise that is already fulfilled with the given value.
- What does Promise.reject() do?
Show answer
Returns a Promise that is already rejected with the given reason.
- What does the async keyword do?
Show answer
Marks a function as asynchronous and makes it always return a Promise.
- What does the await keyword do?
Show answer
Pauses execution of an async function until a Promise settles and returns the resolved value.
- What does an async function always return?
Show answer
A Promise, even if the function returns a plain value.
- How do you handle errors in an async function?
Show answer
Use try/catch: try { ... } catch (error) { ... }
- Can you await multiple Promises sequentially in an async function?
Show answer
Yes, each await pauses execution until that Promise resolves before moving to the next.