<?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>Forem: Nishant Singh</title>
    <description>The latest articles on Forem by Nishant Singh (@nishantsinghchandel).</description>
    <link>https://forem.com/nishantsinghchandel</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%2F1503747%2F5268752e-da25-4909-9568-9b915b66d9d5.png</url>
      <title>Forem: Nishant Singh</title>
      <link>https://forem.com/nishantsinghchandel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nishantsinghchandel"/>
    <language>en</language>
    <item>
      <title>JavaScript Pollyfills</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 22 Dec 2024 11:06:32 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/javascript-pollyfills-37i8</link>
      <guid>https://forem.com/nishantsinghchandel/javascript-pollyfills-37i8</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Polyfills in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript development, a &lt;strong&gt;polyfill&lt;/strong&gt; is a piece of code (typically JavaScript) that provides modern functionality on older browsers that do not natively support it. Polyfills allow developers to use new JavaScript features without worrying about compatibility issues with older environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Polyfill?
&lt;/h3&gt;

&lt;p&gt;A polyfill is essentially a backward-compatible shim that replicates the behavior of modern features in JavaScript. For instance, if a browser does not support &lt;code&gt;Array.prototype.map&lt;/code&gt;, a polyfill can be written to add this functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use Polyfills?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Browser Compatibility&lt;/strong&gt;: Ensure your code runs on older browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Future-Proofing&lt;/strong&gt;: Use modern JavaScript features without waiting for full browser adoption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistent Behavior&lt;/strong&gt;: Guarantee that the feature behaves the same way across all environments.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Befor we dive into some example one of the most common Polyfill question asked in interviews is Promise.all. Watch our video on this -&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Qg4jKQsbpGg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Polyfills for &lt;code&gt;Array.prototype.map&lt;/code&gt; and &lt;code&gt;Array.prototype.filter&lt;/code&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.map&lt;/code&gt; Polyfill
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; method creates a new array populated with the results of calling a provided function on every element in the original array.&lt;/p&gt;

&lt;p&gt;Here’s a polyfill for &lt;code&gt;Array.prototype.map&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Array.prototype.map called on null or undefined&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&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="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; is not a function&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.filter&lt;/code&gt; Polyfill
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;filter&lt;/code&gt; method creates a new array with all elements that pass the test implemented by the provided function.&lt;/p&gt;

&lt;p&gt;Here’s a polyfill for &lt;code&gt;Array.prototype.filter&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Array.prototype.filter called on null or undefined&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&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="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; is not a function&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using Polyfilled Methods
&lt;/h3&gt;

&lt;p&gt;Here’s how you can use the polyfilled &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;filter&lt;/code&gt; methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Using map to double the numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;doubled&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: [2, 4, 6, 8, 10]&lt;/span&gt;

&lt;span class="c1"&gt;// Using filter to get even numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;evens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;evens&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: [2, 4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices for Polyfills
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check Native Support&lt;/strong&gt;: Always check if the browser already supports the feature to avoid overwriting native implementations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Modern Tools&lt;/strong&gt;: Leverage tools like Babel or core-js to automate polyfilling in your projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be Mindful of Performance&lt;/strong&gt;: Polyfills may have performance implications compared to native implementations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit Polyfills&lt;/strong&gt;: Only include polyfills for features your target audience’s browsers are missing.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Polyfills are essential for creating backward-compatible JavaScript applications. By understanding how to write and use polyfills, you can ensure your code works seamlessly across different browsers and environments. The examples of &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;filter&lt;/code&gt; show how simple and effective polyfilling can be for extending JavaScript functionality.&lt;/p&gt;

&lt;p&gt;Watch more content on our Youtube channel - &lt;a href="https://www.youtube.com/channel/UCBM2Z-kqN7ioFKeR_-iU0zA?sub_confirmation=1" rel="noopener noreferrer"&gt;Frontend With Chandel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Async/Await and Promises in JavaScript</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 22 Dec 2024 10:54:21 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/asyncawait-and-promises-in-javascript-3h94</link>
      <guid>https://forem.com/nishantsinghchandel/asyncawait-and-promises-in-javascript-3h94</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Async/Await and Promises in JavaScript
&lt;/h2&gt;

&lt;p&gt;JavaScript’s ability to handle asynchronous operations is crucial for modern web development. &lt;strong&gt;Promises&lt;/strong&gt; and &lt;strong&gt;async/await&lt;/strong&gt; are two key mechanisms to manage asynchronous code effectively. This article explores these concepts, their usage, and best practices, along with examples.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tVQxH29XB6c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Promises?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Promise&lt;/strong&gt; represents a value that may be available now, or in the future, or never. It allows developers to write asynchronous code that’s more manageable and less error-prone than traditional callbacks.&lt;/p&gt;

&lt;h4&gt;
  
  
  States of a Promise:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pending&lt;/strong&gt;: The initial state, neither fulfilled nor rejected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fulfilled&lt;/strong&gt;: The operation completed successfully.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rejected&lt;/strong&gt;: The operation failed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Creating and Using Promises
&lt;/h4&gt;

&lt;p&gt;Here’s an example of creating and consuming a Promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Simulating success or failure&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data fetched successfully!&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error fetching data.&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="mi"&gt;1000&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="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logs: Data fetched successfully!&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is Async/Await?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Async/Await&lt;/strong&gt; is syntactic sugar built on top of Promises, introduced in ES2017 (ES8). It allows asynchronous code to be written in a synchronous-looking manner, making it more readable and easier to debug.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Points:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;async&lt;/code&gt; keyword marks a function as asynchronous.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;await&lt;/code&gt; keyword pauses the execution of an &lt;code&gt;async&lt;/code&gt; function until the Promise is resolved or rejected.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using Async/Await
&lt;/h4&gt;

