<?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: Ludo05</title>
    <description>The latest articles on DEV Community by Ludo05 (@lewis150193).</description>
    <link>https://dev.to/lewis150193</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%2F247050%2Faa22b6fc-c6e0-4a62-ad71-230896d72802.png</url>
      <title>DEV Community: Ludo05</title>
      <link>https://dev.to/lewis150193</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lewis150193"/>
    <language>en</language>
    <item>
      <title>What is a Promise?!?</title>
      <dc:creator>Ludo05</dc:creator>
      <pubDate>Tue, 29 Oct 2019 15:43:49 +0000</pubDate>
      <link>https://dev.to/lewis150193/what-is-a-promise-2o33</link>
      <guid>https://dev.to/lewis150193/what-is-a-promise-2o33</guid>
      <description>&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;Promises have had me head scratching for quite a while but now I feel I have a grasp of what they are and how to use them I thought why not create a post for others who may of felt the same. &lt;/p&gt;

&lt;h2&gt;
  
  
  The definition
&lt;/h2&gt;

&lt;p&gt;I will start with the definition given by Javascript MDN:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What I took from this is that it is very similar to how we think of a normal promise, someone promises to do something for you when he/she gets something from you.&lt;/p&gt;

&lt;p&gt;For instance I can promise to give you some data in turn of you giving me the location to find it. Now I can hold this promise if data is in the location you provided or reject if the data you asked for isn't at the provided &lt;br&gt;
location.&lt;/p&gt;

&lt;p&gt;Javascript promises work in a very similar way, they will return a &lt;code&gt;resolve&lt;/code&gt; or a &lt;code&gt;reject&lt;/code&gt;. The resolve will hold the information that you expect when from the function and the reject will usually hold the error or why the promises couldn't be held.&lt;/p&gt;

&lt;p&gt;Note: It is always good to know what type of data type you are expecting back from a promise.&lt;/p&gt;

&lt;p&gt;I will now show a simple promise which I have written up:&lt;/p&gt;

&lt;p&gt;This promise will resolve if I give the parameter name as 'Lewis' or reject if it is not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffkd4qugym8ldnxqi9yk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffkd4qugym8ldnxqi9yk3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We then can run this promise by simply calling the function and chaining a &lt;code&gt;.then()&lt;/code&gt; to it. This then allows you to pass the data through and then do some computational stuff with (You can chain &lt;code&gt;.then()&lt;/code&gt; together which I will show later on). There is also a &lt;code&gt;.catch()&lt;/code&gt; which is used to hold the errors if the promise returns a reject. There is usually one catch per promise as they can catch all errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr5nehutnx3xujj4cpuzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr5nehutnx3xujj4cpuzf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following promise will result in the following code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F10i6hsbdqa10g048jw1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F10i6hsbdqa10g048jw1b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if I give the wrong name I get the rejection error (the catch) executed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F83htdja4u5n94tfmig3x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F83htdja4u5n94tfmig3x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn0mvfjaewwm45cc3ea6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn0mvfjaewwm45cc3ea6h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting data example
&lt;/h2&gt;

&lt;p&gt;I have another example which is similar to my analogy above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F16j4821bpvfbiwsigot0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F16j4821bpvfbiwsigot0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have created above a promise that will read data from a text file using a node module.&lt;/p&gt;

&lt;p&gt;I then chain multiple &lt;code&gt;.then()&lt;/code&gt; together to get the edit the data I get back from the promise.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa6jcja0wu8vjx5auerfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa6jcja0wu8vjx5auerfr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which outputs: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh69d9a6h8s3ljipcdaqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh69d9a6h8s3ljipcdaqs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use them
&lt;/h2&gt;

&lt;p&gt;The advantages of using promises are you are able to chain them together using the &lt;code&gt;.then()&lt;/code&gt; and catch errors using the &lt;code&gt;.catch()&lt;/code&gt; which helps avoid &lt;code&gt;callback hell&lt;/code&gt;. Also it is much easier to follow what the code is doing and each point. &lt;/p&gt;

&lt;p&gt;You can also use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function" rel="noopener noreferrer"&gt;async await&lt;/a&gt; which is syntactical sugar to make promises even easier to read!&lt;/p&gt;

&lt;p&gt;I hope this aided you in getting a better understanding of Javascript Promises&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;

&lt;p&gt;I'm open to comments about this little description as I am new to blog posts.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My Journey to becoming a developer - First post =] </title>
      <dc:creator>Ludo05</dc:creator>
      <pubDate>Mon, 28 Oct 2019 20:46:39 +0000</pubDate>
      <link>https://dev.to/lewis150193/my-journey-to-becoming-a-developer-first-post-3p92</link>
      <guid>https://dev.to/lewis150193/my-journey-to-becoming-a-developer-first-post-3p92</guid>
      <description>&lt;p&gt;The Beginning&lt;/p&gt;

&lt;p&gt;Always wanted to post about my journey to becoming a developer so I thought were else to start if not here. &lt;/p&gt;

&lt;p&gt;Why I started programming?&lt;/p&gt;

&lt;p&gt;I started programming because I've always found interest in how computers work and also how to program them to perform tasks for us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rocky Roads&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started programming around 3/4 years ago and remember thinking i'll never get that hang of it. Spent hours on the most trivial tasks and found it really hard to carry on, even cases were I'd think I'm not good enough to be a programmer. Luckily I always found comfort in thinking about all the cools things I'll be able to do once I passed these rocky moments.&lt;/p&gt;

&lt;p&gt;Now I am software dev who's worked on both front-end and back-end. So if you were to take only one thing from this post it's to remember never to give up! Everyone hits hard times but it's the way you react to these moments will be the vital to you overcoming the thoughts of not being good enough.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>starter</category>
      <category>hacktoberfest</category>
      <category>motivation</category>
    </item>
  </channel>
</rss>
