<?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: Pranjal Jately</title>
    <description>The latest articles on DEV Community by Pranjal Jately (@pranjaljately).</description>
    <link>https://dev.to/pranjaljately</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%2F407653%2Feccc2ce6-4fa5-4a30-af1d-6879915387a3.png</url>
      <title>DEV Community: Pranjal Jately</title>
      <link>https://dev.to/pranjaljately</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pranjaljately"/>
    <language>en</language>
    <item>
      <title>Measure the time taken by a function to execute - console.time &amp; console.timeEnd ⏳⏲</title>
      <dc:creator>Pranjal Jately</dc:creator>
      <pubDate>Sun, 06 Sep 2020 23:18:12 +0000</pubDate>
      <link>https://dev.to/pranjaljately/measure-the-time-taken-by-a-function-to-execute-console-time-console-timeend-3e6e</link>
      <guid>https://dev.to/pranjaljately/measure-the-time-taken-by-a-function-to-execute-console-time-console-timeend-3e6e</guid>
      <description>&lt;p&gt;A quick and easy way to measure the time it takes code to run is by using &lt;code&gt;console.time&lt;/code&gt; in conjunction with &lt;code&gt;console.timeEnd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All you need to do is surround the code or function call you desire to evaluate with &lt;code&gt;console.time&lt;/code&gt; and &lt;code&gt;console.timeEnd&lt;/code&gt; respectively...&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8c3d3jpz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EcA9-z9WsAAHGwI.jpg" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--Na3ATVhY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1264994297516089350/yWYECVqG_normal.jpg" alt="Pranjal Jately 👨🏽‍💻 profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Pranjal Jately 👨🏽‍💻
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @pjately
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      💡 &lt;a href="https://twitter.com/hashtag/JavaScript"&gt;#JavaScript&lt;/a&gt; tip: console.time &amp;amp; console.timeEnd ⏲&lt;br&gt;&lt;br&gt;I'm no performance expert, but TIL a quick and easy way to measure the time it takes code to run ⬇&lt;br&gt;&lt;br&gt;&lt;a href="https://twitter.com/hashtag/100DaysOfCode"&gt;#100DaysOfCode&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/webdev"&gt;#webdev&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/CodeNewbie"&gt;#CodeNewbie&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/LearnInPublic"&gt;#LearnInPublic&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/React"&gt;#React&lt;/a&gt; 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      16:37 PM - 03 Jul 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1279092026643013633" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1279092026643013633" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      7
      &lt;a href="https://twitter.com/intent/like?tweet_id=1279092026643013633" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      3
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;&lt;code&gt;console.time(&amp;lt;label&amp;gt;)&lt;/code&gt; starts a timer with a given (unique) label and &lt;code&gt;console.timeEnd(&amp;lt;label&amp;gt;)&lt;/code&gt; stops the timer with the corresponding label (the labels must match for this to work).&lt;/p&gt;

&lt;p&gt;Once stopped, the elapsed time is automatically displayed in the console 🤯&lt;/p&gt;

&lt;p&gt;Drop a comment if you've ever used this technique to measure the performance of your code.&lt;br&gt;
Have a good one.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Destructuring a property with a different name</title>
      <dc:creator>Pranjal Jately</dc:creator>
      <pubDate>Wed, 01 Jul 2020 20:32:45 +0000</pubDate>
      <link>https://dev.to/pranjaljately/destructuring-a-property-with-a-different-name-4a0i</link>
      <guid>https://dev.to/pranjaljately/destructuring-a-property-with-a-different-name-4a0i</guid>
      <description>&lt;p&gt;So, you want to destructure an object but the property name is already assigned to another variable in the same scope or you just don't like the property name?&lt;/p&gt;