&lt;p&gt;Here’s the same example rewritten with &lt;code&gt;async/await&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Simulating success or failure&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data fetched successfully!&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error fetching data.&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="mi"&gt;1000&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="nx"&gt;fetchAsyncData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logs: Data fetched successfully!&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="nf"&gt;fetchAsyncData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparing Promises and Async/Await
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Promises&lt;/th&gt;
&lt;th&gt;Async/Await&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Syntax&lt;/td&gt;
&lt;td&gt;Chaining with &lt;code&gt;.then&lt;/code&gt; and &lt;code&gt;.catch&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Looks like synchronous code with &lt;code&gt;await&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Readability&lt;/td&gt;
&lt;td&gt;Moderate, especially with long chains&lt;/td&gt;
&lt;td&gt;High, especially for sequential tasks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error Handling&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;.catch&lt;/code&gt; for errors&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;try/catch&lt;/code&gt; for errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debugging&lt;/td&gt;
&lt;td&gt;Stack traces can be challenging&lt;/td&gt;
&lt;td&gt;Easier due to synchronous-like flow&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Example: Handling Multiple Promises
&lt;/h3&gt;

&lt;p&gt;Both Promises and async/await can handle multiple asynchronous operations using &lt;code&gt;Promise.all&lt;/code&gt; or loops. Here’s an example:&lt;/p&gt;

&lt;h4&gt;
  
  
  Using &lt;code&gt;Promise.all&lt;/code&gt;:
&lt;/h4&gt;



&lt;div class="highlight js-code-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;fetchData1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;fetchData1&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;fetchData2&lt;/span&gt;&lt;span class="p"&gt;()])&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logs: ['Data 1', 'Data 2']&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using Async/Await:
&lt;/h4&gt;



&lt;div class="highlight js-code-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;fetchAsyncData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;fetchData1&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;fetchData2&lt;/span&gt;&lt;span class="p"&gt;()]);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logs: ['Data 1', 'Data 2']&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="nf"&gt;fetchAsyncData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices for Async/Await and Promises
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;try/catch&lt;/code&gt; for Error Handling&lt;/strong&gt;:&lt;br&gt;
Always wrap &lt;code&gt;await&lt;/code&gt; calls in &lt;code&gt;try/catch&lt;/code&gt; blocks to handle errors gracefully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid Blocking Code&lt;/strong&gt;:&lt;br&gt;
Do not use &lt;code&gt;await&lt;/code&gt; inside loops without careful consideration as it can lead to performance bottlenecks. Use &lt;code&gt;Promise.all&lt;/code&gt; for parallel execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Chain Promises Wisely&lt;/strong&gt;:&lt;br&gt;
For simpler operations, Promises with &lt;code&gt;.then&lt;/code&gt; and &lt;code&gt;.catch&lt;/code&gt; may suffice. Use async/await for complex flows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Functions Modular&lt;/strong&gt;:&lt;br&gt;
Break down large functions into smaller ones to keep your async code clean and maintainable.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Promises and async/await are powerful tools for managing asynchronous operations in JavaScript. While Promises provide flexibility and a structured way to handle async tasks, async/await enhances readability and debugging. Understanding when and how to use them effectively will greatly improve your JavaScript development workflow.&lt;/p&gt;

&lt;p&gt;Watch more content on our Youtube channel - &lt;a href="https://www.youtube.com/channel/UCBM2Z-kqN7ioFKeR_-iU0zA?sub_confirmation=1" rel="noopener noreferrer"&gt;Frontend With Chandel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Event Loop</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 22 Dec 2024 10:44:21 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/javascript-event-loop-5bhk</link>
      <guid>https://forem.com/nishantsinghchandel/javascript-event-loop-5bhk</guid>
      <description>&lt;h2&gt;
  
  
  Understanding the JavaScript Event Loop
&lt;/h2&gt;

&lt;p&gt;JavaScript is a single-threaded, non-blocking, asynchronous programming language. At the heart of its asynchronous behavior is the &lt;strong&gt;event loop&lt;/strong&gt;. Understanding how the event loop works is crucial for writing efficient and bug-free JavaScript code. This article breaks down the key concepts of the JavaScript event loop and how it manages asynchronous operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Event Loop?
&lt;/h3&gt;

&lt;p&gt;The event loop is a mechanism in JavaScript that allows the language to handle asynchronous operations, despite being single-threaded. It continuously checks the &lt;strong&gt;call stack&lt;/strong&gt; and the &lt;strong&gt;callback queue&lt;/strong&gt; to determine what code to execute next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Components of the Event Loop
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/CNGA0I-nVEg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Call Stack&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The call stack is a data structure that records function calls.&lt;/li&gt;
&lt;li&gt;When a function is invoked, it is added to the top of the call stack.&lt;/li&gt;
&lt;li&gt;When the function execution is complete, it is removed from the stack.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Web APIs&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web APIs provide the functionality for asynchronous operations, such as &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;fetch&lt;/code&gt;, and DOM events.&lt;/li&gt;
&lt;li&gt;These APIs delegate tasks to the browser’s threads for processing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Callback Queue&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The callback queue holds callbacks and tasks that are ready to be executed.&lt;/li&gt;
&lt;li&gt;These callbacks are added to the queue after the corresponding Web API operation completes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Microtask Queue&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Microtasks are prioritized over regular callbacks in the callback queue.&lt;/li&gt;
&lt;li&gt;Examples include &lt;code&gt;Promise.then&lt;/code&gt;, &lt;code&gt;MutationObserver&lt;/code&gt;, and queueMicrotask.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Event Loop&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The event loop continuously monitors the call stack and the callback queue.&lt;/li&gt;
&lt;li&gt;If the call stack is empty, the event loop pushes the first task from the callback or microtask queue to the call stack for execution.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How It All Works Together
&lt;/h3&gt;

