<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ScribbleTons</title>
    <description>The latest articles on DEV Community by ScribbleTons (@scribbletons).</description>
    <link>https://dev.to/scribbletons</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F502769%2F20ccdbe2-c96a-4df0-8f73-af8fb4191091.png</url>
      <title>DEV Community: ScribbleTons</title>
      <link>https://dev.to/scribbletons</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scribbletons"/>
    <language>en</language>
    <item>
      <title>Javascript Promise</title>
      <dc:creator>ScribbleTons</dc:creator>
      <pubDate>Thu, 05 Nov 2020 12:30:20 +0000</pubDate>
      <link>https://dev.to/scribbletons/javascript-promise-2fgj</link>
      <guid>https://dev.to/scribbletons/javascript-promise-2fgj</guid>
      <description>&lt;p&gt;Below here is a pseudo-code for javascript promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve,reject) =&amp;gt; {
if(condition is true){
resolve("Retrieve data from database");
}else{
reject("An error occured");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As in life promises, something happens when a promise is fulfilled. You can achieve that with these lines of codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*
When the resolve parameter of the promise constructor is resolved (processed and returns true) we can use 'then' property of Promise class to fulfill our promise.
*/
myPromise.then(res =&amp;gt; { 
// do something with res data
});

//Similarly

/*
When the resolve parameter of the promise constructor is rejected due to some  (processed and returns false) we can use 'catch' property of Promise class to fulfill our promise but this time catching the error.
*/

myPromise.catch(error =&amp;gt; {
//do something when promise is not resolved or display error
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading my first post on dev.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
