FlashKeepers

JavaScript · JavaScript · College and University

JavaScript Async Programming and ES6+ Features

Promises, async/await, arrow functions, and other modern ES6+ JavaScript features.

About this set

40 basic cards for JavaScript JavaScript. It opens with "What is a Promise in JavaScript?" and "What are the three states a Promise can be in?". More College and University decks are listed below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a Promise in JavaScript?
Show answerAn 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 answerPending, fulfilled (resolved), or rejected.
How do you create a new Promise?
Show answerUse the Promise constructor: new Promise((resolve, reject) => { ... })
What does the .then() method return?
Show answerA 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 answerRuns code after a Promise settles, whether fulfilled or rejected, and returns a new Promise.
What does Promise.all() do?
Show answerTakes 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 answerTakes 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 answerReturns a Promise that is already fulfilled with the given value.
What does Promise.reject() do?
Show answerReturns a Promise that is already rejected with the given reason.
What does the async keyword do?
Show answerMarks a function as asynchronous and makes it always return a Promise.
What does the await keyword do?
Show answerPauses execution of an async function until a Promise settles and returns the resolved value.
What does an async function always return?
Show answerA Promise, even if the function returns a plain value.
How do you handle errors in an async function?
Show answerUse try/catch: try { ... } catch (error) { ... }
Can you await multiple Promises sequentially in an async function?
Show answerYes, each await pauses execution until that Promise resolves before moving to the next.

25 more cards in the app

Study this set free