&lt;p&gt;Here’s a step-by-step explanation of how the event loop operates:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Function Execution&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the JavaScript engine runs, the main script is added to the call stack and executed line by line.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Asynchronous Operations&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When an asynchronous function (e.g., &lt;code&gt;setTimeout&lt;/code&gt;) is called, the browser delegates it to a Web API.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Task Completion&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once the asynchronous operation completes, its callback is added to the appropriate queue (callback queue or microtask queue).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Event Loop Processing&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The event loop checks if the call stack is empty.&lt;/li&gt;
&lt;li&gt;If empty, it processes tasks from the microtask queue first, then the callback queue.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example: Event Loop in Action
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xvya3qgfgQg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Consider the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Timeout&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Promise&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;End&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Execution Flow&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;console.log('Start')&lt;/code&gt; is executed and prints &lt;code&gt;Start&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setTimeout&lt;/code&gt; is called, and its callback is sent to the Web API.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Promise.resolve().then&lt;/code&gt; adds its callback to the microtask queue.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;console.log('End')&lt;/code&gt; is executed and prints &lt;code&gt;End&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The microtask queue is processed, and &lt;code&gt;Promise&lt;/code&gt; is printed.&lt;/li&gt;
&lt;li&gt;The callback queue is processed, and &lt;code&gt;Timeout&lt;/code&gt; is printed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start
End
Promise
Timeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices for Working with the Event Loop
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Avoid Blocking the Call Stack&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Long-running tasks block the call stack and delay asynchronous operations. Use &lt;code&gt;setTimeout&lt;/code&gt; or Web Workers for heavy computations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prioritize Microtasks&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;Promise&lt;/code&gt; or &lt;code&gt;queueMicrotask&lt;/code&gt; for tasks that must run before the next event loop iteration.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Understand Callback Timing&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recognize that microtasks execute before the callback queue, ensuring higher priority for &lt;code&gt;Promise&lt;/code&gt;-based logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The JavaScript event loop is a powerful mechanism that enables asynchronous programming. By understanding its components and behavior, you can write more efficient and predictable code. Remember to keep the call stack clear, leverage microtasks wisely, and respect the asynchronous nature of JavaScript.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building a Quote Generator in React: A Beginner's Guide</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 08 Sep 2024 19:08:20 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/building-a-quote-generator-in-react-a-beginners-guide-370e</link>
      <guid>https://forem.com/nishantsinghchandel/building-a-quote-generator-in-react-a-beginners-guide-370e</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/LjpsJ4l21Ug"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you're looking to enhance your React skills by building simple projects, a &lt;strong&gt;Quote Generator&lt;/strong&gt; is an ideal choice. In this guide, we’ll create a Quote Generator that fetches random advice from an external API using React, &lt;code&gt;axios&lt;/code&gt;, and a loading state to enhance the user experience. This project will help you get hands-on practice with state management, conditional rendering, and API handling in React.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Overview
&lt;/h3&gt;

&lt;p&gt;This &lt;strong&gt;Quote Generator&lt;/strong&gt; will display random pieces of advice by fetching data from the &lt;a href="https://api.adviceslip.com/advice" rel="noopener noreferrer"&gt;Advice Slip API&lt;/a&gt;. Upon clicking a button, a new piece of advice will be displayed, with a loading indicator showing while the advice is being fetched.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before we dive into the code, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of &lt;strong&gt;React&lt;/strong&gt;, including hooks like &lt;code&gt;useState&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Familiarity with &lt;strong&gt;axios&lt;/strong&gt; for API requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js and npm&lt;/strong&gt; installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Set Up Your React Project
&lt;/h3&gt;

&lt;p&gt;First, create a new React project by running the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app quote-generator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the setup is complete, navigate to the project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;quote-generator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install &lt;code&gt;axios&lt;/code&gt;, which we'll use to fetch data from the API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Update &lt;code&gt;App.js&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Replace the default content in &lt;code&gt;src/App.js&lt;/code&gt; with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;apiUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.adviceslip.com/advice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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="nx"&gt;advice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAdvice&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please click button to see your advice !!&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleQuoteGenerate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;apiUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setAdvice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;advice&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(response.data);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; Quote Generator &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"quote-container"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"quote"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;blockquote&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"quote"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;advice&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;blockquote&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"default-btn"&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleQuoteGenerate&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Give Me Advice
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;State Management&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We define two states using the &lt;code&gt;useState&lt;/code&gt; hook:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;advice&lt;/code&gt;: This holds the current piece of advice, initialized with a default message ("Please click button to see your advice!!").&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isLoading&lt;/code&gt;: This is a boolean flag that manages the loading state, initially set to &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;API Call&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;handleQuoteGenerate&lt;/code&gt; function is an asynchronous function that fetches advice from the Advice Slip API.&lt;/li&gt;
&lt;li&gt;Before the request is made, we set &lt;code&gt;isLoading&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt; to display the loading indicator. After the API request completes, the fetched advice is set in the &lt;code&gt;advice&lt;/code&gt; state, and &lt;code&gt;isLoading&lt;/code&gt; is set back to &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Conditional Rendering&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We use a ternary operator to conditionally render the loading indicator (&lt;code&gt;...&lt;/code&gt;) when &lt;code&gt;isLoading&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;. Once the advice is fetched and &lt;code&gt;isLoading&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;, the &lt;code&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; tag displays the fetched advice.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Button&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The "Give Me Advice" button triggers the &lt;code&gt;handleQuoteGenerate&lt;/code&gt; function, fetching a new piece of advice every time it's clicked.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3: Add Some Basic Styling
&lt;/h3&gt;

&lt;p&gt;To improve the visual appearance of the app, let's add some simple styles. In the &lt;code&gt;src/App.css&lt;/code&gt; &amp;amp; &lt;code&gt;src/index.css&lt;/code&gt; file, add the following CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* src/App.css */&lt;/span&gt;
&lt;span class="nc"&gt;.App&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.quote-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#f5f5f5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;650px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="m"&gt;150deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#2b2e4a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#3e345e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#57386e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#723b78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#903c7a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#af3d73&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#cd3f63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#e84545&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.quote&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.default-btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#2b2e4a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.default-btn&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3e345e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, add in &lt;code&gt;src/index.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* src/index.css */&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;-apple-system&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BlinkMacSystemFont&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Segoe UI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Roboto"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Oxygen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;"Ubuntu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Cantarell"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Fira Sans"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Droid Sans"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Helvetica Neue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;-webkit-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;antialiased&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;-moz-osx-font-smoothing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grayscale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="m"&gt;135deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#ffe5ce&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#ffd0ba&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#ffb9b0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#ffa2b0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#fd8dba&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#ec7cca&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#cd72de&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="m"&gt;#9c71f2&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;/* made at https://learnui.design/tools/gradient-generator.html */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Run the Application
&lt;/h3&gt;

