stevenberry2001
stevenberry2001 Jan 4, 2026 β€’ 6 views

JavaScript Promises Example Code: Fetching and Handling Data

Hey everyone! πŸ‘‹ Let's dive into JavaScript Promises with some practical examples. I've put together a quick study guide and a practice quiz to help you master fetching and handling data using Promises. Good luck! πŸ€
πŸ’» Computer Science & Technology

1 Answers

βœ… Best Answer
User Avatar
gregory_jones Jan 3, 2026

πŸ“š Quick Study Guide

  • ⏱️ Promises are objects representing the eventual completion (or failure) of an asynchronous operation.
  • πŸ”‘ A Promise can be in one of three states: pending, fulfilled, or rejected.
  • βœ… .then() is used to handle the fulfilled state of a Promise.
  • ❌ .catch() is used to handle the rejected state of a Promise.
  • πŸ”— .finally() is executed after the Promise is either fulfilled or rejected, regardless of the outcome.
  • πŸ“‘ The fetch() function is commonly used to make network requests and returns a Promise.
  • βš™οΈ Async/Await is syntactic sugar built on top of Promises, making asynchronous code easier to read and write.

πŸ§ͺ Practice Quiz

  1. Which of the following is NOT a state of a JavaScript Promise?
    1. Pending
    2. Fulfilled
    3. Rejected
    4. Running
  2. What method is used to handle the successful resolution of a Promise?
    1. .catch()
    2. .finally()
    3. .then()
    4. .reject()
  3. Which method is always executed regardless of whether the Promise is fulfilled or rejected?
    1. .then()
    2. .catch()
    3. .finally()
    4. .resolve()
  4. What does the fetch() function return?
    1. A string
    2. An object
    3. A Promise
    4. An array
  5. How do you handle errors when using async/await?
    1. Using .catch()
    2. Using try...catch blocks
    3. Using .finally()
    4. Errors are automatically handled
  6. What is the purpose of Promise.all()?
    1. To handle a single Promise
    2. To execute Promises in sequence
    3. To execute multiple Promises in parallel and resolve when all are fulfilled
    4. To reject all Promises
  7. Which of the following is the correct way to chain Promises?
    1. promise1.then(promise2).then(promise3)
    2. promise1.then().promise2.then().promise3
    3. promise1.then(promise2.then(promise3))
    4. promise1.then().then(promise2).then().then(promise3)
Click to see Answers
  1. D
  2. C
  3. C
  4. C
  5. B
  6. C
  7. A

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! πŸš€