Introduction to Promise & its Properties in Javascript

$$/$$

In the next video, you’ll get a brief introduction from Sakshi using an analogy for promises in JavaScript, which is the concept that you’ll be learning about in all the segments related to promises.

SDE 6.6.2 - B2 - video 08
Video Player is loading.
Current Time 0:00
Duration 0:00
Loaded: 0%
Stream Type LIVE
Remaining Time 0:00
 
1x
  • Chapters
  • descriptions off, selected
  • subtitles off, selected
      $$/$$

      In the next video, you’ll learn from Srishti what a promise is and what role it plays in the asynchronous programming.

      SDE_B02_6.6.4_Ver 03_Video 27
      Video Player is loading.
      Current Time 0:00
      Duration 0:00
      Loaded: 0%
      Stream Type LIVE
      Remaining Time 0:00
       
      1x
      • Chapters
      • descriptions off, selected
      • subtitles off, selected
          $$/$$

          In the last video, you learned the following facts:
           

          1.      There are two types of code in asynchronous programming:

          • Producer Code: The code that produces some result
          • Consumer Code: The code that consumes the result produced by the producer code

          2.      A promise is an object which makes the result produced by the producer code available to the consumer code, thus linking them together.
           

          3.      The producer code is contained inside the promise object.
           

          4.     The producer code, which is inside the promise object, contains resolve & reject callbacks.
           

          5.      The producer code is executed as soon as the promise object is created. You do not need to explicitly call the producer code.
           

          You also learned the following syntax of defining a promise object:


          Syntax of a Promise:

          let promiseObj = new Promise((resolve, reject) => {
              // producer code
          });
          

           

          Now that you’ve got an idea about what a promise is, you’ll learn from Srishti about the properties of a promise object in the next video.

          SDE_B02_6.6.4_Ver 03_Video 28
          Video Player is loading.
          Current Time 0:00
          Duration 0:00
          Loaded: 0%
          Stream Type LIVE
          Remaining Time 0:00
           
          1x
          • Chapters
          • descriptions off, selected
          • subtitles off, selected
              $$/$$

              In the last video, you learned the following facts:
               

              1.  The internal properties of an object are the ones which cannot be accessed directly or manipulated. Also, the internal properties are enclosed within double square brackets [[]].
               

              2.  A promise object consists of two internal properties:

              • PromiseStatus
              • PromiseValue

              3.  When a promise object is created, the [[PromiseStatus]] property is initialized with ‘pending’ and the [[PromiseValue]] property is initialized with undefined.