&lt;p&gt;Once you've added the code and styles, run your application with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will launch the app in your browser, where you’ll see a heading, the default advice message, and the button. Click the button to fetch a new piece of advice from the API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Features of the App
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;API Integration&lt;/strong&gt;: The app integrates with the Advice Slip API to fetch random advice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loading Indicator&lt;/strong&gt;: A simple loading indicator (&lt;code&gt;...&lt;/code&gt;) is shown while waiting for the advice to load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Interaction&lt;/strong&gt;: The user can click the button multiple times to fetch new pieces of advice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Potential Enhancements
&lt;/h3&gt;

&lt;p&gt;Once you're comfortable with this basic version of the quote generator, you can extend it with additional features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;: Implement error handling for cases when the API fails to respond.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;apiUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="nf"&gt;setAdvice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;advice&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;setAdvice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Oops! Something went wrong.&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="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Save Favorite Quotes&lt;/strong&gt;: Allow users to save their favorite quotes using &lt;code&gt;localStorage&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sharing&lt;/strong&gt;: Add a feature to allow users to share their favorite advice on social media.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Building this simple &lt;strong&gt;Quote Generator&lt;/strong&gt; in React is an excellent project for beginners. It allows you to get hands-on experience with &lt;code&gt;axios&lt;/code&gt; for API requests, React’s &lt;code&gt;useState&lt;/code&gt; for managing state, and &lt;code&gt;useEffect&lt;/code&gt; for handling side effects like fetching data. Plus, it’s a fun and interactive app that can be easily extended with new features as your React skills grow!&lt;/p&gt;

&lt;h3&gt;
  
  
  Checkout other projects as well
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/1Hf3Xqxj1mM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding `async` and `defer` in JavaScript: A Guide for Interview Preparation</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 01 Sep 2024 17:29:25 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/understanding-async-and-defer-in-javascript-a-guide-for-interview-preparation-3fi9</link>
      <guid>https://forem.com/nishantsinghchandel/understanding-async-and-defer-in-javascript-a-guide-for-interview-preparation-3fi9</guid>
      <description>&lt;p&gt;JavaScript is a language that runs in the browser to enhance user experience by manipulating the Document Object Model (DOM), handling events, and performing asynchronous operations. When a web page is loaded, the browser parses the HTML and executes the JavaScript in the order it encounters the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags. However, JavaScript execution can block the parsing of HTML, potentially slowing down the page load time. To optimize this, modern web development uses &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; attributes on &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags, especially when loading external scripts.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/p-EbMa8X1rw?start=363"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This article will delve into what &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; are, how they work, and their key differences—knowledge that is crucial for any JavaScript developer, particularly in interviews.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftftyk8avza9wrc5358h5.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftftyk8avza9wrc5358h5.png" alt="Legend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The Default Behavior of Script Tags
&lt;/h4&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff015xjh28af0labs5l05.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff015xjh28af0labs5l05.png" alt="default"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we explore &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt;, it’s essential to understand the default behavior of &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blocking Behavior&lt;/strong&gt;: When the browser encounters a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, it stops parsing the HTML, downloads the script, and executes it immediately before continuing with the rest of the HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Order of Execution&lt;/strong&gt;: If there are multiple script tags, they are executed in the order they appear in the HTML document. This can lead to slower page loads, as the browser waits for each script to download and execute before moving on.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. The &lt;code&gt;async&lt;/code&gt; Attribute
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;async&lt;/code&gt; attribute is used to load scripts asynchronously, which means the browser doesn’t block the HTML parsing while the script is being downloaded. However, the script will execute immediately after it has been downloaded, potentially out of order relative to other scripts.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo10heti08gkwm7vh8ab.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo10heti08gkwm7vh8ab.png" alt="async"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Non-blocking Download&lt;/strong&gt;: The script is downloaded while the HTML continues to be parsed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Timing&lt;/strong&gt;: The script is executed as soon as it is downloaded, without waiting for the rest of the HTML to be parsed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order of Execution&lt;/strong&gt;: Scripts with the &lt;code&gt;async&lt;/code&gt; attribute may execute in any order, depending on which script finishes downloading first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script1.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script2.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this case, &lt;code&gt;script1.js&lt;/code&gt; and &lt;code&gt;script2.js&lt;/code&gt; are downloaded concurrently. Whichever script finishes downloading first will execute first, potentially leading to an unpredictable order of execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use &lt;code&gt;async&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For independent scripts that don’t rely on each other or the DOM being fully parsed (e.g., analytics or advertisement scripts).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. The &lt;code&gt;defer&lt;/code&gt; Attribute
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;defer&lt;/code&gt; attribute also loads scripts asynchronously, but it ensures that the scripts are executed in the order they appear in the document. Additionally, scripts with the &lt;code&gt;defer&lt;/code&gt; attribute will only execute after the HTML parsing is complete.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgmrmmhmjq7delz64emx.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgmrmmhmjq7delz64emx.png" alt="defer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Non-blocking Download&lt;/strong&gt;: Like &lt;code&gt;async&lt;/code&gt;, the script is downloaded while the HTML continues to be parsed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Timing&lt;/strong&gt;: The script is executed after the HTML document has been fully parsed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order of Execution&lt;/strong&gt;: Scripts with the &lt;code&gt;defer&lt;/code&gt; attribute execute in the order they appear in the document.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script1.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script2.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, &lt;code&gt;script1.js&lt;/code&gt; and &lt;code&gt;script2.js&lt;/code&gt; are downloaded concurrently, but they will execute in the order they appear, only after the HTML parsing is complete.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use &lt;code&gt;defer&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For scripts that rely on the DOM being fully loaded or that need to be executed in a specific order (e.g., main application scripts).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Comparison of &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Attribute&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;HTML Parsing&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Script Download&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Script Execution&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Execution Order&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;async&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Asynchronously&lt;/td&gt;
&lt;td&gt;Immediately after download&lt;/td&gt;
&lt;td&gt;Unpredictable, as per download order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;defer&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Continues&lt;/td&gt;
&lt;td&gt;Asynchronously&lt;/td&gt;
&lt;td&gt;After HTML parsing is complete&lt;/td&gt;
&lt;td&gt;Preserved as per document order&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqe6v75v5awqq9g048ci.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqe6v75v5awqq9g048ci.png" alt="async defer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Common Interview Questions
&lt;/h4&gt;