&lt;p&gt;A property can be destructured from an object and assigned to a variable with a different name using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;personal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Something personal...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;personal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pjately.dev&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;social&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;twitter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twitter.com/pjately&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;github&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;github.com/pranjaljately&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;personal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// pjately.dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Short, simple and sweet.&lt;br&gt;
Peace.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>What the Fetch - Failed HTTP responses</title>
      <dc:creator>Pranjal Jately</dc:creator>
      <pubDate>Sun, 21 Jun 2020 22:54:27 +0000</pubDate>
      <link>https://dev.to/pranjaljately/what-the-fetch-failed-http-responses-11kk</link>
      <guid>https://dev.to/pranjaljately/what-the-fetch-failed-http-responses-11kk</guid>
      <description>&lt;p&gt;So you think you know Fetch? Let's start with a little quiz...&lt;br&gt;
&lt;/p&gt;
&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ebPBkUdJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EbCUvF0WoAEI-4a.png" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--Na3ATVhY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1264994297516089350/yWYECVqG_normal.jpg" alt="Pranjal Jately 👨🏽‍💻 profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Pranjal Jately 👨🏽‍💻
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @pjately
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      🏆 &lt;a href="https://twitter.com/hashtag/JavaScript"&gt;#JavaScript&lt;/a&gt; quiz&lt;br&gt;&lt;br&gt;What will the code below log to the console?&lt;br&gt;&lt;br&gt;URL in snippet: &lt;a href="https://t.co/EsmqtY8wce"&gt;httpstat.us/500&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="https://twitter.com/hashtag/100DaysOfCode"&gt;#100DaysOfCode&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/webdev"&gt;#webdev&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/CodeNewbie"&gt;#CodeNewbie&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/React"&gt;#React&lt;/a&gt; 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      12:35 PM - 21 Jun 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1274682427663933441" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1274682427663933441" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      6
      &lt;a href="https://twitter.com/intent/like?tweet_id=1274682427663933441" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      8
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;Well done to those that guessed &lt;code&gt;Okay...&lt;/code&gt;. If you didn't, don't feel bad, I too assumed that the code logs &lt;code&gt;Error...&lt;/code&gt;. I then did some digging around and understood why it doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, why does Fetch do this?
&lt;/h2&gt;

&lt;p&gt;As per the docs on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful"&gt;MDN&lt;/a&gt;{:target="_blank"},&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;code&gt;fetch()&lt;/code&gt; promise will reject with a &lt;code&gt;TypeError&lt;/code&gt; when a network error is encountered or CORS is misconfigured on the server-side, although this usually means permission issues or similar — a 404 does not constitute a network error, for example.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt;(Or in our case a 500)&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;So, how do we handle this? The good news is, we can simply check if the &lt;code&gt;Response.ok()&lt;/code&gt; property has a value of true.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U568tHkY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EbETy6JUEAAH_OX%3Fformat%3Djpg%26name%3Dmedium" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U568tHkY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/EbETy6JUEAAH_OX%3Fformat%3Djpg%26name%3Dmedium" alt=""&gt;&lt;/a&gt;{:target="_blank"}&lt;/p&gt;

&lt;p&gt;So now the code logs &lt;code&gt;Error: Internal Server Error&lt;/code&gt;, which is what you probably wanted in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Many of you, including myself, expected &lt;code&gt;Error...&lt;/code&gt; to be logged from the very first snippet. This expectation probably comes from regularly using a library like Axios which handles the failed HTTP status code for you as seen in this &lt;a href="https://codesandbox.io/s/what-the-fetch-failed-http-responses-t5e9q?expanddevtools=1&amp;amp;fontsize=14&amp;amp;hidenavigation=1&amp;amp;theme=dark"&gt;CodeSandox&lt;/a&gt;{:target="_blank"}. &lt;/p&gt;

&lt;p&gt;Let me know if you were caught out by this in the discussion section below. Ciao.&lt;/p&gt;

&lt;p&gt;P.S. This is my first blog post so I would appreciate any feedback 😁&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
  </channel>
</rss>
