• 10 heures
  • Moyenne

Ce cours est visible gratuitement en ligne.

course.header.alt.is_video

course.header.alt.is_certifying

J'ai tout compris !

Mis à jour le 02/04/2020

Use asynchronous programming

Compétences évaluées

  • 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;
              }
          });
      }
      
Et si vous obteniez un diplôme OpenClassrooms ?
  • Formations jusqu’à 100 % financées
  • Date de début flexible
  • Projets professionnalisants
  • Mentorat individuel
Trouvez la formation et le financement faits pour vous