&lt;p&gt;When it comes to interviews, understanding &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; is essential. Here are some common questions you might encounter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What is the difference between &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; attributes in a script tag?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;async&lt;/code&gt; executes the script as soon as it's downloaded, while &lt;code&gt;defer&lt;/code&gt; waits until the entire HTML document is parsed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;When would you use &lt;code&gt;async&lt;/code&gt; over &lt;code&gt;defer&lt;/code&gt; and vice versa?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;async&lt;/code&gt; for independent scripts that don’t depend on other scripts or the DOM. Use &lt;code&gt;defer&lt;/code&gt; for scripts that need the DOM to be fully parsed or that depend on other scripts.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;What are the potential issues with using &lt;code&gt;async&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Since &lt;code&gt;async&lt;/code&gt; scripts may execute in an unpredictable order, it can lead to issues if one script depends on another.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Conclusion
&lt;/h4&gt;

&lt;p&gt;Understanding &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; is crucial for optimizing the performance of web pages. By knowing when and how to use these attributes, you can ensure faster page loads and a better user experience. As a JavaScript developer, particularly in an interview setting, being able to articulate the differences and appropriate use cases for &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;defer&lt;/code&gt; will demonstrate your proficiency in modern web development practices.&lt;/p&gt;

&lt;p&gt;Make sure to experiment with these attributes in your projects to get a solid grasp of their behavior. Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/LnV22-JVt5c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>React Interview Questions</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sun, 18 Aug 2024 12:10:18 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/react-interview-questions-e3h</link>
      <guid>https://forem.com/nishantsinghchandel/react-interview-questions-e3h</guid>
      <description>&lt;p&gt;Hellooo everyone, &lt;br&gt;
Most of the frontend developer are preparing for interviews these days. So, the questions comes first before we start preparation is from where to start.&lt;/p&gt;

&lt;p&gt;Don't worry I am here to help you with the topics you should cover one by one. &lt;/p&gt;

&lt;p&gt;React is one of the most popular library and have large community that makes it perfect for every company to hire developers who knows react very well. Then often look into the candidate who knows react in depth. &lt;/p&gt;

