• 10 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 4/2/20

Use asynchronous programming

Log in or subscribe for free to enjoy all this course has to offer!

Evaluated skills

  • build and send AJAX requests
  • handle AJAX response data
  • use async/await
  • handle errors
  • Question 1

    Which of the following correctly handles a promise?

    • myPromise.try(
      (data) => {
      console.log(data);
      }
      ).catch(
      (error) => {
      console.log(error);
      }
      );
    • myPromise.then(
      (data) => {
      console.log(data);
      }
      ).catch(
      (error) => {
      console.log(error);
      }
      );
    • myPromise.then(
      (data) => {
      console.log(data);
      }
      ).error(
      (error) => {
      console.log(error);
      }
      );
    • myPromise.resolve(
      (data) => {
      console.log(data);
      }
      ).reject(
      (error) => {
      console.log(error);
      }
      );
  • Question 2

    Which of the following describes the three states of a promise?

      • Promise is started
      • Promise is pending
      • Promise is resolved
      • Promise is implemented
      • Promise is resolved
      • Promise is complete
      • Promise is pending
      • Promise is resolved
      • Promise is rejected
      • Promise is resolved
      • Promise is rejected
      • Promise is complete
  • Question 3

    Which of the following correctly creates a function which returns a promise?

    • function makeMeAPromise() {
      return new Promise((resolve, reject) => {
      // Do some stuff here
      if (success) {
      resolve(successData);
      }
      else {
      reject(errorData);
      }
      });
      }

       

    • function makeMeAPromise() {
      return new Promise(resolve, reject) => {
      // Do some stuff here
      if (success) {
      resolve(successData);
      }
      else {
      reject(errorData);
      }
      };
      }
    • function makeMeAPromise() {
      return new Promise((resolve, reject) => {
      // Do some stuff here
      success.then(data).catch(error);
      });
      }
    • function makeMeAPromise() {
      return new Promise((resolve, reject) => {
      // Do some stuff here
      if (success) {
      return successData
      }
      else {
      return error;
      }
      });
      }