&lt;p&gt;Before taking you to further, there is Youtube video for this.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/_X2A3Q5bxJw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Below is the main topics - &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;HOOKS**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;useState()&lt;/li&gt;
&lt;li&gt;useEffect() ❗&lt;/li&gt;
&lt;li&gt;useRef() ❗&lt;/li&gt;
&lt;li&gt;useContext()&lt;/li&gt;
&lt;li&gt;useReducer()&lt;/li&gt;
&lt;li&gt;useMemo() ❗&lt;/li&gt;
&lt;li&gt;useCallback() ❗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;HOC - High Order Components**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When to use?&lt;/li&gt;
&lt;li&gt;How to use?&lt;/li&gt;
&lt;li&gt;Example?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Life Cycle methods of components**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;3 phase (mounting, unmounting, updating) ❗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;State Management**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State/Props&lt;/li&gt;
&lt;li&gt;Props Drilling ❗&lt;/li&gt;
&lt;li&gt;Context&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Virtual DOM**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reconciliation ❗&lt;/li&gt;
&lt;li&gt;React fibre&lt;/li&gt;
&lt;li&gt;Renders&lt;/li&gt;
&lt;li&gt;Diff Algorithm ❗&lt;/li&gt;
&lt;li&gt;How render works&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Custom Hooks**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When to use?&lt;/li&gt;
&lt;li&gt;Example (clean, maintainable, Reusable)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Lazy Loading**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code Splitting ❗&lt;/li&gt;
&lt;li&gt;Chunking&lt;/li&gt;
&lt;li&gt;Suspense&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;SSR vs CSR**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Routing (RBAC - Route Based Access Control)&lt;/li&gt;
&lt;li&gt;Protected Routes ❗&lt;/li&gt;
&lt;li&gt;Query Params&lt;/li&gt;
&lt;li&gt;Dynamic Routing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Redux/Zustand (RTK)**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redux Toolkit (RTK)&lt;/li&gt;
&lt;li&gt;How to use?&lt;/li&gt;
&lt;li&gt;When to use?&lt;/li&gt;
&lt;li&gt;Why?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Async Tasks**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API calls (fetch/axios)&lt;/li&gt;
&lt;li&gt;Events&lt;/li&gt;
&lt;li&gt;Promises ❗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Performance**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lazy Loading ❗&lt;/li&gt;
&lt;li&gt;Asset Optimization ❗&lt;/li&gt;
&lt;li&gt;Bundler&lt;/li&gt;
&lt;li&gt;JS/CSS optimization&lt;/li&gt;
&lt;li&gt;CDN/ Server&lt;/li&gt;
&lt;li&gt;Optimized Code ❗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Styling**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tailwind CSS&lt;/li&gt;
&lt;li&gt;Stylex (Facebook)&lt;/li&gt;
&lt;li&gt;Material UI&lt;/li&gt;
&lt;li&gt;Ant UI&lt;/li&gt;
&lt;li&gt;CSS/SCSS/LESS/SASS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅&lt;/strong&gt;Miscellaneous**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reusability&lt;/li&gt;
&lt;li&gt;Modularity&lt;/li&gt;
&lt;li&gt;Testability&lt;/li&gt;
&lt;li&gt;Testing&lt;/li&gt;
&lt;li&gt;Accessibility ❗&lt;/li&gt;
&lt;li&gt;Security ❗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/eiOCuw6gfHc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Watch more content on our Youtube channel - &lt;a href="https://www.youtube.com/channel/UCBM2Z-kqN7ioFKeR_-iU0zA?sub_confirmation=1" rel="noopener noreferrer"&gt;Frontend With Chandel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>interview</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Frontend Interview Preparation Day 2 - Linked List</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sat, 22 Jun 2024 13:13:13 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/maang-interview-preparation-day-2-linked-list-2kca</link>
      <guid>https://forem.com/nishantsinghchandel/maang-interview-preparation-day-2-linked-list-2kca</guid>
      <description>&lt;p&gt;Hi there 🙏, today is June 22, 2024. So, I woke up at 7 AM ⏰ today, did some morning walk, yoga for 30 mins. Went to temple &amp;amp; then started the routine.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/3gvonwRV5bM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Today's Plan - 💯
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;June 22 (Sat)&lt;/strong&gt;: Study linked lists, practice easy problems. (4 hours)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Watch the videos for linked list from Udemy Course.&lt;br&gt;
&lt;a href="https://www.udemy.com/share/1013ja3@8z3jnE8L7842ZCmS_vaEAdTJmJKxuxPyDvHeXHPejNI9tEGIqTlqmNy897xhr198/" rel="noopener noreferrer"&gt;Master the Coding Interview: Data Structures + Algorithms&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ What is linked list?&lt;/strong&gt; ⛓️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A linked list is a linear data structure that stores a collection of data elements dynamically.&lt;/li&gt;
&lt;li&gt;Nodes represent those data elements, and links or pointers connect each node.&lt;/li&gt;
&lt;li&gt;Each node consists of two fields, the information stored in a linked list and a pointer that stores the address of its next node.&lt;/li&gt;
&lt;li&gt;The last node contains null in its second field because it will point to no node.&lt;/li&gt;
&lt;li&gt;A linked list can grow and shrink its size, as per the requirement.&lt;/li&gt;
&lt;li&gt;It does not waste memory space.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅ The linked list mainly has three types, they are:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Singly Linked List&lt;/li&gt;
&lt;li&gt;Doubly Linked List&lt;/li&gt;
&lt;li&gt;Circular Linked List&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96k8ubgn4t9ylwa24xtd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96k8ubgn4t9ylwa24xtd.png" alt="Image description" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Essential Operation on Linked Lists&lt;/strong&gt; 🚥&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Traversing: To traverse all nodes one by one.&lt;/li&gt;
&lt;li&gt;Insertion: To insert new nodes at specific positions.&lt;/li&gt;
&lt;li&gt;Deletion: To delete nodes from specific positions.&lt;/li&gt;
&lt;li&gt;Searching: To search for an element from the linked list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;✅ Application of a Linked List&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A linked list is used to implement stacks and queues.&lt;/li&gt;
&lt;li&gt;A linked list also helps to implement an adjacency matrix graph.&lt;/li&gt;
&lt;li&gt;It is used for the dynamic memory location.&lt;/li&gt;
&lt;li&gt;The linked list makes it easy to deal with the addition and multiplication of polynomial operations.&lt;/li&gt;
&lt;li&gt;Implementing a hash table, each bucket of the hash table itself behaves as a linked list.&lt;/li&gt;
&lt;li&gt;It is used in a functionality known as undo in Photoshop and Word.&lt;/li&gt;
&lt;li&gt;With that, you have reached the end of this tutorial on Linked Lists.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅ Some leet code question which I solved today&lt;/strong&gt; 👨‍💻&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/linked-list-cycle/description/" rel="noopener noreferrer"&gt;linked-list-cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/merge-two-sorted-lists/description/" rel="noopener noreferrer"&gt;Merge Two Sorted Lists&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/" rel="noopener noreferrer"&gt;Remove Duplicates from Sorted List&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/intersection-of-two-linked-lists/description/" rel="noopener noreferrer"&gt;Intersection of Two Linked Lists&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the above leet code questions are solved from my end, I hope you will also try the same. If you can't solve it no problem. Learn it and try again. Never give up.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always remember, your career is a marathon, not a sprint.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;✅ Checkout some of my post&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/nishantsinghchandel/frontend-interview-preparation-cl"&gt;Frontend Interview Preparation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/nishantsinghchandel/maang-interview-preparation-day-1-the-plan-3i61"&gt;MAANG Interview Preparation Day 1 - The Plan&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Frontend Interview Preparation Day 1 - The Plan</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sat, 22 Jun 2024 12:46:03 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/maang-interview-preparation-day-1-the-plan-3i61</link>
      <guid>https://forem.com/nishantsinghchandel/maang-interview-preparation-day-1-the-plan-3i61</guid>
      <description>&lt;p&gt;Hello everyone 🙏, just writing this post to motivate you all to start preparation of you dream company MAANG. This is just a post related to what I am planning to do in coming weeks and I will try to post each and everything related to interview preparation.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/LnV22-JVt5c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;20 June 2024,&lt;/strong&gt; is the last working 👨‍💻 day at &lt;strong&gt;MakeMyTrip&lt;/strong&gt;. As I am looking forward for better opportunity and career. So, I took this decision because I need a break from work, meanwhile I will also learn DSA and other stuff.&lt;/p&gt;




&lt;p&gt;Making it short, today &lt;strong&gt;21 June 2024&lt;/strong&gt;, I started to plan 🔖 everything how much time I have to study, how many topics I have to cover etc. I will go one by one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm00ya08g5a8a1mkk0aq0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm00ya08g5a8a1mkk0aq0.jpg" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I generate a master plan using &lt;strong&gt;chat-gpt&lt;/strong&gt; of 8 weeks of interview preparation. I will suggest you all to do the same. This plan covers an 8-week period, focusing on algorithms, data structures, system design, and behavioral questions. Each day has a study duration of approximately 4-5 hours.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Daily Tasks&lt;/strong&gt;: 🥧

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;June 21 (Fri)&lt;/strong&gt;: Introduction to arrays and strings, practice easy problems. (4 hours) - DONE&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 22 (Sat)&lt;/strong&gt;: Study linked lists, practice easy problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 23 (Sun)&lt;/strong&gt;: Dive into stacks and queues, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 24 (Mon)&lt;/strong&gt;: Understand hash tables, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 25 (Tue)&lt;/strong&gt;: Learn trees (binary trees and binary search trees), practice easy problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 26 (Wed)&lt;/strong&gt;: Explore graphs, practice easy problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 27 (Thu)&lt;/strong&gt;: Review and recap the week’s topics, practice a mixed set of problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 28 (Fri)&lt;/strong&gt;: Study heaps and priority queues, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 29 (Sat)&lt;/strong&gt;: Understand tries, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;June 30 (Sun)&lt;/strong&gt;: Learn about sorting algorithms, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;July 1 (Mon)&lt;/strong&gt;: Explore searching algorithms, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;July 2 (Tue)&lt;/strong&gt;: Study dynamic programming, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;July 3 (Wed)&lt;/strong&gt;: Introduction to backtracking, practice medium problems. (4 hours)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;July 4 (Thu)&lt;/strong&gt;: Review and recap the week’s topics, practice a mixed set of problems. (4 hours)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;This is my plan don't try the same if you are working professional with other priorities. Please take help from Chat-GPT to generate customized plan, it is free.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next, I updated my resume 🗒️, If you have any confusion 😕 about how to make a resume, here is the link please follow along, it is very helpful.
&lt;a href="https://applieddigitalskills.withgoogle.com/c/middle-and-high-school/en/create-a-resume-in-google-docs/overview.html" rel="noopener noreferrer"&gt;Design, write, and format a professional resume that stands out&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;✅ Resume should be of 1 page 📄 only, which has all the skills you know and which is required for job. Don't mention anything you don't know.&lt;/li&gt;
&lt;li&gt;✅ Resume should contain your experiences with impact, like if you developed something and it reduces cost mention it properly.&lt;/li&gt;
&lt;li&gt;✅ Focus on Relevance: Highlight experiences that are most relevant to the job you are applying for.&lt;/li&gt;
&lt;li&gt;✅ Use Action Verbs: Start each bullet point with strong action verbs like "developed," "managed," "implemented," etc.&lt;/li&gt;
&lt;li&gt;✅ Quantify Achievements: Whenever possible, use numbers to quantify your achievements (e.g., "Increased sales by 20%").&lt;/li&gt;
&lt;li&gt;✅ Be Specific: Provide specific examples of your accomplishments and responsibilities.&lt;/li&gt;
&lt;li&gt;✅ Highlight Key Skills: Emphasize skills that are listed in the job description.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I bought some stuffs from amazon which helps in problem solving. Don't get excited it's just a small white board 📋. I prefer this board because it's portable and handy, for large white boards you have to hang it some where or you need extra space during coding. So, I highly recommend to buy this size of white board. It easily fits your desk.&lt;br&gt;
(White Board)[&lt;a href="https://amzn.in/d/098jHWGO" rel="noopener noreferrer"&gt;https://amzn.in/d/098jHWGO&lt;/a&gt;]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A timer for deep focus 💡, so that you can keep track that you are working not wasting time. I pause the timer if I leave my seat. Just a website which helps you to keep track of it.&lt;br&gt;
&lt;a href="https://www.timeanddate.com/timer/" rel="noopener noreferrer"&gt;Timer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notebook 📔 to write important points which you need before interview for faster revision.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Of course a laptop 💻 for coding.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp7jm9djndvv1gnjwtex.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp7jm9djndvv1gnjwtex.jpg" alt="Image description" width="600" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;That's all, you are almost ready with your plan for this battle. This planning is almost took 2 hours&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Now the execution time *&lt;/em&gt; ⏰&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;June 21 (Fri)&lt;/strong&gt;: Introduction to arrays and strings, practice easy problems. (4 hours) &lt;/p&gt;

&lt;p&gt;So, on day 1 after planning everything I watch some lectures from my Udemy courses on Array &amp;amp; Strings from this course, this is for javascript developers, if you are looking for DSA in other language feel free to search on Udemy or other platform. This course cost me only INR 499 💰.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.udemy.com/share/1013ja3@8z3jnE8L7842ZCmS_vaEAdTJmJKxuxPyDvHeXHPejNI9tEGIqTlqmNy897xhr198/" rel="noopener noreferrer"&gt;Master the Coding Interview: Data Structures + Algorithms&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This video tutorial for Array &amp;amp; strings is covered within 1 hour with 1.25x speed on udemy.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Now its high time we start practising some leet code questions. ❓&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I solved these questions on leet code all are easy ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array 💣
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/majority-element/description/" rel="noopener noreferrer"&gt;Majority Element&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/contains-duplicate/description/" rel="noopener noreferrer"&gt;Contains Duplicate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/contains-duplicate-ii/description/" rel="noopener noreferrer"&gt;Contains Duplicate II&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/summary-ranges/description/" rel="noopener noreferrer"&gt;Summary Ranges&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/range-sum-query-immutable/" rel="noopener noreferrer"&gt;Range Sum Query - Immutable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/move-zeroes/description/" rel="noopener noreferrer"&gt;Move Zeroes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/missing-number/description/" rel="noopener noreferrer"&gt;Missing Numbers&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please try these questions. If you are not able to solve it don't worry try again.&lt;/p&gt;

&lt;p&gt;I want everyone to watch this video 📺 if you feel that you can't do it or if you have self doubt, please watch this video.&lt;br&gt;
&lt;a href="https://youtu.be/whyUPLJZljE?si=0TvdEDWfHugIsvXk" rel="noopener noreferrer"&gt;Must Watch&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always remember, your career is a marathon 🏃‍♂️, not a sprint.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>Frontend Interview Preparation</title>
      <dc:creator>Nishant Singh</dc:creator>
      <pubDate>Sat, 18 May 2024 10:12:51 +0000</pubDate>
      <link>https://forem.com/nishantsinghchandel/frontend-interview-preparation-cl</link>
      <guid>https://forem.com/nishantsinghchandel/frontend-interview-preparation-cl</guid>
      <description>&lt;p&gt;Just started my interview preparation for MAANG companies. I am going through lots of blogs and articles to list down topics which are important for interview preparation. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/eiOCuw6gfHc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Although this is my first post, I have never thought of writing any articles/blogs. But this will be a journey, where I can express my learnings. I have enrolled to some of Udemy courses to brush up my skills.&lt;/p&gt;

&lt;p&gt;Udemy Courses -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/share/103J3E3@lGhe63tthzCjlbb_qrv4o1bpyduzGIj2QQvz6y5dj_RKPjcxkqhXfwkuq9R-kptP/" rel="noopener noreferrer"&gt;Master the Coding Interview: Big Tech (FAANG) Interviews
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/share/101qSq3@qs7_Kw29fppho2ZPqqqPPUZPhldtfQIcc97j5Nkgf54PcJY3SWNXwdBurXDTCcUg/" rel="noopener noreferrer"&gt;Master the Coding Interview: Data Structures + Algorithms
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/share/104pm23@vqJrOf7cOYPvBDRPTCb42_KIGgvCE9B88RcqiVQdQLOmHeSeV631FIBXb3ab9mLa/" rel="noopener noreferrer"&gt;
JavaScript Data Structures &amp;amp; Algorithms + LEETCODE Exercises
&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Don't go for all courses at once, go for one or two, please checkout the sample video before enrolling to courses. These courses are not expensive as I have waited for price drop and single course cost me INR 500 only. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please don't be impulsive, buy only if you have interest in it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lj4r65lkbag8jjuo7b8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lj4r65lkbag8jjuo7b8.jpg" alt="Finding image" width="640" height="360"&gt;&lt;/a&gt;&lt;br&gt;
Here are some of my findings - &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WEB Concepts&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CRP (critical rendering path).&lt;/li&gt;
&lt;li&gt;Debouncing/Throttling&lt;/li&gt;
&lt;li&gt;Event Delegation/Bubbling.&lt;/li&gt;
&lt;li&gt;Bundle Splitting&lt;/li&gt;
&lt;li&gt;Preload, Pre connect, Prefetch, Prerender.&lt;/li&gt;
&lt;li&gt;Web Workers&lt;/li&gt;
&lt;li&gt;HTTP2&lt;/li&gt;
&lt;li&gt;Etag/Cache-Control Response Header&lt;/li&gt;
&lt;li&gt;Document Fragment.&lt;/li&gt;
&lt;li&gt;Reflow.&lt;/li&gt;
&lt;li&gt;Image compression.&lt;/li&gt;
&lt;li&gt;Memory Leak.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;WEB Security&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Transfer-encoding&lt;/li&gt;
&lt;li&gt;Same origin policy&lt;/li&gt;
&lt;li&gt;Access-Control-Allow-Origin&lt;/li&gt;
&lt;li&gt;CORS&lt;/li&gt;
&lt;li&gt;Content Security Policy.&lt;/li&gt;
&lt;li&gt;CSRF&lt;/li&gt;
&lt;li&gt;Referrer-Policy&lt;/li&gt;
&lt;li&gt;Inner HTML&lt;/li&gt;
&lt;li&gt;X-XSS Protection&lt;/li&gt;
&lt;li&gt;X-Frame Options&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;COMPONENTS&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Image Carousel&lt;/li&gt;
&lt;li&gt;Star Component (REVIEW 5 STAR)&lt;/li&gt;
&lt;li&gt;Comment Section&lt;/li&gt;
&lt;li&gt;Pagination&lt;/li&gt;
&lt;li&gt;Search Bar.&lt;/li&gt;
&lt;li&gt;Accordion.&lt;/li&gt;
&lt;li&gt;Navbar.&lt;/li&gt;
&lt;li&gt;Traffic Light&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Other Topics&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Web Components&lt;/li&gt;
&lt;li&gt;PWA (Progressive Web Apps)&lt;/li&gt;
&lt;li&gt;Micro frontend.&lt;/li&gt;
&lt;li&gt;Typescript.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Interview Preparation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.greatfrontend.com/" rel="noopener noreferrer"&gt;Frontend Interviews&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/h5bp/Front-end-Developer-Interview-Questions/blob/main/src/questions/javascript-questions.md" rel="noopener noreferrer"&gt;Front-end-Developer-Interview-Questions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://web.dev/learn" rel="noopener noreferrer"&gt;Web development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//javascript.info"&gt;JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Security" rel="noopener noreferrer"&gt;Web Security etc.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/getify/You-Dont-Know-JS" rel="noopener noreferrer"&gt;You-Dont-Know-JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/denysdovhan/wtfjs" rel="noopener noreferrer"&gt;Funny &amp;amp; Tricky JS questions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.bitsrc.io/10-javascript-design-patterns-3087d1dda5b4" rel="noopener noreferrer"&gt;10-javascript-design-patterns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ryanmcdermott/clean-code-javascript" rel="noopener noreferrer"&gt;clean-code-javascript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.greatfrontend.com/system-design" rel="noopener noreferrer"&gt;system-design&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One book which is recommended by one of my friend from Google for System Design is:&lt;br&gt;
&lt;a href="https://amzn.in/d/073PjfwU" rel="noopener noreferrer"&gt;Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apart from this DSA is very important to brush up your coding skill I will suggest start coding on Leet code. Adding some questions to start with - &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coding Websites&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://leetcode.com/" rel="noopener noreferrer"&gt;Leetcode&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.greatfrontend.com/prepare" rel="noopener noreferrer"&gt;Frontend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DSA Questions&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Array
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/majority-element/description/" rel="noopener noreferrer"&gt;Majority Element&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/contains-duplicate/description/" rel="noopener noreferrer"&gt;Contains Duplicate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/contains-duplicate-ii/description/" rel="noopener noreferrer"&gt;Contains Duplicate II&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/summary-ranges/description/" rel="noopener noreferrer"&gt;Summary Ranges&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Linked List
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/linked-list-cycle/description/" rel="noopener noreferrer"&gt;linked-list-cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/merge-two-sorted-lists/description/" rel="noopener noreferrer"&gt;Merge Two Sorted Lists&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/" rel="noopener noreferrer"&gt;Remove Duplicates from Sorted List&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/intersection-of-two-linked-lists/description/" rel="noopener noreferrer"&gt;Intersection of Two Linked Lists&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the above leetcode questions are solved from my end, I hope you will also try the same. If you can't solve it no problem. Learn it and try again. Never give up.&lt;/p&gt;

&lt;p&gt;These are my findings, but I know this is not enough for interview preparation for tier 1 companies. But it's just the beginning, I will continue to update the topics and also share the interview process. Feel free to comment if anything goes missed from my end. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always remember, your career is a marathon, not a sprint.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZT3yQE1zthU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Watch more content on our Youtube channel - &lt;a href="https://www.youtube.com/channel/UCBM2Z-kqN7ioFKeR_-iU0zA?sub_confirmation=1" rel="noopener noreferrer"&gt;Frontend With Chandel&lt;/a&gt;&lt;/p&gt;

</description>
      <category>faang</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
