<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prashant Yadav</title>
    <description>The latest articles on DEV Community by Prashant Yadav (@learnersbucket).</description>
    <link>https://dev.to/learnersbucket</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%2F150420%2F359a8b09-bd6c-4c7d-8b18-f0f76fef71d9.jpg</url>
      <title>DEV Community: Prashant Yadav</title>
      <link>https://dev.to/learnersbucket</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/learnersbucket"/>
    <language>en</language>
    <item>
      <title>Reactivity in JavaScript frameworks</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Sun, 23 Apr 2023 17:09:16 +0000</pubDate>
      <link>https://dev.to/learnersbucket/reactivity-in-javascript-frameworks-2fm3</link>
      <guid>https://dev.to/learnersbucket/reactivity-in-javascript-frameworks-2fm3</guid>
      <description>&lt;h2&gt;
  
  
  What is Reactivity?.
&lt;/h2&gt;

&lt;p&gt;The process in which the view of the application is automatically updated when the state changes are known as Reactivity.&lt;/p&gt;

&lt;p&gt;Let us see two different examples to understand Reactivity.&lt;/p&gt;

&lt;p&gt;In vanilla JavaScript, we will do something like this to update the view whenever the state changes.&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;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
  &amp;lt;button id="increment-btn"&amp;gt;Increment&amp;lt;/button&amp;gt;
  &amp;lt;span id="count-tracker"&amp;gt;0&amp;lt;/span&amp;gt;
  &amp;lt;button id="decrement-btn"&amp;gt;Decrement&amp;lt;/button&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;incrementBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#increment-btn&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;decrementBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#decrement-btn&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;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#count-tracker&lt;/span&gt;&lt;span class="dl"&gt;'&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;count&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;decrementBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;incrementBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;count&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;You see how after every state update &lt;code&gt;count--&lt;/code&gt; and &lt;code&gt;count++&lt;/code&gt;, we are manually updating the view &lt;code&gt;span.innerText = count&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But on the other hand in this React example,&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;function&lt;/span&gt; &lt;span class="nx"&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&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="mi"&gt;0&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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;Decrement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&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;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;Incremenet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;p&gt;The framework/library explicitly handles the view change under the hood giving us the freedom to focus more on the business logic and state management and build and ship things faster.&lt;/p&gt;

&lt;p&gt;Not only React but all the major JavaScript frontend frameworks abstract Reactivity, because this is the part where many frameworks do the performance optimization, for example using virtual DOM with Reconciliation (using an intelligent diffing algorithm to check what has changed in the view and updating only that elements).&lt;/p&gt;

&lt;p&gt;The most challenging thing for Reactivity is deciding &lt;strong&gt;WHEN&lt;/strong&gt; to update the view and &lt;strong&gt;WHAT&lt;/strong&gt; to update.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to update the View?
&lt;/h2&gt;

&lt;p&gt;There is no particular answer to when to update the view and each framework has a different implementation of Reactivity according to how the framework is developed, but the one thing that is common is that the update happens in batches.&lt;/p&gt;

&lt;p&gt;Frequent updates are very expensive and they will outthrow the complete purpose of creating the framework, otherwise same could have been done in the vanilla JavaScript.&lt;/p&gt;

&lt;p&gt;One way is how React does this is that it &lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript"&gt;debounces&lt;/a&gt; the updates and batches multiple updates together and this are done when the state updates, like in the component lifecycle event &lt;a href="https://blog.logrocket.com/using-react-useeffect-hook-lifecycle-methods/#updating-phase-shouldcomponentupdate-componentdidupdate"&gt;ShouldComponentUpdate&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the below example,&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;function&lt;/span&gt; &lt;span class="nx"&gt;Count&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&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;totalCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTotalCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onAddCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;count&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;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;counts&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;counts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nx"&gt;setTotalCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalCounts&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;totalCounts&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;p&gt;There are two state updates happening one after another, if the view is also updated synchronously then we will see there is a glitch (views will be changing one after the other) and the changes won’t reflect properly. (For this example, though it won’t be visible to the naked eye when you are doing the animation it will be visible.) That is why batch updates are important.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to update in the View?
&lt;/h2&gt;

&lt;p&gt;Now that we know &lt;strong&gt;WHEN&lt;/strong&gt; to update the view, let us see how to decide &lt;strong&gt;WHAT&lt;/strong&gt; to update.&lt;/p&gt;

&lt;p&gt;To decide &lt;strong&gt;WHAT&lt;/strong&gt; to update, we will have to track what has been changed, for primitive values, it is simple to track changes, but for Objects, it is hard, as Objects can be mutated after defining and we cannot freeze them as this beats all the purpose.&lt;/p&gt;

&lt;p&gt;Objects have to be extensible but still, there should be a way to track the mutation.&lt;/p&gt;

&lt;p&gt;For example,&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// getting property&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;getName&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="na"&gt;get&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&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="c1"&gt;// setting property&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;changeName&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="na"&gt;set&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&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;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prashant&lt;/span&gt;

&lt;span class="c1"&gt;// changing the property value&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;changeName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Prashant2&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prashant2&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Learnersbucket&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blog&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Learnersbucket&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here if you see, I have defined an object with a single property &lt;code&gt;firstName&lt;/code&gt; and I was able to get and set its value and it can be tracked, but when I added a new property &lt;code&gt;blog&lt;/code&gt;, I was not aware of it.&lt;/p&gt;

&lt;p&gt;To solve this we can use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy"&gt;Proxies&lt;/a&gt;. Using the Proxy object, we can build a proxy for another object that can intercept and alter its core activities.&lt;/p&gt;

&lt;p&gt;In simple terms, proxies will work as observers through which we can monitor what has changed in the object.&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Prashant&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;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is changed from &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt; to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&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;proxyPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Proxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;proxyPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Prashant 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// "firstName is changed from Prashant to Prashant 2"&lt;/span&gt;

&lt;span class="nx"&gt;proxyPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learnersbucket&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// "blog is changed from undefined to Learnersbucket"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is this that simple?, No! This is one way of handling mutation, not every framework does that, each one keeps on experimenting and uses many performant techniques, but this is one of tracking the mutation.&lt;/p&gt;

&lt;p&gt;Once the mutation is tracked, it is easier to decide what has changed and update only that part.&lt;/p&gt;

&lt;p&gt;I hope you now have a decent idea about Reactivity in front-end frameworks.&lt;/p&gt;




&lt;p&gt;I am author of the Ebook &lt;a href="https://learnersbucket.gumroad.com/l/javascript-interview-guide"&gt;JavaScript Interview Guide&lt;/a&gt;(860+ copies sold), if you are preparing for JavaScript Interview, do checkout the book.&lt;/p&gt;

&lt;p&gt;Also, You can follow me on &lt;a href="https://twitter.com/LearnersBucket"&gt;Twitter&lt;/a&gt; for tips and tricks to solve the coding interviews and more solved examples of Algorithms. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>⚡️ Use ChatGPT on any website 🔥</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Mon, 17 Apr 2023 11:36:52 +0000</pubDate>
      <link>https://dev.to/learnersbucket/use-chatgpt-on-any-website-5h6</link>
      <guid>https://dev.to/learnersbucket/use-chatgpt-on-any-website-5h6</guid>
      <description>&lt;p&gt;A few days back I created &lt;a href="https://learnersbucket.gumroad.com/l/butler-ai"&gt;Butler-AI&lt;/a&gt; that allows you to use the ChatGPT on any website by simply typing the command &lt;strong&gt;“butler: whatever you want to do;”&lt;/strong&gt;. It is a Chrome extension and works like a charm on many different websites.&lt;/p&gt;

&lt;p&gt;You can see how it works in the following image.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X2oozQ4X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://i0.wp.com/learnersbucket.com/wp-content/uploads/2023/04/ezgif.com-video-to-gif2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X2oozQ4X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://i0.wp.com/learnersbucket.com/wp-content/uploads/2023/04/ezgif.com-video-to-gif2.gif" alt="Butler-AI powered by ChatGPT" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After receiving an overwhelming response to it, I decided to create a simple tutorial around this on how it works and how you can create a similar extension of your own.&lt;/p&gt;

&lt;p&gt;So let’s get started.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup the chrome extension
&lt;/h2&gt;

&lt;p&gt;Chrome currently suggests using the &lt;a href="https://developer.chrome.com/docs/extensions/mv3/intro/"&gt;Manifest V3&lt;/a&gt; to define any extension and we are going to use the same. &lt;code&gt;manifest.json&lt;/code&gt; is the config file that defines any Chrome extension.&lt;/p&gt;

&lt;p&gt;Define a &lt;code&gt;manifest.json&lt;/code&gt; in your directory and inside that add the following things.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Butler AI - Powered by ChatGPT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Use the power of ChatGPT at your fingertips, The butler will serve its master."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Prashant Yadav"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"manifest_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"storage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"activeTab"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"host_permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"default_popup"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"popup.html"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"content_scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"matches"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"runAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"document_end"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"js"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"script.js"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"all_frames"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many things are self-explanatory, let’s do a walkthrough of the important properties.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;permissions&lt;/strong&gt;: This defines all things this Chrome extension will have access to, we want access to the &lt;code&gt;activeTab&lt;/code&gt; to observe what is being written in the command and respond to that and &lt;code&gt;storage&lt;/code&gt; to access the localStorage and store some secrets like ChatGPT API key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;action&lt;/strong&gt;: default_popup: The default HTML page that opens when you click on the ICON of the extension.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;content_scripts&lt;/strong&gt;: This defines which javascript file to load when a new tab opens and when to run this. Basically, we will open the &lt;code&gt;script.js&lt;/code&gt; on the &lt;code&gt;document_end&lt;/code&gt; (when page load is complete) and for all the URLs &lt;code&gt;all_urls&lt;/code&gt; in all the frames &lt;code&gt;Iframes&lt;/code&gt; as well. Inside this &lt;code&gt;script.js&lt;/code&gt; our all logic will be present.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  popup.html
&lt;/h3&gt;

&lt;p&gt;Written a simple message just to make sure &lt;code&gt;popup.html&lt;/code&gt; is loading properly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"IE=edge"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Butler AI&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Butler AI Powered By ChatGPT&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  script.js
&lt;/h3&gt;

&lt;p&gt;Printing a message to check if the script is being properly injected or not.&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ButlerAI&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;h3&gt;
  
  
  Load the Chrome extension
&lt;/h3&gt;

&lt;p&gt;Now that our boilerplate is ready, let’s load the extension and see if it working fine or not.&lt;/p&gt;

&lt;p&gt;Remember that we will have to load this on developer mode on the local machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the Chrome browser.&lt;/li&gt;
&lt;li&gt;Go to settings &amp;gt; extensions.&lt;/li&gt;
&lt;li&gt;Enable the Developer mode on right handside top corner.&lt;/li&gt;
&lt;li&gt;Click on Load unpacked button on the left handside top corner.&lt;/li&gt;
&lt;li&gt;Navigate and load your directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you have loaded the extension, open a new tab and navigate to &lt;a href="https://stackedit.io/app"&gt;StackEdit&lt;/a&gt; and in the console, the message &lt;code&gt;ButlerAI&lt;/code&gt; should be printed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Observe the text being written on any webpage
&lt;/h2&gt;

&lt;p&gt;For this tutorial, I am going to run this extension on the &lt;a href="https://stackedit.io/app"&gt;StackEdit&lt;/a&gt; which is a popular markdown editor. Now that the extension is loaded, inside the &lt;code&gt;script.js&lt;/code&gt; we will have to observe what the user is typing and find if anything in the context &lt;strong&gt;butler: whatever is the command;&lt;/strong&gt; is written or not.&lt;/p&gt;

&lt;p&gt;To do this, we will listen to the keypress event on the whole window (activeTab) and when the user stops typing, we will parse the HTML and look for any text that starts with &lt;strong&gt;butler&lt;/strong&gt; and ends with &lt;strong&gt;;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Observe what the user is typing on the active tab
&lt;/h3&gt;

&lt;p&gt;This we will do on the &lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript"&gt;debounced&lt;/a&gt; event because we want to search only when a user stops typing, thus debouncing is a good thing to do.&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="c1"&gt;// helper function to debounce function calls&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&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;inDebounce&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&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;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&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;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;inDebounce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&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="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&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="c1"&gt;// debounced function call&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;debouncedScrapText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scrapText&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="c1"&gt;// observe what the user is typing&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keypress&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;debouncedScrapText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the &lt;code&gt;scrapText&lt;/code&gt; function will be debounced after 1000 milliseconds that is if the user stopped typing for 1 second then only the function &lt;code&gt;scrapText&lt;/code&gt; will be invoked.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding text that starts with butler
&lt;/h3&gt;

&lt;p&gt;We will have to first collect all the text from the page and then check which text starts with &lt;strong&gt;butler:&lt;/strong&gt; and ends with &lt;strong&gt;;&lt;/strong&gt;. If any such text is found then we will store the HTML node that contains this text so that we will populate it back with the response of the command and also extract the command.&lt;/p&gt;

&lt;p&gt;To narrow down the search, rather than parsing the whole page, we will only parse the HTML element that accepts text. For example where the user can type or provide input.&lt;/p&gt;

&lt;p&gt;On the StackEdit the area where the user can write has the attribute &lt;code&gt;contenteditable="true"&lt;/code&gt; thus we can get this element and get its text and parse them.&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="c1"&gt;// regex to check the text is in the form "butler: command;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getTextParsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&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;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/butler:&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;?)\;&lt;/span&gt;&lt;span class="sr"&gt;/gi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&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;parsed&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;parsed&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="p"&gt;:&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="c1"&gt;// helper function to get the nodes, extract their text &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getTextContentFromDOMElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;textarea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;nodes&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&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;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;node&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;nodes&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;textarea&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&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;node&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;value&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getTextParsed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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;text&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="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;return&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// function to find the text on active tab&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scrapText&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ele&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[contenteditable="true"]&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;parsedValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getTextContentFromDOMElements&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ele&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;parsedValue&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;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;parsedValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;makeChatGPTCall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;node&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;Here we are getting all the HTML elements, extracting their text, and checking if they are matching the pattern we are expecting, once they match, we get that node (HTML element) and the command.&lt;/p&gt;

&lt;p&gt;Different websites have different ways of accepting input, thus you will see that I am checking if the node is of type &lt;code&gt;textarea&lt;/code&gt; or not and getting its value accordingly.&lt;/p&gt;

&lt;p&gt;Once we have them we are passing them forward to make the ChatGPT API call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the command response with ChatGPT API
&lt;/h2&gt;

&lt;p&gt;Create this function that will accept the command and the node and populate the node with the response from the ChatGPT API for this command.&lt;/p&gt;

&lt;p&gt;We are going to use the &lt;a href="https://platform.openai.com/docs/api-reference/completions"&gt;completions API of ChatGPT&lt;/a&gt; with the &lt;a href="https://platform.openai.com/docs/models/gpt-3-5"&gt;text-davinci-003&lt;/a&gt; model. You can use any of the APIs and Models as per your preference, but remember you have limited tokens in the free tier so make a note of it while testing to not exhaust the limit. Explore your choice through this &lt;a href="https://platform.openai.com/playground"&gt;ChatGPT playground&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You will have to pass your API key in the Authorization headers to make it work.&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;makeChatGPTCall&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="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;node&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;myHeaders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;myHeaders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;myHeaders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;apikey&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// set request payload&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-davinci-003&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;max_tokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;temperature&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="na"&gt;top_p&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="na"&gt;n&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="na"&gt;stream&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="na"&gt;logprobs&lt;/span&gt;&lt;span class="p"&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="c1"&gt;// set request options&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;myHeaders&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;follow&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="c1"&gt;// make the api call&lt;/span&gt;
    &lt;span class="kd"&gt;let&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;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.openai.com/v1/completions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;requestOptions&lt;/span&gt;&lt;span class="p"&gt;);&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&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;choices&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// remove the spaces from the reponse text&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nx"&gt;choices&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="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+|&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+$/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// populate the node with the response&lt;/span&gt;
    &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&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;e&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error while calling openai api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&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;p&gt;That’s it, reload the extension and see the magic, it should work like a charm on &lt;a href="https://stackedit.io/app#"&gt;StackEdit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The most challenging part of this extension is reading the values from different websites as a user writes and then populating back them with the response. For security purposes, websites do many internal things and block the updation of value by just changing the content through javascript.&lt;/p&gt;

&lt;p&gt;I made this work on many websites. You can get the source code of &lt;a href="https://learnersbucket.gumroad.com/l/butler-ai"&gt;Butler-AI for $10&lt;/a&gt;, but I leave it up to you, to try and make it work on as many websites as possible.&lt;/p&gt;

&lt;p&gt;You can also watch the tutorial on my &lt;a href="https://youtu.be/rtPakstkxV4"&gt;youtube channel&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Also, follow me on  &lt;a href="https://twitter.com/LearnersBucket"&gt;Twitter&lt;/a&gt; for tips and tricks to solve the coding interviews and more solved examples of Algorithms. I write 2 - 3 post weekly on my blog &lt;a href="https://learnersbucket.com"&gt;learnersbucket.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React interview question - Detect overlapping circles</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Fri, 09 Dec 2022 09:54:28 +0000</pubDate>
      <link>https://dev.to/learnersbucket/react-interview-question-detect-overlapping-circles-4l2i</link>
      <guid>https://dev.to/learnersbucket/react-interview-question-detect-overlapping-circles-4l2i</guid>
      <description>

&lt;blockquote&gt;
&lt;p&gt;I have written an Ebook that has 100 JavaScript, 20 React, &amp;amp; 2 Frontend system design questions. Get a &lt;a href="https://drive.google.com/file/d/1XWBItcsxD55S8GR2bWRkrxum0yNtfcym/view?usp=sharing"&gt;free preview&lt;/a&gt; or &lt;a href="https://learnersbucket.com/javascript-interview-guide-ebook/?epc_purge_single=1"&gt;grab your copy for $10 or ₹599&lt;/a&gt;.&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;I have been collecting frontend interview questions since the last 4 years and have been writing about it on my blog &lt;a href="https://learnersbucket.com"&gt;learnersbucket.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lately I have came across this interesting question that has been asked in an &lt;a href="https://leetcode.com/discuss/interview-question/1784074/Uber-or-Phone-or-Overlapping-circles-app-or-Reject"&gt;Uber interview&lt;/a&gt; and I tried to solve it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Question
&lt;/h2&gt;

&lt;p&gt;Draw circles on the screen on the click and whenever two circles overlap change the color of the second circle.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a user clicks anywhere on the DOM, create a circle around it of a radius of 100px with red background.&lt;/li&gt;
&lt;li&gt;If two or more circles overlap, change the background of the later circle.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;Let us understand the logic of creating the circle first.&lt;/p&gt;

&lt;p&gt;As we have to create the circle with a radius of 100px (200px diameter), rather than generating the circle on the click, we will store the coordinates of the position where the circle should be generated when the user clicks and then create circles out of these co-ordinates.&lt;/p&gt;

&lt;p&gt;As all the circles will be in absolute position so that they can be freely placed on the screen, we will calculate the &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;bottom&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;, and &lt;code&gt;right&lt;/code&gt; positions that will help in placement as well as detecting if two circles are colliding.&lt;/p&gt;

&lt;p&gt;Get the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX"&gt;clientX&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientY"&gt;clientY&lt;/a&gt; coordinates when the user clicks and align the circle around with a simple calculation so that it is placed in the center. Also before updating the state check if the current circle is overlapping with the existing circles then update the background color of the current.&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="c1"&gt;// helper function to gather configuration when user clicks&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;draw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="c1"&gt;// get the co-ordinates where user has clicked&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;clientX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// decide the position where circle will be created and placed&lt;/span&gt;
  &lt;span class="c1"&gt;// as the circle is of 100 radius (200 diameter), we are subtracting the values&lt;/span&gt;
  &lt;span class="c1"&gt;// so that circle is placed in the center&lt;/span&gt;
  &lt;span class="c1"&gt;// set the initial background color to red&lt;/span&gt;
  &lt;span class="nx"&gt;setElementsCoordinates&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prevState&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;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&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="c1"&gt;// before making the new entry&lt;/span&gt;
    &lt;span class="c1"&gt;// check with the exisitng circles&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="nx"&gt;prevState&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="c1"&gt;// if the current circle is colliding with any existing&lt;/span&gt;
      &lt;span class="c1"&gt;// update the background color of the current&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;elementsOverlap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prevState&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="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;background&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getRandomColor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;break&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="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&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;p&gt;Assign the event listener and draw the circle on the click.&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="c1"&gt;// assign the click event&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;draw&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;draw&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Helper function to detect collision and generate random colors.&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="c1"&gt;// helper function to generate a random color&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getRandomColor&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;letters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0123456789ABCDEF&lt;/span&gt;&lt;span class="dl"&gt;"&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;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&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="mi"&gt;6&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="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;letters&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;16&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;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// helper function to detect if two elements are overlapping&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;elementsOverlap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rect2&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;collide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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;collide&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;Generate the circles from the coordinates which we have stored after the user has clicked. As the detection is done before making entry into the state, the circles are generated with different colors if they will be colliding.&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="c1"&gt;// circle element&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;background&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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;absolute&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;borderRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;50%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0.5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;background&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* render each circle */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elementsCoordinates&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="nx"&gt;e&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Circle&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;))}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Putting everything together.&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;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="c1"&gt;// helper function to generate a random color&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getRandomColor&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;letters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0123456789ABCDEF&lt;/span&gt;&lt;span class="dl"&gt;"&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;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&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="mi"&gt;6&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="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;letters&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;16&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;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// helper function to detect if two elements are overlapping&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;elementsOverlap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rect2&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;collide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="nx"&gt;rect1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rect2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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;collide&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;Example&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="c1"&gt;// store the configuration of each circle&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;elementsCoordinates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setElementsCoordinates&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="c1"&gt;// helper function to gather configuration when user clicks&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;draw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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="c1"&gt;// get the co-ordinates where user has clicked&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;clientX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// decide the position where circle will be created and placed&lt;/span&gt;
    &lt;span class="c1"&gt;// as the circle is of 100 radius (200 diameter), we are subtracting the values&lt;/span&gt;
    &lt;span class="c1"&gt;// so that circle is placed in the center&lt;/span&gt;
    &lt;span class="c1"&gt;// set the initial background color to red&lt;/span&gt;
    &lt;span class="nx"&gt;setElementsCoordinates&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prevState&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;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&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="c1"&gt;// before making the new entry&lt;/span&gt;
      &lt;span class="c1"&gt;// check with the exisitng circles&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="nx"&gt;prevState&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="c1"&gt;// if the current circle is colliding with any existing&lt;/span&gt;
        &lt;span class="c1"&gt;// update the background color of the current&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;elementsOverlap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prevState&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="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;background&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getRandomColor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="k"&gt;break&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="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&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="c1"&gt;// assign the click event&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;draw&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;draw&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="c1"&gt;// circle element&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;background&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="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
          &lt;span class="na"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;absolute&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;borderRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;50%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0.5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nx"&gt;background&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* render each circle */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elementsCoordinates&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="nx"&gt;e&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Circle&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&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;Example&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eprhlIJA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/learnersbucket.com/wp-content/uploads/2022/11/collision.jpg%3Fw%3D1709%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eprhlIJA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/learnersbucket.com/wp-content/uploads/2022/11/collision.jpg%3Fw%3D1709%26ssl%3D1" alt="Detect overlapping circles" width="800" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>JavaScript SDE Cheat Sheet</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Mon, 09 May 2022 07:21:40 +0000</pubDate>
      <link>https://dev.to/learnersbucket/javascript-sde-cheat-sheet-4h2</link>
      <guid>https://dev.to/learnersbucket/javascript-sde-cheat-sheet-4h2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I am currently running #250DaysOfJSQuestions on twitter where I share one JavaScript interview questions daily, follow me on twitter &lt;a href="https://twitter.com/LearnersBucket"&gt;@learnersbucket&lt;/a&gt; for web dev and interview related content.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In 2019 January, during the lockdown, I had started solving problems in JavaScript and writing articles on it on my blog, over the time I have solved 300+ problems. This cheat sheet contains list of problem that can be asked to a JavaScript dev.&lt;/p&gt;

&lt;p&gt;This is a curated list of solved problems in JavaScript categorized on the type &amp;amp; nature of the problem which you can refer to and use as a cheat sheet for interview preparation.&lt;/p&gt;

&lt;p&gt;It contains Data Structures &amp;amp; Algorithms, functions, async, closure, &amp;amp; hoisting-related problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  DataStructures
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/array/javascript-array-complete-reference"&gt;Javascript array: Complete reference.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/javascript-objects-complete-reference"&gt;Javascript Objects: Complete Reference.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/javascript-string"&gt;Javascript String: Complete Reference.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/stack"&gt;Implement Stack data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/queue-implementation-in-javascript"&gt;Queue data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/list-data-structure-in-javascript"&gt;List data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/linked-list-implementation-in-javascript"&gt;Linked list data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/implement-stack-using-linked-list"&gt;Implement stack using linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/implement-queue-using-linked-list"&gt;Implement queue using linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/doubly-linked-list-implementation-in-javascript"&gt;Doubly linked list implementation in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/implement-deque-data-structure-in-javascript"&gt;Implement deque data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/deque-data-structure-with-doubly-linked-list"&gt;Deque data structure with doubly linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/circular-linked-list-implementation-in-javascript"&gt;Circular linked list implementation in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/circular-doubly-linked-list-in-javascript"&gt;Circular Doubly linked list in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/priority-queue-implementation-in-javascript"&gt;Priority Queue Implementation in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/tree-data-structure-in-javascript"&gt;Tree data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/array/heap-data-structure-in-javascript"&gt;Heap data structure in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/treap-data-structure-in-javascript"&gt;Treap data structure in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/trie-data-structure-in-javascript"&gt;Trie data structure in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/javascript-graph-data-structure"&gt;Javascript graph data structure.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/data-structures/avl-tree-in-javascript"&gt;AVL Tree in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Algorithms
&lt;/h3&gt;

&lt;p&gt;It contains only the important ones, you can checkout the whole list &lt;a href="https://learnersbucket.com/examples/topics/algorithms/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/balanced-parentheses"&gt;Implement Stack data structure in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/subarrays-with-a-given-sum-k-in-an-array"&gt;Print all subarrays with a given sum k in an array.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/program-to-check-if-a-subarray-with-0-sum-exits-or-not"&gt;Program to check if a subarray with 0 sum exits or not.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-distinct-ways-to-climb-the-stairs-in-javascript"&gt;Find distinct ways to climb the stairs in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/caesar-cipher-in-javascript"&gt;Caesar Cipher in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/count-all-substrings-having-character-k"&gt;Count all substrings having character k.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/number-of-subarrays-with-given-sum-k"&gt;Number of subarrays with given sum k.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/implement-a-stack-using-queue"&gt;Implement a Stack using Queue.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/implement-queue-using-two-stack"&gt;Implement queue using two stack.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/learn-how-to-implement-two-stack-with-an-array"&gt;Learn how to implement two stack with an array.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/alternatively-merge-two-different-arrays"&gt;Alternatively merge two different arrays.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/implement-stack-with-max-and-min-function"&gt;Implement stack with max and min function.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/merge-two-sorted-linked-list"&gt;Merge two sorted linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/how-to-find-loop-in-linked-list"&gt;How to find loop in linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-height-and-width-of-binary-tree"&gt;Find height and width of binary tree.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/tree-traversal-in-javascript"&gt;Tree traversal in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/flood-fill-algorithm-in-javascript"&gt;Flood fill algorithm in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-longest-palindrome-in-a-string"&gt;Find longest palindrome in a string.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-all-anagrams-substring-in-a-string"&gt;Find all anagrams substring in a string.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-the-largest-sum-of-contiguous-subarray"&gt;Find the largest sum of contiguous subarray.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/check-if-binary-tree-has-path-sum"&gt;Check if binary tree has path sum.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/rotate-matrix-90-degrees-clockwise-and-anti-clockwise"&gt;Rotate matrix 90 degrees clockwise and anti-clockwise.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-the-intersection-point-of-two-linked-list"&gt;Find the intersection point of two linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/trapping-rain-water-in-javascript"&gt;Trapping rain water in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/diagonal-traversal-of-binary-tree"&gt;Diagonal traversal of binary tree.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/check-if-binary-tree-is-symmetric"&gt;Check if binary tree is symmetric.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-floor-and-ceil-of-binary-search-tree"&gt;Find floor and ceil of binary search tree.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-least-common-ancestor-lca-of-binary-tree"&gt;Find Least Common Ancestor (LCA) of binary tree.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-kth-smallest-and-largest-element-in-bst"&gt;Find kth smallest and largest element in BST.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/serialize-and-deserialize-binary-tree"&gt;Serialize and Deserialize Binary Tree.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-inorder-successor-of-a-given-key-in-a-bst"&gt;Find inorder successor of a given key in a BST.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/find-inorder-predecessor-of-a-given-key-in-a-bst"&gt;Find inorder predecessor of a given key in a BST.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/n-meetings-in-one-room"&gt;N meetings in one room.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/knapsack-problem-in-javascript"&gt;knapsack problem in Javascript (Bounded &amp;amp; Unbounded).&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/lru-cache-in-javascript"&gt;LRU cache in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/fractional-knapsack-problem"&gt;Fractional knapsack problem.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/longest-common-subsequence"&gt;Longest Common Subsequence.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/longest-repeated-subsequence"&gt;Longest repeated subsequence.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/longest-consecutive-sequence"&gt;Longest Consecutive Sequence.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/deepest-leaves-sum-of-binary-tree"&gt;Deepest leaves sum of binary tree.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Sorting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/selection-sort-in-javascript"&gt;Selection sort in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/javascript/dutch-national-flag-problem"&gt;Dutch national flag problem.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/bubble-sort-algorithm-in-javascript"&gt;Bubble sort algorithm in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/recursive-bubble-sort-algorithm"&gt;Recursive Bubble sort algorithm.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/insertion-sort-algorithm-in-javascript"&gt;Insertion sort algorithm in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/recursive-insertion-sort-algorithm"&gt;Recursive Insertion Sort Algorithm.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/sorting-a-linked-list"&gt;Sorting a linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/bubble-sort-using-two-stacks"&gt;Bubble sort using two stacks.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/merge-sort-javascript"&gt;Merge sort in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/iterative-merge-sort-algorithm"&gt;Iterative merge sort algorithm.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/merge-sort-a-linked-list"&gt;Merge sort a linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/quick-sort-algorithm-javascript"&gt;Quick sort algorithm in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/quick-sort-iterative"&gt;Quick sort Iterative.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/quick-sort-using-linked-list"&gt;Quick sort using linked list.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/heap-sort-algorithm-in-javascript"&gt;Heap sort algorithm in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/iterative-heap-sort-in-javascript"&gt;Iterative heap sort in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/counting-sort-algorithm-in-javascript"&gt;Counting Sort Algorithm In Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/radix-sort-algorithm-in-javascript"&gt;Radix sort algorithm in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/bucket-sort-algorithm"&gt;Bucket Sort Algorithm.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/algorithms/shell-sort-algorithm-in-javascript"&gt;Shell Sort Algorithm In Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Searching
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/linear-search"&gt;Linear search algorithm in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/binary-search-in-javascript"&gt;Binary search in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/implement-iterative-binary-search"&gt;Binary search in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/algorithms/search-in-a-sorted-rotated-array"&gt;Search in a sorted rotated array.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  JavaScript specific problems.
&lt;/h3&gt;

&lt;p&gt;I am currently working on this list, these are few random questions, you can find the full list &lt;a href="https://learnersbucket.com/examples/topics/interview/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/how-to-merge-objects-in-javascript"&gt;How to merge objects in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/array/compare-two-array-or-object-with-javascript"&gt;Compare two array or object with JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript"&gt;What is debouncing in javascript?.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/what-is-throttling-in-javascript"&gt;What is throttling in javascript?.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/number-increment-counter-in-javascript-react"&gt;Number increment counter in Javascript (React).&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/detect-idle-state-inactive-in-javascript"&gt;Detect idle state (inactive) in Javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/deep-flatten-object-in-javascript-1"&gt;Deep flatten object in Javascript – 1.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/currying-in-javascript-part-1"&gt;Currying in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/capture-product-visible-on-viewport-when-user-stops-scrolling"&gt;Capture product visible on viewport when user stops scrolling.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/animate-elements-in-a-sequence"&gt;Animate elements in a sequence.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/create-pausable-auto-incrementer"&gt;Create Pausable auto incrementer.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/implement-clearalltimeout-in-javascript"&gt;Implement clearAllTimeout in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/implement-clearallinterval-in-javascript"&gt;Implement ClearAllInterval in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/singleton-design-pattern-in-javascript"&gt;Singleton design pattern in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/observer-design-pattern-in-javascript"&gt;Observer design pattern in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/remove-cycle-from-the-object-in-javascript"&gt;Remove cycle from the object in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/execute-async-functions-in-series"&gt;Execute async functions in Series.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/retry-promises-n-number-of-times-in-javascript"&gt;Retry promises N number of times in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/examples/interview/in-memory-filesystem-library-in-javascript"&gt;In-memory filesystem library in JavaScript.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  JavaScript projects.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/create-simple-calculator-with-javascript"&gt;Create simple calculator with javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/whack-a-mole-game-in-javascript"&gt;Whack a mole game in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/rock-paper-scissor-lizard-spock-game-in-javascript"&gt;Rock, Paper, Scissor, Lizard, Spock game in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/eye-follow-cursor-in-javascript"&gt;Eye follow cursor in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/text-typing-effect-in-javascript"&gt;Text typing effect in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/word-falling-effect-in-javascript"&gt;Word falling effect in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/day-night-toggle-switch-in-javascript"&gt;Day night toggle switch in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/user-profile-viewer-in-javascript"&gt;Day night toggle switch in javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/roman-to-numeral-converter-javascript"&gt;Roman to numeral converter javascript.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://learnersbucket.com/tutorials/js-projects/tic-tac-toe-game-in-javascript-with-bot"&gt;Tic tac toe game in javascript with bot.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More questions will be added to it as and when I write them.&lt;/p&gt;

</description>
      <category>learnersbucket</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to merge objects in javascript</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Mon, 02 May 2022 10:50:45 +0000</pubDate>
      <link>https://dev.to/learnersbucket/how-to-merge-objects-in-javascript-5cil</link>
      <guid>https://dev.to/learnersbucket/how-to-merge-objects-in-javascript-5cil</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a series of #250DaysOfJSQuestions that I had started on twitter where I share one JavaScript interview question daily, follow me on twitter &lt;a href="https://twitter.com/LearnersBucket"&gt;@learnersbucket&lt;/a&gt; for web dev and interview related content.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt;. Learn how to merge two or more &lt;a href="https://learnersbucket.com/tutorials/data-structures/javascript-objects-complete-reference"&gt;objects&lt;/a&gt; in javascript. &lt;/p&gt;

&lt;p&gt;Almost everything in javascript is object, but still it does not have any good methods to merge two or more different objects. &lt;/p&gt;

&lt;p&gt;After &lt;a href="https://learnersbucket.com/tutorials/es6/es6-intro"&gt;ES6&lt;/a&gt; there are new methods added which can be used to merge objects in javascript. &lt;/p&gt;

&lt;p&gt;There are two different types of merge that can be performed on the objects. &lt;/p&gt;

&lt;p&gt;1). Shallow merge &lt;br&gt;
2). Deep merge&lt;/p&gt;
&lt;h2&gt;
  
  
  Shallow Merge objects
&lt;/h2&gt;

&lt;p&gt;In shallow merge only the properties owned by the object will be merged, it will not merge the extended properties or methods.&lt;/p&gt;
&lt;h3&gt;
  
  
  Using &lt;code&gt;...&lt;/code&gt; &lt;a href="https://learnersbucket.com/tutorials/es6/spread-and-rest-operators-in-javascript"&gt;spread&lt;/a&gt; operator
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;...&lt;/code&gt; spread operators copies all the properties of the objects into another object.&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;let&lt;/span&gt; &lt;span class="nx"&gt;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&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;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;qualification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BSC CS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;loves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&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;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj2&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  qualification: "BSC CS"
}
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"&gt;Object.assign()&lt;/a&gt; method
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Object.assign(target, source1, soure2, ...)&lt;/code&gt; method copies all the enumerable own property of source object to target object and returns the target object.&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;let&lt;/span&gt; &lt;span class="nx"&gt;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&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;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;qualification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BSC CS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;loves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&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;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt; &lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  qualification: "BSC CS"
}
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have used an empty object &lt;code&gt;{}&lt;/code&gt; as a target and passed the sources objects which should be merged in target.&lt;/p&gt;




&lt;h3&gt;
  
  
  Using custom function to merge objects
&lt;/h3&gt;

&lt;p&gt;We can also create custom function to merge two or more objects.&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;let&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="c1"&gt;// Create a new object&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="c1"&gt;// Merge the object into the target object&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;merger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&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;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;prop&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;obj&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;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Push each value from 'obj' into 'target'&lt;/span&gt;
     &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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="c1"&gt;// Loop through each object and conduct a merge&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="nx"&gt;arguments&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="nx"&gt;merger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&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;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&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;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;qualification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BSC CS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;loves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&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;merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merged&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  qualification: "BSC CS"
}
*/&lt;/span&gt;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Deep Merge Objects
&lt;/h2&gt;

&lt;p&gt;To deep merge an object we have to copy the own properties and extended properties as well, if it exits. The best way to do so is to create a custom function.&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;let&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="c1"&gt;// Variables&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="c1"&gt;// Merge the object into the target object&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;merger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&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;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;prop&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;obj&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;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prop&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="nb"&gt;Object&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;toString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[object Object]&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="c1"&gt;// If we're doing a deep merge and the property is an object&lt;/span&gt;
        &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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="c1"&gt;// Otherwise, do a regular merge&lt;/span&gt;
        &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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="p"&gt;};&lt;/span&gt;

 &lt;span class="c1"&gt;//Loop through each object and conduct a merge&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="nx"&gt;arguments&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="nx"&gt;merger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&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;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;nature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;helping&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;shy&lt;/span&gt;&lt;span class="dl"&gt;"&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;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;qualification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BSC CS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;loves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;nature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;angry&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;shy&lt;/span&gt;&lt;span class="dl"&gt;"&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="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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  nature: Object {
    angry: false,
    helping: true,
    shy: true
  },
  qualification: "BSC CS"
}
*/&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We can combine both the function for shallow copy and deep copy together to create a single function which will perform merge based on the arguments passed. &lt;/p&gt;

&lt;p&gt;If we will pass &lt;code&gt;true&lt;/code&gt; as first argument then it will perform deep merge else it will perform shallow merge.&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;let&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="c1"&gt;// Variables&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&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;deep&lt;/span&gt; &lt;span class="o"&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;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="c1"&gt;// Check if a deep merge&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;boolean&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;deep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arguments&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="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="c1"&gt;// Merge the object into the target object&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;merger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&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;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;prop&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;obj&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;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prop&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;deep&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;Object&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;toString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[object Object]&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="c1"&gt;// If we're doing a deep merge and the property is an object&lt;/span&gt;
                &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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="c1"&gt;// Otherwise, do a regular merge&lt;/span&gt;
                &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;prop&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="p"&gt;};&lt;/span&gt;

   &lt;span class="c1"&gt;//Loop through each object and conduct a merge&lt;/span&gt;
   &lt;span class="k"&gt;for&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="nx"&gt;arguments&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="nx"&gt;merger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&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;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prashant&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;nature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;helping&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;shy&lt;/span&gt;&lt;span class="dl"&gt;"&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;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;qualification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BSC CS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;loves&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;nature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;angry&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;shy&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//Shallow merge&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  nature: Object {
    angry: false,
    shy: true
  },
  qualification: "BSC CS"
}
*/&lt;/span&gt;

&lt;span class="c1"&gt;//Deep merge&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;merge&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="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="cm"&gt;/*
Object {
  age: 23,
  loves: "Javascript",
  name: "prashant",
  nature: Object {
    angry: false,
    helping: true,
    shy: true
  },
  qualification: "BSC CS"
}
*/&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;There are other libraries available which you can use to merge or two objects like&lt;/p&gt;

&lt;h3&gt;
  
  
  Jquery's &lt;a href="https://api.jquery.com/jQuery.extend/#jQuery-extend-target-object1-objectN"&gt;$.extend()&lt;/a&gt; method
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;$.extend(deep, copyTo, copyFrom)&lt;/code&gt; can be used to make a complete deep copy of any array or object in javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lodash &lt;a href="https://www.npmjs.com/package/lodash.merge"&gt;merge()&lt;/a&gt; method
&lt;/h3&gt;

&lt;p&gt;which will merge objects and arrays by performing deep merge recursively.&lt;/p&gt;

</description>
      <category>250daysofjsquestions</category>
      <category>learnersbucket</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Frontend System Design - Capture product visible on viewport when user stops scrolling.</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Sun, 26 Sep 2021 11:01:28 +0000</pubDate>
      <link>https://dev.to/learnersbucket/frontend-system-design-capture-product-visible-on-viewport-when-user-stops-scrolling-2he5</link>
      <guid>https://dev.to/learnersbucket/frontend-system-design-capture-product-visible-on-viewport-when-user-stops-scrolling-2he5</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your JavaScript interview. You will find DSA, System Design and JavaScript Questions.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;This system design question was asked to one of my linkedin connection in &lt;a href="https://www.nobroker.in/careers" rel="noopener noreferrer"&gt;NoBroker’s&lt;/a&gt; interview. When he approached me regarding the solution of this. It immediately caught my attention and I solved this problem that day itself.&lt;/p&gt;

&lt;p&gt;As it is an interesting problem I thought of writing an article around it, so here it is.&lt;/p&gt;

&lt;p&gt;The question was quoted as &lt;strong&gt;“If user scroll and see any property and stays there for more than 5 sec then call API and store that property”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Apart from online real-estate platform, this can be also applied on others platforms as well, such as social media like Facebook where if users reads a post for few seconds, store and use it to provide recommendations of new posts. Same can be used on E-commerce platform or other platforms where products are listed.&lt;/p&gt;

&lt;p&gt;Let us see how should we approach such problems and then solve it with an example. I have created a dummy HTML template which contains different blocks, which we can use for testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"IE=edge"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;.wrapper&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;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;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;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;.blocks&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;300px&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;300px&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;inline-flex&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;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;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&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="no"&gt;red&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;40px&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="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;4&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;5&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;6&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;7&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;8&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;9&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;10&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;11&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;12&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;13&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;14&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;15&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;16&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;17&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;18&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;19&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;20&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;21&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;22&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;23&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;24&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;25&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;26&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blocks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;27&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when this web page will be scrolled, we will log the blocks which are within the viewport when ever user stops for more than 1 seconds.&lt;/p&gt;

&lt;p&gt;A vital thing to keep in mind is to read the problem statement multiple times and then break the problem into sub-problems so that we can tackle each of them independently.&lt;/p&gt;

&lt;p&gt;By reading the problem statement, I figured two sub-problems and decided to break it into two parts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A way to check if the element is within the viewport.&lt;/li&gt;
&lt;li&gt;A way to make the API call only after user stops scrolling and waits for sometime (5 secs in this case), if user scrolls before that then we should revoke the call.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Check if an element is within the viewport.
&lt;/h2&gt;

&lt;p&gt;“With in the viewport” means then element which are within the visible part of the screens not within the visible area.&lt;/p&gt;

&lt;p&gt;For this we will create a function which will return true or false, depending upon whether element is within the viewport of not.&lt;/p&gt;

&lt;p&gt;To determine this we will use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect" rel="noopener noreferrer"&gt;Element.getBoundingClientRect()&lt;/a&gt; method which returns the elements position within the viewport. It returns an object with an element’s height and width, as well as it’s distance from the top, bottom, left, and right of the viewport.&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="c1"&gt;// Get the H1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Get it's position in the viewport&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bounding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Log&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;bounding&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// {&lt;/span&gt;
&lt;span class="c1"&gt;//  height: 118,&lt;/span&gt;
&lt;span class="c1"&gt;//  width: 591.359375,&lt;/span&gt;
&lt;span class="c1"&gt;//  top: 137,&lt;/span&gt;
&lt;span class="c1"&gt;//  bottom: 255,&lt;/span&gt;
&lt;span class="c1"&gt;//  left: 40.3125,&lt;/span&gt;
&lt;span class="c1"&gt;//  right: 631.671875&lt;/span&gt;
&lt;span class="c1"&gt;// }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then next thing after getting the elements placement details is to determine if it is within the viewport.&lt;/p&gt;

&lt;p&gt;If an element is in the viewport then its position from &lt;strong&gt;top&lt;/strong&gt; and &lt;strong&gt;left&lt;/strong&gt; will always be greater than or equal to &lt;strong&gt;0&lt;/strong&gt;. It’s distance from the &lt;strong&gt;right&lt;/strong&gt; will be less than or equal to the total width of the viewport, and it’s distance from the &lt;strong&gt;bottom&lt;/strong&gt; will be less than or equal to the height of the viewport.&lt;/p&gt;

&lt;p&gt;There are couple of ways to get the width and height of the viewport.&lt;/p&gt;

&lt;p&gt;For width, Some browsers support &lt;strong&gt;window.innerWidth&lt;/strong&gt; while some support &lt;strong&gt;document.documentElement.clientWidth&lt;/strong&gt; and some support both. We try using one of them and other as fallback to get the width using OR operator.&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="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly to get the height, some browsers support &lt;strong&gt;window.innerHeight&lt;/strong&gt; while some support &lt;strong&gt;document.documentElement.clientHeight&lt;/strong&gt; and some support both. Thus we can use the same fallback approach here as well.&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="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Combining this together, We can check if the element is in the viewport like this.&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;isInViewport&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;elem&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;bounding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&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="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
       &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
       &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
       &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientWidth&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;p&gt;Now we can use this helper method on each element to determine if they are within the viewport or not.&lt;/p&gt;

&lt;p&gt;First sub-problem is solved, now lets try to solve the second one.&lt;/p&gt;




&lt;h2&gt;
  
  
  Call a function when user stops scrolling or any other interactions for sometime.
&lt;/h2&gt;

&lt;p&gt;For this we can use the &lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript" rel="noopener noreferrer"&gt;debouncing&lt;/a&gt; technique.&lt;/p&gt;

&lt;p&gt;Debouncing is a method or a way to execute a function when it is made sure that no further repeated event will be triggered in a given frame of time.&lt;/p&gt;

&lt;p&gt;In simple words if the scroll event is not triggered again within the specified time (assume 5 seconds) then only invoke the function. This is implemented using the &lt;a href="https://learnersbucket.com/examples/javascript/javascript-settimeout-method" rel="noopener noreferrer"&gt;setTimeout&lt;/a&gt; timer function.&lt;/p&gt;

&lt;p&gt;I have already explained two different variations of debouncing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript/" rel="noopener noreferrer"&gt;Normal debouncing&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/interview/debounce-function-with-immediate-flag-in-javascript/" rel="noopener noreferrer"&gt;Debouncing with Immediate flag&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Based on the use, we can chose any one of them. For this problem we will go with the normal one.&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;debounce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&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;let&lt;/span&gt; &lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&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;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&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;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;inDebounce&lt;/span&gt; &lt;span class="o"&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="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&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;p&gt;This takes care of our second sub-problem. Now lets put this all together and create the final solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Putting everything together
&lt;/h2&gt;

&lt;p&gt;Lets put each piece in the place to get the final picture.&lt;/p&gt;

&lt;p&gt;Select all the elements / products / articles / blocks of the DOM which you want to store in the API call, as I have assigned &lt;strong&gt;blocks&lt;/strong&gt; class to each of them, I will query select them all and store in a variable.&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="c1"&gt;// Get all the products&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.blocks&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;Next thing is we will need a function which will check which elements are within the viewport and then take appropriate course of action thereafter.&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="c1"&gt;// Helper function to check if element is in viewport&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isInViewport&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;elem&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;bounding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&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="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientWidth&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="c1"&gt;// Function which will make the API call&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getBlocks&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="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isInViewport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;//make API call here&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;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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="c1"&gt;// add a space&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="s2"&gt; &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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call this function after debouncing the scroll event for which we will have to assign an event listener.&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="c1"&gt;// Debounce a function call&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&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;let&lt;/span&gt; &lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&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;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&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;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;inDebounce&lt;/span&gt; &lt;span class="o"&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="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&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="c1"&gt;// Assign the event listener&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scroll&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getBlocks&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, we are done.&lt;/p&gt;

&lt;p&gt;We can see the working of this in this image.&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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fezgif.com-gif-maker.gif%3Fresize%3D597%252C297%26ssl%3D1" 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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fezgif.com-gif-maker.gif%3Fresize%3D597%252C297%26ssl%3D1" alt="Capture product visible on viewport when user stops scrolling"&gt;&lt;/a&gt;&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="nx"&gt;DOCTYPE&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UTF-8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;equiv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X-UA-Compatible&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IE=edge&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;viewport&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;width=device-width, initial-scale=1.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Document&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&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;wrapper&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="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;wrap&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="nx"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="nx"&gt;px&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="mi"&gt;300&lt;/span&gt;&lt;span class="nx"&gt;px&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="nx"&gt;inline&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&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="mi"&gt;5&lt;/span&gt;&lt;span class="nx"&gt;px&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="nx"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;font&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="nx"&gt;px&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wrapper&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blocks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="c1"&gt;// Helper function to check if element is in viewport&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isInViewport&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;elem&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;bounding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&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="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
                &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
                &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
                &lt;span class="nx"&gt;bounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientWidth&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="c1"&gt;// Debounce a function call&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&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;let&lt;/span&gt; &lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&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;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&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;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inDebounce&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nx"&gt;inDebounce&lt;/span&gt; &lt;span class="o"&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="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&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="c1"&gt;// Function which will make the API call&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getBlocks&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="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;block&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isInViewport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;block&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="nx"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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="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="s2"&gt; &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="c1"&gt;// Get all the products&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.blocks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Assign the event listener&lt;/span&gt;
        &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scroll&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getBlocks&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>The frontend Landscape – Different Architectures</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Sun, 19 Sep 2021 18:14:23 +0000</pubDate>
      <link>https://dev.to/learnersbucket/the-frontend-landscape-different-architectures-m2j</link>
      <guid>https://dev.to/learnersbucket/the-frontend-landscape-different-architectures-m2j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your JavaScript interview. You will find DSA, System Design and JavaScript Questions.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Web development (Frontend) has come a long way from its inception. There was a time when static websites were designed using tables for layouts and some styles around it which were only built for desktops.&lt;/p&gt;

&lt;p&gt;But today web apps can be created with complex user interfaces and for cross devices. SAAS which are built as web applications allow us to stream movies and music on demand, order pizza, handle bank processes, even book a cab, and do more and more things which makes our life easier.&lt;/p&gt;

&lt;p&gt;Over time to create apps which provide so much capabilities, security, flexibility, and also are manageable and scalable, organizations experimented with multiple architectures.&lt;/p&gt;

&lt;p&gt;As a developer, architect, or tech lead, when we start a fresh project we need to decide which architecture we will be following. There are an array of options to choose from, but not all of them are fit for every job. We need to understand the challenges we will face along the way to make the right decision for our projects.&lt;/p&gt;

&lt;p&gt;Let us explore the current architectures which are available to us for the frontend development.&lt;/p&gt;




&lt;h2&gt;
  
  
  Server Side Application or Multi Page Application.
&lt;/h2&gt;

&lt;p&gt;Server side rendered websites were a thing back when they had not become the web apps. All they did was display text and images and very minimal interactivity.&lt;/p&gt;

&lt;p&gt;These websites were built with server-side rendering which means the HTML was generated on the server along with all the data and it is returned to the browser and then the browser used to render it.&lt;/p&gt;

&lt;p&gt;When a page refreshes or the user navigates to a different page, the servers used to send new HTML. This will be repeated every time if your browser does not have the cached version of that page.&lt;/p&gt;

&lt;p&gt;As each time when you make the request to the server, the server regenerates the whole HTML even if we are only expecting for minor changes, this hampers the speed of the website.&lt;/p&gt;

&lt;p&gt;Though the speed of the website varies on many factors like your internet speed, location of the server, number of users who are trying to access the site, etc.&lt;/p&gt;

&lt;p&gt;For small websites these issues are negligible but for modern websites which have more than thousands of lines of code as well as complex logics will take more time for processing. Now imagine when you browse through the website and you have to keep waiting for each web page which you visit.&lt;/p&gt;

&lt;p&gt;But the good thing about server-side rendering is that it is great for SEO. Your content is present before you get it, so search engines are able to index it and crawl it just fine.&lt;/p&gt;




&lt;h2&gt;
  
  
  Single Page Application (Client – Side Rendering)
&lt;/h2&gt;

&lt;p&gt;In the current time, SPAs are the most used implementations. In single page applications client-side rendering is used. The browser loads the initial page from the server, along with the scripts (frameworks, libraries, app code) and stylesheets required for the whole app.&lt;/p&gt;

&lt;p&gt;When the user navigates to other pages, a page refresh is not triggered. The URL of the page is updated via the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API" rel="noopener noreferrer"&gt;HTML5 History API&lt;/a&gt;. New data required for the new page, usually in JSON format, is retrieved by the browser via &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started" rel="noopener noreferrer"&gt;AJAX&lt;/a&gt; requests to the server. The SPA then dynamically updates the page with the data via JavaScript, which it has already downloaded in the initial page load. This model is like how native mobile apps work.&lt;/p&gt;

&lt;p&gt;Using SPAs has many advantages like the whole application code is downloaded just once on initial load and then the entire application logic is available throughout the user session.&lt;/p&gt;

&lt;p&gt;As the SPAs only deal with the client side logic, it can be developed independently and to get the data it communicates with APIs by exchanging data with the persistent layer (backend or server side).&lt;/p&gt;

&lt;p&gt;The client side and server side are decoupled, which means that we can independently develop new clients for different platforms (e.g. mobile, chatbots, smart watches) without having to modify the server code. The client can also be developed using a new tech stack.&lt;/p&gt;

&lt;p&gt;As we don’t have to repeatedly fetch the same resources again and again, we have to make fewer HTTP requests, also the payloads size is smaller which is faster to process.&lt;/p&gt;

&lt;p&gt;Because both client and server side are decoupled which means they are smaller in size and faster to download, interpret and process.&lt;/p&gt;

&lt;p&gt;All these features enhance the user experience and give an expression of what we usually have when we interact with a native application for mobile devices or desktop.&lt;/p&gt;

&lt;p&gt;SPAs also allow us to decide how we are going to split the application logic between server and client. We can have either “thick-client” and “fat-server” or “fat-client” and “thick-server” depending upon which type of problem we are addressing.&lt;/p&gt;

&lt;p&gt;Majorly “thick-client” and “fat-server” is used as by keeping all the logic on the server we can use that across multiple clients, that way if we update the logic on one platform it will be available on each client.&lt;/p&gt;

&lt;p&gt;The bad thing about this is as the majority of the resources are fetched when the web app loads for the first time it can hamper the initial load time of the application majorly on devices with less processing power and slower networks.&lt;/p&gt;

&lt;p&gt;There’s an additional step to be done on your server which is to configure it to route all requests to a single entry point and allow client-side routing to take over from there. All the client side routing is managed internally using HTML5 history API.&lt;/p&gt;

&lt;p&gt;As the pages in the SPAs are dynamically generated on the run-time, another disadvantage of using SPAs relates to search engine optimization (SEO). When a crawler tries to index your website, it won’t have an easy job indexing all the contents served by an SPA unless we prepare alternative ways for fetching it.&lt;/p&gt;

&lt;p&gt;Another disadvantage of using SPAs is on the organizational side. When the SPA is a large application being developed and maintained by coalted teams working on the same codebase, could end up with a mix of approaches and decisions that could confuse team members. &lt;/p&gt;




&lt;h2&gt;
  
  
  Isomorphic applications (Hybrid approach)
&lt;/h2&gt;

&lt;p&gt;With the above two approaches we learned that server-side rendering can be used to solve the SEO related issues and client-side rendering can be used for performance optimization. What if we could use both of them together and use the best of both to create faster web applications which are also very well SEO optimized.&lt;/p&gt;

&lt;p&gt;Isomorphic or universal applications are web applications where the code between server and client is shared and can run in both contexts.&lt;/p&gt;

&lt;p&gt;These web applications share code between server and client.When you visit the web app for the first time the application is rendered on the server side using server side rendering techniques with Nodejs and then it is sent to the browser and displayed to the user, here after whenever user navigates the web apps the pages are rendered on client-side with JavaScript using SPA techniques.The content is updated by consuming APIs and fetching data from them.&lt;/p&gt;

&lt;p&gt;The complexity of this approach is majorly among the state management. One way to solve this is to create and save the state on the server side and then provide this state to the browser. The browser uses this state to bootstrap the SPA, without this the user must wait for the server side page to render and wait more for the complete re-render process in the browser.&lt;/p&gt;

&lt;p&gt;To make the most out of this approach, we can render the page with bare minimum things which is required to create the skeleton of the page such as inline CSS and few HTML content and minimum JavaScript so that browser can load it extremely fast and there after update the content as per requirement on the client side using JavaScript.&lt;/p&gt;

&lt;p&gt;With these we can also solve the routing issue, you can either render the pages complete on the server-side or use the hybrid approach. Use the server-side rendering for initial view and then load an SPA, where the server will do the macro routing that serves different SPAs, each with its own routing system to navigate between views.&lt;/p&gt;

&lt;p&gt;Isomorphic applications can suffer from the scalability problems if the web app is visited by a large number of users. Having a right caching in place could solve this problem as pages are rendered on server-side.&lt;/p&gt;




&lt;h2&gt;
  
  
  Micro Frontend Architecture
&lt;/h2&gt;

&lt;p&gt;Micro-Frontend is a fairly new and emerging architecture which is inspired by the micro-services architecture of backend development.&lt;/p&gt;

&lt;p&gt;When multiple teams are involved in the development of a single application, it becomes difficult to manage the code base and applications itself as multiple people will be touching the same code base.&lt;/p&gt;

&lt;p&gt;This approach tends to solve this problem by splitting the application in different parts depending on the requirement and each of them would be developed independently which would be shipped as a single application. The main idea behind this is to break down a monolithic codebase into smaller parts, allowing to spread out the work among various teams, whether collocated or distributed.&lt;/p&gt;

&lt;p&gt;There are different approaches for architecturing a micro-frontends application. Certain architectural decisions have to be made upfront because they will cave the road for future decisions. The decision majorly covers four key areas.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defining different micro-frontends.&lt;/li&gt;
&lt;li&gt;Composing micro-frontends.&lt;/li&gt;
&lt;li&gt;Routing micro-frontends.&lt;/li&gt;
&lt;li&gt;Communicating between micro-frontends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can decide multiple micro-frontends for the same view or having one micro-frontend per view and based on this we can split the application.&lt;/p&gt;

&lt;p&gt;The application can be split horizontally or vertically.&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%2Fi1.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F09%2FMicroservices-Architecture1.png%3Fw%3D768%26ssl%3D1" 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%2Fi1.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F09%2FMicroservices-Architecture1.png%3Fw%3D768%26ssl%3D1" alt="Microservices Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the horizontal split we split the views of the pages into multiple micro-frontends and different teams will be responsible for the development of these views. This approach provides great flexibility as certain micro-frontends could be reused across different views, but it also needs more discipline and governance to make sure we don’t end up with large amounts of micro-frontends.&lt;/p&gt;

&lt;p&gt;In the vertical split we split the pages or module completely. For example different teams will be responsible for the development of different modules like authentication, streaming services, search, etc.&lt;/p&gt;




&lt;h2&gt;
  
  
  JAMSTack
&lt;/h2&gt;

&lt;p&gt;Nowadays there’s another new frontend architecture which is enjoying its success called JAMStack (JavaScript, APIs, Markup).&lt;/p&gt;

&lt;p&gt;Being a modern architecture JAMSTack helps to create fast and secure sites and dynamic apis with JavaScript/APIs and pre-rendered markup, served without web servers.&lt;/p&gt;

&lt;p&gt;In fact the final output is a static artifact composed of HTML, CSS and JavaScript, basically the holy trinity of frontend development which can be served directly using CDN as it doesn’t require any server side technology to work. The most simplest way of serving a JAMStack application is using &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;Github pages&lt;/a&gt; for hosting the final result.&lt;/p&gt;

&lt;p&gt;The primary advantages of these architectures are better performances, cheaper infrastructure and maintenance considering they can be served directly by a CDN, great scalability because static files are served, higher security due to decrease of attack surface and easy integration with headless CMS.&lt;/p&gt;

&lt;p&gt;JAMStack is a great companion for many websites we have to create especially considering the frictionless developer experience.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Industry focused roadmap to be JavaScript developer – 2021</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Sun, 29 Aug 2021 18:30:51 +0000</pubDate>
      <link>https://dev.to/learnersbucket/industry-focused-roadmap-to-be-javascript-developer-2021-1m2b</link>
      <guid>https://dev.to/learnersbucket/industry-focused-roadmap-to-be-javascript-developer-2021-1m2b</guid>
      <description>&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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FIndustry-focused-roadmap-to-be-JavaScript-developer-2021-2-1.png%3Fw%3D768%26ssl%3D1" 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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FIndustry-focused-roadmap-to-be-JavaScript-developer-2021-2-1.png%3Fw%3D768%26ssl%3D1" alt="Industry focused roadmap to be JavaScript developer – 2021"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your JavaScript interview. You will find DSA, System Design and JavaScript Questions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An Industry Focused Roadmap to become Frontend Developer.&lt;/p&gt;

&lt;p&gt;This is guide is my recommendation of libraries/frameworks to learn each aspect of front-end development, based on their popularity across the industry.&lt;/p&gt;

&lt;p&gt;This roadmap is targeted at the freshers who are trying to understand front end. If you are already familiar with front end development and want to explore another perspective, then you are welcome to explore it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: If you find an issue, please comment it down, I will try to fix it. Also if you like it, share it with others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Good understanding of core programming concepts.&lt;/li&gt;
&lt;li&gt;Already familiar with the working of web such as with web protocols and conventions like HTTP and RESTful APIs.&lt;/li&gt;
&lt;li&gt;Comfortable with basic command line actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS: Cascading Style Sheets&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;Single Page Application (SPA)&lt;/li&gt;
&lt;li&gt;React (A library to create Single Page Applications)&lt;/li&gt;
&lt;li&gt;State Management – Flux/Redux&lt;/li&gt;
&lt;li&gt;CSS Modules (CSS in JS)&lt;/li&gt;
&lt;li&gt;Maintainability

&lt;ul&gt;
&lt;li&gt;Linting JavaScript – ESLint&lt;/li&gt;
&lt;li&gt;Linting CSS – stylelint&lt;/li&gt;
&lt;li&gt;Formatting Code – Prettier&lt;/li&gt;
&lt;li&gt;Testing – Jest + Enzyme&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Deployment and Hosting

&lt;ul&gt;
&lt;li&gt;Version Control System – GIT&lt;/li&gt;
&lt;li&gt;Package Management – NPM&lt;/li&gt;
&lt;li&gt;Build System – webpack&lt;/li&gt;
&lt;li&gt;Deployment – CI/CD&lt;/li&gt;
&lt;li&gt;Hosting and CDN&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Advanced Topics

&lt;ul&gt;
&lt;li&gt;Static Types – Typescript&lt;/li&gt;
&lt;li&gt;Mobile App Development – React Native&lt;/li&gt;
&lt;li&gt;Desktop App Development – Electron JS&lt;/li&gt;
&lt;li&gt;Server Side Rendering – Next.js&lt;/li&gt;
&lt;li&gt;Progressive Web Apps (PWA): The future of web development&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  HTML &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;HTML is a (Hypertext Markup Language) is not a programming language. It is a markup language that tells web browsers how to structure the web pages you visit. It can be as complicated or as simple as the web developer wants it to be.&lt;/p&gt;

&lt;p&gt;HTML consists of a series of elements, which you use to enclose, wrap, or markup different parts of content to make it appear or act in a certain way. The enclosing tags can make content into a hyperlink to connect to another page, italicize words, and so on. For example, consider the following line of text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;Hello World!.&amp;lt;/p&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below figure represents the anatomy of HTML.&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%2Fi0.wp.com%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FLearn%2FHTML%2FIntroduction_to_HTML%2FGetting_started%2Fgrumpy-cat-small.png%3Fw%3D1170%26ssl%3D1" 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%2Fi0.wp.com%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FLearn%2FHTML%2FIntroduction_to_HTML%2FGetting_started%2Fgrumpy-cat-small.png%3Fw%3D1170%26ssl%3D1" alt="Anatomy of HTML (MDN)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTML is very important from the SEO perspective thus HTML5 introduced many new tags which really helps in SEO optimization.&lt;/p&gt;

&lt;p&gt;Apart from that, accessibility is also an important thing to learn in HTML to make sure web-apps are accessible to everyone through different devices.&lt;/p&gt;

&lt;h4&gt;
  
  
  Things to learn in HTML.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;SEMANTIC HTML (HTML5)&lt;/li&gt;
&lt;li&gt;Accessibility&lt;/li&gt;
&lt;li&gt;DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estimated Time to learn:- 10 to 15 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/web" rel="noopener noreferrer"&gt;Web.dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=pQN-pnXPaVg" rel="noopener noreferrer"&gt;Freecodecamp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CSS: Cascading Style Sheets &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.&lt;/p&gt;

&lt;p&gt;It is extremely important to have a good understanding of CSS, it may seem simple but is quite complex to work with. Writing cross device / browser style can be challenging at times.&lt;/p&gt;

&lt;h4&gt;
  
  
  Things to study under css.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;CSS Specificity&lt;/li&gt;
&lt;li&gt;CSS Pre-processors&lt;/li&gt;
&lt;li&gt;CSS resetting / normalization&lt;/li&gt;
&lt;li&gt;CSS Architecture(BEM)&lt;/li&gt;
&lt;li&gt;Floats&lt;/li&gt;
&lt;li&gt;Flexbox &amp;amp; Grids&lt;/li&gt;
&lt;li&gt;SVG&lt;/li&gt;
&lt;li&gt;Media Queries&lt;/li&gt;
&lt;li&gt;Display Properties&lt;/li&gt;
&lt;li&gt;Position properties&lt;/li&gt;
&lt;li&gt;Animations&lt;/li&gt;
&lt;li&gt;Psuedo Classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estimated Time to learn:- 10 – 15 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://smacss.com/" rel="noopener noreferrer"&gt;Smaccs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/" rel="noopener noreferrer"&gt;CSS-Tricks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=1Rs2ND1ryYc" rel="noopener noreferrer"&gt;CSS Tutorial – Zero to Hero (Complete Course)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ieTHC78giGQ" rel="noopener noreferrer"&gt;CSS Full Course – Includes Flexbox and CSS Grid Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Advanced CSS
&lt;/h3&gt;

&lt;p&gt;CSS is now advanced and provides using normal programming concepts with it like defining variable, functions, using &lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming" rel="noopener noreferrer"&gt;OOPs concepts&lt;/a&gt;, etc. There are many extensions of it that help in using it more efficiently.&lt;/p&gt;

&lt;h4&gt;
  
  
  SASS
&lt;/h4&gt;

&lt;p&gt;Sass stands for Syntactically Awesome Stylesheet is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS).&lt;/p&gt;

&lt;p&gt;Estimated Time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h5&gt;
  
  
  Study Links
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=_a5j7KoflTs" rel="noopener noreferrer"&gt;Sass Tutorial for Beginners – CSS With Superpowers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://sass-lang.com/guide" rel="noopener noreferrer"&gt;SASS – Official Website.&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  LESS
&lt;/h4&gt;

&lt;p&gt;Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS.&lt;/p&gt;

&lt;p&gt;Less extends CSS with dynamic behavior such as variables, mixins, operations and functions. Less runs on both the server-side and client-side.&lt;/p&gt;

&lt;h5&gt;
  
  
  Study Links
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=YD91G8DdUsw" rel="noopener noreferrer"&gt;Less CSS Pre-Processor Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lesscss.org/" rel="noopener noreferrer"&gt;LESS – Official Website.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  JavaScript&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript or ECMAScript is the language of the web, it is incredibly versatile programming language using which we can build web servers, native mobile apps, web apps, and desktop apps.&lt;/p&gt;

&lt;p&gt;Being loosely typed it is easy to learn but hard to master. Practice is the key to mastering it.&lt;/p&gt;

&lt;p&gt;In recent times, JavaScript has seen major improvements with lots of new features being added to the language making it more powerful.&lt;/p&gt;

&lt;p&gt;ECMAScript 2015 (previously called ECMAScript 6) was released, which had major feature updates, after that every year new features are being added to the language, new version of ECMAScript is referred as ESNext.&lt;/p&gt;

&lt;p&gt;Here is a great article incase you want to learn &lt;a href="https://auth0.com/blog/a-brief-history-of-javascript/" rel="noopener noreferrer"&gt;history of JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As browsers must implement the new features once they are published to make them useable, which takes time, tools such as &lt;a href="https://learnersbucket.com/tutorials/es6/babel" rel="noopener noreferrer"&gt;Babel&lt;/a&gt; enable developers to write these new features in their apps as Babel &lt;a href="https://en.wikipedia.org/wiki/Babel_(transcompiler)" rel="noopener noreferrer"&gt;transpiles&lt;/a&gt; them down to browser compatible code.&lt;/p&gt;

&lt;p&gt;With the development of &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Nodejs&lt;/a&gt;, JavaScript was able to move out of the web to everywhere, right now you can use JavaScript as a server side languages as well as almost on every platform, Web, Mobile, Desktop, IOT, etc.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 30 – 45 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links (Basic).
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript30.com/" rel="noopener noreferrer"&gt;JavaScript30&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eloquentjavascript.net/" rel="noopener noreferrer"&gt;Eloquent JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/learn-javascript" rel="noopener noreferrer"&gt;ES5 on Codecademy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/introduction-to-javascript" rel="noopener noreferrer"&gt;ES6 on Codecademy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://babeljs.io/docs/en/learn/" rel="noopener noreferrer"&gt;ES5 on Babel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/tutorials/es6/es6-intro" rel="noopener noreferrer"&gt;ES6 Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/yangshun/front-end-interview-handbook/blob/master/contents/en/javascript-questions.md" rel="noopener noreferrer"&gt;JavaScript Questions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Topics to cover to get better at the language.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;this&lt;/li&gt;
&lt;li&gt;IIFE&lt;/li&gt;
&lt;li&gt;Closure&lt;/li&gt;
&lt;li&gt;Null vs undefined&lt;/li&gt;
&lt;li&gt;Loop vs map&lt;/li&gt;
&lt;li&gt;call, apply &amp;amp; bind&lt;/li&gt;
&lt;li&gt;hoisting&lt;/li&gt;
&lt;li&gt;Scope&lt;/li&gt;
&lt;li&gt;attributes vs properties&lt;/li&gt;
&lt;li&gt;Ternary operators&lt;/li&gt;
&lt;li&gt;Promises vs callbacks&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/tutorials/data-structures/javascript-objects-complete-reference" rel="noopener noreferrer"&gt;Objects&lt;/a&gt;, Object freezing&lt;/li&gt;
&lt;li&gt;mutable vs immutable&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/tutorials/es6/javascript-symbol" rel="noopener noreferrer"&gt;Symbol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/examples/interview/currying-in-javascript-part-1" rel="noopener noreferrer"&gt;Currying&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript" rel="noopener noreferrer"&gt;Debouncing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/examples/interview/what-is-throttling-in-javascript" rel="noopener noreferrer"&gt;Throttling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnersbucket.com/examples/html/how-to-load-script-efficiently-with-async-and-defer" rel="noopener noreferrer"&gt;async vs defer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Event Bubbling &amp;amp; Capturing&lt;/li&gt;
&lt;li&gt;Prototype &amp;amp; Prototypal Inheritance&lt;/li&gt;
&lt;li&gt;Thinking Recursively&lt;/li&gt;
&lt;li&gt;Local Storage and Session Storage&lt;/li&gt;
&lt;li&gt;CORS&lt;/li&gt;
&lt;li&gt;sum(a)(b)(c)…(n)&lt;/li&gt;
&lt;li&gt;Web Storage APIs&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=8aGhZQkoFbQ" rel="noopener noreferrer"&gt;Event Loop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Web Sockets&lt;/li&gt;
&lt;li&gt;Single Page Applications&lt;/li&gt;
&lt;li&gt;Server Side rendering&lt;/li&gt;
&lt;li&gt;Optimization&lt;/li&gt;
&lt;li&gt;Critical rendering path&lt;/li&gt;
&lt;li&gt;Lazy loading data&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Advanced Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/getify/You-Dont-Know-JS" rel="noopener noreferrer"&gt;You Don’t Know JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691" rel="noopener noreferrer"&gt;Professional JAVASCRIPT For Web Developers – Book&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Single Page Application (SPA) &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Traditionally website were built with server-side rendering. Browser used to receive HTML from the server and then render it. When page refreshes or user navigates to different page, the servers used to send new HTML.&lt;/p&gt;

&lt;p&gt;However in single page applications (SPA) client-side rendering is used. The browser loads the initial page from the server, along with the scripts (frameworks, libraries, app code) and stylesheets required for the whole app. When the user navigates to other pages, a page refresh is not triggered. The URL of the page is updated via the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API" rel="noopener noreferrer"&gt;HTML5 History API&lt;/a&gt;. New data required for the new page, usually in JSON format, is retrieved by the browser via &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started" rel="noopener noreferrer"&gt;AJAX&lt;/a&gt; requests to the server. The SPA then dynamically updates the page with the data via JavaScript, which it has already downloaded in the initial page load. This model is like how native mobile apps work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Web apps give more native feel and are more responsive as there is no flash between page navigations due to full-page refreshes.&lt;/li&gt;
&lt;li&gt;As we don’t have to repeatedly fetch the same resources again and again, we have to make fewer HTTP request, also the payload size are smaller which are faster to process.&lt;/li&gt;
&lt;li&gt;The server and client are decoupled which means that we can independently develop new clients for different platforms (e.g. mobile, chatbots, smart watches) without having to modify the server code. The client can also be developed using new tech stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;As majority of the resources are fetched when the web app loads for first time it can hamper the initial load time of the application.&lt;/li&gt;
&lt;li&gt;There’s an additional step to be done on your server which is to configure it to route all requests to a single entry point and allow client-side routing to take over from there.&lt;/li&gt;
&lt;li&gt;SEO issues:- SPAs are reliant on JavaScript to render content, but not all search engines execute JavaScript during crawling, and they may see empty content on your page. This inadvertently hurts the Search Engine Optimization (SEO) of your app. To overcome this, you can either server-side render your app or use services such as Prerender to “render your javascript in a browser, save the static HTML, and return that to the crawlers”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is still time when server-side applications are preferred where SEO is involved as well as when we are building small scale applications like blogs etc.&lt;/p&gt;

&lt;p&gt;But a SPA application with client-server relation is preferred for large enterprise application where a clear client-server separation scales better for larger engineering teams, as the client and server code can be developed and released independently.&lt;/p&gt;

&lt;p&gt;Web developers these days refer to the products they build as web apps, rather than websites. While there is no strict difference between the two terms, web apps tend to be highly interactive and dynamic, allowing the user to perform actions and receive a response for their action.&lt;/p&gt;

&lt;p&gt;While jQuery can be still used for server-side applications to add user interactivity to each page. But it is not easy for jQuery for handle large scale applications. After all, jQuery is primarily a library for DOM manipulation and it’s not a framework.&lt;/p&gt;

&lt;p&gt;For this task JavaScript frameworks have been created to provide higher-level abstractions over the DOM, allowing you to keep state in memory, out of the DOM. Using frameworks also brings the benefits of reusing recommended concepts and best practices for building apps.&lt;/p&gt;

&lt;p&gt;It is lot easier to onboard a Junior who is not familiar with the code base, but has experience with a framework, will find it easier to understand the code because it is organized in a structure that he is familiar with. Also popular frameworks have great community support and tutorials as well as guide which makes them easy to start with.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/21862054/single-page-app-advantages-and-disadvantages" rel="noopener noreferrer"&gt;Single Page App: advantages and disadvantages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.isquaredsoftware.com/presentations/2016-10-revolution-of-web-dev/" rel="noopener noreferrer"&gt;The (R)Evolution of Web Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.freecodecamp.com/heres-why-client-side-rendering-won-46a349fadb52" rel="noopener noreferrer"&gt;Here’s Why Client Side Rendering Won&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  React (A library to create Single Page Applications) &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;There is no other JavaScript library other than &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; which has taken the front-end ecosystem by storm in modern time. React is a library built and open-sourced by the smart people at Facebook. In React, developers write components for their web interface and compose them together.&lt;/p&gt;

&lt;p&gt;As frontend development is shifting towards a paradigm of component-based development, where each components are developed independently and then clubbed together to create a feature and eventually leads in creating a web app using these features. React encourages that you write your HTML and CSS in your JavaScript itself. This sounds like a crazy idea at first as it is opposite of the existing good practice to write HTML, JavaScript and CSS separately. But if you keep your HTML, CSS, and JavaScript scoped to the component level only, then it is easier to do the development with conflict also different components can be developed individually without any dependency on each other while designing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Features of React.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Declarative&lt;/strong&gt;:- You describe what you want to see in your view and not how to achieve it. Each component has its own state, you simply change the state within the component and the view will update itself according to the state. It is also easy to determine how the component will look like just by looking at the HTML in the &lt;code&gt;render()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functional&lt;/strong&gt;:- Each component is a JavaScript pure function which has &lt;code&gt;props&lt;/code&gt; (External data) and &lt;code&gt;state&lt;/code&gt; (Internal data). Pure functions are easy to test, and the same goes for functional components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainable&lt;/strong&gt;:- React forces composition rather inheritance for scalability and reusability, thus writing your view in a component-based fashion encourages reusability. As each component has their logic and view limited to themselves, it is easier to maintain them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Performance&lt;/strong&gt;:- React use a concept of Virtual DOM and it re-renders everything when there is a change in state or props. Why is there a need for a virtual DOM? While modern JavaScript engines are fast, reading from and writing to the DOM is slow. React keeps a lightweight virtual representation of the DOM in memory. Re-rendering everything is a misleading term. In React it actually refers to re-rendering the in-memory representation of the DOM, not the actual DOM itself. When there’s a change in the underlying data of the component, a new virtual representation is created, and compared against the previous representation. The difference (minimal set of changes required) is then patched to the real browser DOM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Learning&lt;/strong&gt;:- React has very few API’s which remains constant and hardly changes, apart from that it is one of the largest community which providing an array of tools, open-sourced UI components, and a ton of great resources online to get you started on learning React.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Over the years, new view libraries that are even more performant than React have emerged. React may not be the fastest library out there, but in terms of the ecosystem, overall usage experience and benefits, it is still one of the greatest. Facebook is also channeling efforts into making React even faster with a &lt;a href="https://github.com/acdlite/react-fiber-architecture" rel="noopener noreferrer"&gt;rewrite of the underlying reconciliation algorithm&lt;/a&gt;. The concepts that React introduced has taught us how to write better code, more maintainable web apps and made us better engineers.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 30 – 45 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://facebook.github.io/react/tutorial/tutorial.html" rel="noopener noreferrer"&gt;React Official Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://egghead.io/courses/build-your-first-production-quality-react-app" rel="noopener noreferrer"&gt;Egghead Course – Build Your First Production Quality React App&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=Ke90Tje7VS0" rel="noopener noreferrer"&gt;Reactjs – Crash Course&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://emberjs.com/" rel="noopener noreferrer"&gt;Ember&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cycle.js.org/" rel="noopener noreferrer"&gt;Cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://svelte.dev/" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  State Management – Flux/Redux &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;React is a library, not a framework, and does not deal with the layers below the view.&lt;/p&gt;

&lt;p&gt;As your app grows bigger, you may find that the app structure becomes a little messy. Components throughout the app may have to share and display common data but there is no elegant way to handle that in React. After all, React is just the view layer, it does not dictate how you structure the other layers of your app, such as the model and the controller, in traditional MVC paradigms. In an effort to solve this, Facebook invented &lt;a href="https://facebook.github.io/flux/docs/in-depth-overview.html" rel="noopener noreferrer"&gt;Flux&lt;/a&gt;, an app architecture that complements React’s composable view components by utilizing a unidirectional data flow.&lt;/p&gt;

&lt;p&gt;In summary, the Flux pattern has the following characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unidirectional data flow&lt;/strong&gt;:- Makes the app more predictable as updates can be tracked easily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separation of concerns&lt;/strong&gt;:- Each part in the Flux architecture has clear responsibilities and are highly decoupled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Works well with declarative programming&lt;/strong&gt;:- The store can send updates to the view without specifying how to transition views between states.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As Flux is not a framework per se, developers have tried to come up with many implementations of the Flux pattern. Eventually, a clear winner emerged, which was &lt;a href="http://redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt;. Redux combines the ideas from Flux, &lt;a href="https://www.wikiwand.com/en/Command_pattern" rel="noopener noreferrer"&gt;Command pattern&lt;/a&gt; and &lt;a href="https://www.wikiwand.com/en/Command_pattern" rel="noopener noreferrer"&gt;Elm architecture&lt;/a&gt; and is the de facto state management library developers use with React these days. Its core concepts are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App &lt;code&gt;state&lt;/code&gt; is described by a single plain old JavaScript object (POJO).&lt;/li&gt;
&lt;li&gt;Dispatch an &lt;code&gt;action&lt;/code&gt; (also a POJO) to modify the state.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Reducer&lt;/code&gt; is a pure function that takes in current state and action to produce a new state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The concepts sound simple, but they are really powerful as they enable apps to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have their state rendered on the server, booted up on the client.&lt;/li&gt;
&lt;li&gt;Trace, log and backtrack changes in the whole app.&lt;/li&gt;
&lt;li&gt;Implement undo/redo functionality easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The creator of Redux, &lt;a href="https://github.com/gaearon" rel="noopener noreferrer"&gt;Dan Abramov&lt;/a&gt;, has taken great care in writing up detailed documentation for Redux, along with creating comprehensive video tutorials for learning &lt;a href="https://egghead.io/courses/getting-started-with-redux" rel="noopener noreferrer"&gt;basic&lt;/a&gt; and &lt;a href="https://egghead.io/courses/building-react-applications-with-idiomatic-redux" rel="noopener noreferrer"&gt;advanced&lt;/a&gt; Redux. They are extremely helpful resources for learning Redux.&lt;/p&gt;

&lt;p&gt;While Redux does not necessarily have to be used with React, it is highly recommended as they play very well with each other. React and Redux have a lot of ideas and traits in common.&lt;/p&gt;

&lt;p&gt;Your app will likely have to deal with async calls like making remote API requests. &lt;a href="https://github.com/gaearon/redux-thunk" rel="noopener noreferrer"&gt;redux-thunk&lt;/a&gt; and &lt;a href="https://github.com/redux-saga/redux-saga" rel="noopener noreferrer"&gt;redux-saga&lt;/a&gt; were created to solve those problems. They may take some time to understand as they require understanding of functional programming and generators. Our advice is to deal with it only when you need it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/reactjs/react-redux" rel="noopener noreferrer"&gt;react-redux&lt;/a&gt; is an official React binding for Redux and is very simple to learn.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://facebook.github.io/flux" rel="noopener noreferrer"&gt;Flux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://egghead.io/courses/getting-started-with-redux" rel="noopener noreferrer"&gt;Egghead Course – Getting Started with Redux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://egghead.io/courses/building-react-applications-with-idiomatic-redux" rel="noopener noreferrer"&gt;Egghead Course – Build React Apps with Idiomatic Redux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/markerikson/react-redux-links" rel="noopener noreferrer"&gt;React Redux Links&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367" rel="noopener noreferrer"&gt;You Might Not Need Redux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternative
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/mobxjs/mobx" rel="noopener noreferrer"&gt;MobX&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CSS Modules &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;CSS adds interactivity to the HTML, it is used to define how HTML elements will look and adjust as to the screen, to the sibling, etc. We all understand that writing good CSS is hard, it takes years of experience to get better at it. The major problem we face is writing scalable and maintainable CSSS that also for different screens and devices. To make it easier to work with it, over time, experienced frontend developers have designed methodologies to guide people on how to write organized CSS for complex projects, such as using &lt;a href="https://smacss.com/" rel="noopener noreferrer"&gt;SMACSS&lt;/a&gt;, &lt;a href="http://getbem.com/" rel="noopener noreferrer"&gt;BEM&lt;/a&gt;, &lt;a href="https://suitcss.github.io/" rel="noopener noreferrer"&gt;SUIT CSS&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;The bad thing about these methodologies are that they very fragile, they are artificially enforced by conventions and guidelines. They break the moment developers do not follow them.&lt;/p&gt;

&lt;p&gt;As you might have realized by now, the front end ecosystem is saturated with tools, and unsurprisingly, tools have been invented to partially solve some of the &lt;a href="https://speakerdeck.com/vjeux/react-css-in-js" rel="noopener noreferrer"&gt;problems with writing CSS at scale&lt;/a&gt;. “At scale” means that many developers are working on the same large project and touching the same stylesheets. There is no community-agreed approach on writing &lt;a href="https://github.com/MicheleBertoli/css-in-js" rel="noopener noreferrer"&gt;CSS in JS&lt;/a&gt; at the moment, and we are hoping that one day a winner would emerge, just like Redux did, among all the Flux implementations. For now, we are banking on &lt;a href="https://github.com/css-modules/css-modules" rel="noopener noreferrer"&gt;CSS Modules&lt;/a&gt;. CSS modules is an improvement over existing CSS that aims to fix the problem of global namespace in CSS; it enables you to write styles that are local by default and encapsulated to your component. This feature is achieved via tooling. With CSS modules, large teams can write modular and reusable CSS without fear of conflict or overriding other parts of the app. However, at the end of the day, CSS modules are still being compiled into normal globally-namespaced CSS that browsers recognize, and it is still important to learn and understand how raw CSS works.&lt;/p&gt;

&lt;p&gt;If you are a total beginner to CSS, Codecademy’s &lt;a href="https://www.codecademy.com/learn/learn-html-css" rel="noopener noreferrer"&gt;HTML &amp;amp; CSS course&lt;/a&gt; will be a good introduction to you. Next, read up on the &lt;a href="http://sass-lang.com/" rel="noopener noreferrer"&gt;Sass preprocessor&lt;/a&gt;, an extension of the CSS language which adds syntactic improvements and encourages style reusability. Study the CSS methodologies mentioned above, and lastly, CSS modules.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily). Try styling up your app using the SMACSS/BEM approach and/or CSS modules.&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.codecademy.com/learn/learn-html-css" rel="noopener noreferrer"&gt;Learn HTML &amp;amp; CSS course on Codecademy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://intro%20to%20html/CSS%20on%20Khan%20Academy" rel="noopener noreferrer"&gt;Intro to HTML/CSS on Khan Academy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://smacss.com/" rel="noopener noreferrer"&gt;SMACSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://getbem.com/introduction/" rel="noopener noreferrer"&gt;BEM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://suitcss.github.io/" rel="noopener noreferrer"&gt;SUIT CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/css-modules/css-modules" rel="noopener noreferrer"&gt;CSS Modules Specification&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/yangshun/tech-interview-handbook/blob/master/front-end/interview-questions.md#html-questions" rel="noopener noreferrer"&gt;Answers to Front End Job Interview Questions — HTML&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/yangshun/tech-interview-handbook/blob/master/front-end/interview-questions.md#css-questions" rel="noopener noreferrer"&gt;Answers to Front End Job Interview Questions — CSS&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/cssinjs/jss" rel="noopener noreferrer"&gt;JSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/styled-components/styled-components" rel="noopener noreferrer"&gt;Styled Components&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Maintainability
&lt;/h2&gt;

&lt;p&gt;Code is read more frequently than it is written. When you work in a large team and are involved with multiple teams across multiple projects. Then it is extremely important to highly value readability, maintainability and stability of the code and there are a few ways to achieve that: “Extensive testing”, “Consistent coding style” and “Typechecking”.&lt;/p&gt;

&lt;p&gt;Also when you are in a team, sharing same practices becomes really important. If you are a beginner then read about &lt;a href="https://github.com/elsewhencode/project-guidelines" rel="noopener noreferrer"&gt;JavaScript project guidelines&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linting JavaScript – ESLint &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A linter is a tool to statically analyze code and finds problems with them, potentially preventing bugs/runtime errors and at the same time, enforcing a coding style. Time is saved during pull request reviews when reviewers do not have to leave nitpicky comments on coding style. &lt;a href="http://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; is a tool for linting JavaScript code that is highly extensible and customizable. Teams can write their own lint rules to enforce their custom styles. At Grab, we use Airbnb’s &lt;a href="https://www.npmjs.com/package/eslint-config-airbnb" rel="noopener noreferrer"&gt;eslint-config-airbnb&lt;/a&gt; preset, that has already been configured with the common good coding style in the &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;Airbnb JavaScript style guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For the most part, using ESLint is as simple as tweaking a configuration file in your project folder. There’s nothing much to learn about ESLint if you’re not writing new rules for it. Just be aware of the errors when they surface and Google it to find out the recommended style.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 2 – 3 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://eslint.org/" rel="noopener noreferrer"&gt;ESlint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;Airbnb Style Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/standard/standard" rel="noopener noreferrer"&gt;Standard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jshint.com/" rel="noopener noreferrer"&gt;JSHint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/xojs/xo" rel="noopener noreferrer"&gt;XO&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Linting CSS – stylelint  &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;As mentioned earlier, good CSS is notoriously hard to write. Usage of static analysis tools on CSS can help to maintain our CSS code quality and coding style. For linting CSS, we use stylelint. Like ESLint, stylelint is designed in a very modular fashion, allowing developers to turn rules on/off and write custom plugins for it. Besides CSS, stylelint is able to parse SCSS and has experimental support for Less, which lowers the barrier for most existing code bases to adopt it.&lt;/p&gt;

&lt;p&gt;Once you have learnt ESLint, learning stylelint would be effortless considering their similarities. stylelint is currently being used by big companies like Facebook, Github and WordPress.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 2 – 3 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stylelint.io/" rel="noopener noreferrer"&gt;Stylelint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/stylelint/" rel="noopener noreferrer"&gt;Lint your CSS with stylelint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/sasstools/sass-lint" rel="noopener noreferrer"&gt;Sass Lint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://csslint.net/" rel="noopener noreferrer"&gt;CSS Lint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Formatting Code – Prettier &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Another tool for enforcing consistent coding style for JavaScript and CSS is Prettier.&lt;/p&gt;

&lt;p&gt;In most cases, it is recommended to setup Prettier on top of ESLint and stylelint and integrate it into the workflow. This allows the code to be formatted into consistent style automatically via commit hooks, so that developers do not need to spend time formatting the coding style manually.&lt;/p&gt;

&lt;p&gt;Note that Prettier only enforces coding style, but does not check for logic errors in the code. Hence it is not a replacement for linters.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 2 – 3 days (3 – 4 hrs daily). Add prettier extension to your code editor.&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/yangshun/318102f525ec68033bf37ac4a010eb0c" rel="noopener noreferrer"&gt;Comparison between tools that allow you to use ESLint and Prettier together&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Testing – Jest + Enzyme &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;All the above helps to preventing bugs/runtime errors, but once something has been built, it has to be tested to make sure it is meeting all the requirements and working as expected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://facebook.github.io/jest/" rel="noopener noreferrer"&gt;Jest&lt;/a&gt; is a testing library by Facebook that aims to make the process of testing pain-free. As with Facebook projects, it provides a great development experience out of the box. Tests can be run in parallel resulting in shorter duration. During watch mode, by default, only the tests for the changed files are run. One particular feature we like is “Snapshot Testing”. Jest can save the generated output of your React component and Redux state and save it as serialized files, so you wouldn’t have to manually come up with the expected output yourself. Jest also comes with built-in mocking, assertion and test coverage. One library to rule them all!.&lt;/p&gt;

&lt;p&gt;React comes with some testing utilities, but &lt;a href="http://airbnb.io/enzyme/" rel="noopener noreferrer"&gt;Enzyme&lt;/a&gt; by Airbnb makes it easier to generate, assert, manipulate and traverse your React components’ output with a jQuery-like API. It is recommended that Enzyme be used to test React components.&lt;/p&gt;

&lt;p&gt;Jest and Enzyme makes writing front end tests fun and easy. When writing tests becomes enjoyable, developers write more tests. It also helps that React components and Redux actions/reducers are relatively easy to test because of clearly defined responsibilities and interfaces. For React components, we can test that given some props, the desired DOM is rendered, and that callbacks are fired upon certain simulated user interactions. For Redux reducers, we can test that given a prior state and an action, a resulting state is produced.&lt;/p&gt;

&lt;p&gt;The documentation for Jest and Enzyme are pretty concise, and it should be sufficient to learn them by reading it.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://facebook.github.io/jest/" rel="noopener noreferrer"&gt;Jest Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://auth0.com/blog/testing-react-applications-with-jest/" rel="noopener noreferrer"&gt;Testing React Applications with Jest&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://airbnb.io/enzyme/" rel="noopener noreferrer"&gt;Enzyme Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/airbnb-engineering/enzyme-javascript-testing-utilities-for-react-a417e5e5090f" rel="noopener noreferrer"&gt;Enzyme: JavaScript Testing utilities for React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/avajs/ava" rel="noopener noreferrer"&gt;AVA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://karma-runner.github.io/" rel="noopener noreferrer"&gt;Karma&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Deployment and Hosting
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Version Control System – GIT &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/gittutorial" rel="noopener noreferrer"&gt;Git&lt;/a&gt; is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different systems).&lt;/p&gt;

&lt;p&gt;From its definition you would have already realized why GIT is used, it helps us to track the files and folders. If there is any addition or modification to any part in the project, you can track that using git.&lt;/p&gt;

&lt;p&gt;The changes are tracked on your local system with corresponding to the remote repository where the whole code base is maintained (A central system).&lt;/p&gt;

&lt;p&gt;when we work in team, everyone works on different things, thus we there is a need of a central repository where the whole code base will be maintained. Once you code changes are done, you push that changes to the central repo and pull the others code as per your requirement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; is a provider of Internet hosting for software development and version control using Git. All the major cloud service provides provides there own central repository storage service.&lt;/p&gt;

&lt;p&gt;It important that you are familiar with basic git commands to work in collaborative environment.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/gittutorial" rel="noopener noreferrer"&gt;Git official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials" rel="noopener noreferrer"&gt;Atlassian (BitBucket) Git Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=8JJ101D3knE" rel="noopener noreferrer"&gt;Git tutorial – Youtube&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.mercurial-scm.org/" rel="noopener noreferrer"&gt;Mercurial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-in/services/devops/server/" rel="noopener noreferrer"&gt;Azure DevOps Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://subversion.apache.org/" rel="noopener noreferrer"&gt;Subversion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Package Management – NPM &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A good developer does smart work rather than hard work, if there is something already build then it is wise to use that rather than building something of yourself.&lt;/p&gt;

&lt;p&gt;Thus to download and manage all those we need a package manager. &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;Npm&lt;/a&gt; (Node Package Manager) is a package manager for the JavaScript programming language maintained by npm, Inc.&lt;/p&gt;

&lt;p&gt;Npm is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry. The registry is accessed via the client, and the available packages can be browsed and searched via the npm website. The package manager and the registry are managed by npm, Inc.&lt;/p&gt;

&lt;p&gt;All the packages that are download using npm are registered in &lt;code&gt;package.json&lt;/code&gt; file and files and folder are stored inside the &lt;code&gt;node_modules&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;package-lock.json&lt;/code&gt; is another file which is update every time when you add a new package to your project. It is automatically generated for any operations where npm modifies either the &lt;code&gt;node_modules&lt;/code&gt; tree, or &lt;code&gt;package.json&lt;/code&gt;. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.&lt;/p&gt;

&lt;p&gt;This file is intended to be committed into source repositories, and serves various purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Describe a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.
-Provide a facility for users to “time-travel” to previous states of node_modules without having to commit the directory itself.
-Facilitate greater visibility of tree changes through readable source control diffs.
-Optimize the installation process by allowing npm to skip repeated metadata resolutions for previously-installed packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estimated time to learn:- 3 – 4 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/npm-cheat-sheet-most-common-commands-and-nvm/" rel="noopener noreferrer"&gt;NPM Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=bdHE2wHT-gQ" rel="noopener noreferrer"&gt;Getting started with NPM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternative
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://code.facebook.com/posts/1840075619545360" rel="noopener noreferrer"&gt;Yarn: A new package manager for JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Build System – webpack &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This part will be kept short as setting up webpack can be a tedious process and might be a turn-off to developers who are already overwhelmed by the barrage of new things they have to learn for front end development. In a nutshell, webpack is a module bundler that compiles a front end project and its dependencies into a final bundle to be served to users. Usually, projects will already have the webpack configuration set up and developers rarely have to change it. Having an understanding of webpack is still a good to have in the long run. It is due to webpack that features like hot reloading and CSS modules are made possible.&lt;/p&gt;

&lt;p&gt;We have found the webpack walkthrough by &lt;a href="https://survivejs.com/webpack/foreword/" rel="noopener noreferrer"&gt;SurviveJS&lt;/a&gt; to be the best resource on learning webpack. It is a good complement to the official documentation and we recommend following the walkthrough first and referring to the documentation later when the need for further customization arises.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://survivejs.com/webpack/foreword/" rel="noopener noreferrer"&gt;SurviveJS – Webpack: From apprentice to master&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rollupjs.org/" rel="noopener noreferrer"&gt;Rollup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://browserify.org/" rel="noopener noreferrer"&gt;Browserify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://parceljs.org/" rel="noopener noreferrer"&gt;Parcel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Deployment – CI/CD &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;When you commit your code to the github and once your pull request is approved and merged in the codebase, before deploying it on any cloud service it has to again generate the build and run set of test to make sure things won’t break on the production.&lt;/p&gt;

&lt;p&gt;For this we often use tool, which helps us in continuous integration and deployement. Jenkins is one of the most popular Continuous Integration and Continuous Delivery server provider.&lt;/p&gt;

&lt;p&gt;It helps us to run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run linting for the project.&lt;/li&gt;
&lt;li&gt;Run unit tests for the project.&lt;/li&gt;
&lt;li&gt;If all the test cases pass then generate a production bundle with webpack into a build directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once setup and configured it can be automatically/manually triggered to run the build pipeline and once the build is generated, it can be deployed using release pipeline.&lt;/p&gt;

&lt;p&gt;Often there is a separate team (Devops) who handle it configuration and setting up the CI/CD environment, but if you want you can still learn it. Being familiar with basic things is always good.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 3 – 4 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=FX322RVNGj4" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://about.gitlab.com/product/continuous-integration/" rel="noopener noreferrer"&gt;GitLab CI/CD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://circleci.com/" rel="noopener noreferrer"&gt;CircleCI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://travis-ci.com/" rel="noopener noreferrer"&gt;TravisCI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Hosting and CDN &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Traditionally, web servers that receive a request for a webpage will render the contents on the server, and return a HTML page with dynamic content meant for the requester. This is known as server-side rendering. As mentioned earlier in the section on Single-page Apps, modern web applications do not involve server-side rendering, and it is sufficient to use a web server that serves static asset files. Nginx and Apache are possible options and not much configuration is required to get things up and runnning. The caveat is that the web server will have to be configured to route all requests to a single entry point and allow client-side routing to take over. The flow for front end routing goes like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web server receives a HTTP request for a particular route, for example &lt;code&gt;/user/john&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Regardless of which route the server receives, serve up &lt;code&gt;index.html&lt;/code&gt; from the static assets directory.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;index.html&lt;/code&gt; should contain scripts that load up a JavaScript framework/library that handles client-side routing.&lt;/li&gt;
&lt;li&gt;The client-side routing library reads the current route, and communicates to the MVC (or equivalent where relevant) framework about the current route.&lt;/li&gt;
&lt;li&gt;The MVC JavaScript framework renders the desired view based on the route, possibly after fetching data from an API if required. Example, load up &lt;code&gt;UsersController&lt;/code&gt;, fetch user data for the username john as JSON, combine the data with the view, and render it on the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good practice for serving static content is to use caching and putting them on a CDN. We use &lt;a href="https://aws.amazon.com/s3/" rel="noopener noreferrer"&gt;Amazon Simple Storage Service (S3)&lt;/a&gt; for hosting our static website content and &lt;a href="https://aws.amazon.com/cloudfront/" rel="noopener noreferrer"&gt;Amazon CloudFront&lt;/a&gt; as the CDN. We find that it is an affordable and reliable solution that meets our needs.&lt;/p&gt;

&lt;p&gt;S3 provides the option to “Use this bucket to host a website”, which essentially directs the requests for all routes to the root of the bucket, which means we do not need our own web servers with special routing configurations.&lt;/p&gt;

&lt;p&gt;An example of a web app that we host on S3 is &lt;a href="https://hub.grab.com/" rel="noopener noreferrer"&gt;Hub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Other than hosting the website, we also use S3 to host the build files generated from each successful CI build.&lt;/p&gt;

&lt;p&gt;In Visual Studio Code using an extension you can directly &lt;a href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website-host" rel="noopener noreferrer"&gt;deploy static site on Azure and host it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 3 – 4 days (3 – 4 hrs daily). &lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html" rel="noopener noreferrer"&gt;Hosting a Static Website on Amazon S3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-in/" rel="noopener noreferrer"&gt;Microsoft Azure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/" rel="noopener noreferrer"&gt;Google cloud platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/" rel="noopener noreferrer"&gt;Digital Ocean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Advanced Topics
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Static Types – Typescript &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Static typing brings about many benefits when writing apps. They can catch common bugs and errors in your code early. Types also serve as a form of documentation for your code and improves the readability of your code. As a code base grows larger, we see the importance of types as they gives us greater confidence when we do refactoring. It is also easier to onboard new members of the team to the project when it is clear what kind of values each object holds and what each function expects.&lt;/p&gt;

&lt;p&gt;Adding types to your code comes with the trade-off of increased verbosity and a learning curve of the syntax. But this learning cost is paid upfront and amortized over time. In complex projects where the maintainability of the code matters and the people working on it change over time, adding types to the code brings about more benefits than disadvantages.&lt;/p&gt;

&lt;p&gt;The two biggest contenders in adding static types to JavaScript are Flow (by Facebook) and TypeScript (by Microsoft). As of date, there is no clear winner in the battle.&lt;/p&gt;

&lt;p&gt;You can choose anyone of them but I personally prefer TypeScript. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. TypeScript is designed for the development of large applications and &lt;a href="https://en.wikipedia.org/wiki/Source-to-source_compiler" rel="noopener noreferrer"&gt;transcompiles&lt;/a&gt; to JavaScript. As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs.&lt;/p&gt;

&lt;p&gt;TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js or Deno). There are multiple options available for transcompilation. Either the default TypeScript Checker can be used, or the Babel compiler can be invoked to convert TypeScript to JavaScript.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 7 – 10 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=WBPrJSw7yQA" rel="noopener noreferrer"&gt;Learn TypeScript in 50 Minutes – Tutorial for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=BwuLxPH8IDs" rel="noopener noreferrer"&gt;TypeScript Course for Beginners 2021 – Learn TypeScript from Scratch!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://flow.org/" rel="noopener noreferrer"&gt;Flow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/niieani/typescript-vs-flowtype" rel="noopener noreferrer"&gt;TypeScript vs Flow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Mobile App Development – React Native &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It is now possible to create cross device mobile applications using just HTML, CSS, JavaScript. Thus it opened a large boundary for web developers to migrate to different platform and do the development using same technology.&lt;/p&gt;

&lt;p&gt;React Native is a JavaScript framework for building native mobile apps. React Native brings React’s declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.&lt;/p&gt;

&lt;p&gt;Following features are what makes React Native an idle choice.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Declarative&lt;/strong&gt;: React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component-Based&lt;/strong&gt;: Build encapsulated components that manage their state, then compose them to make complex UIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Developer Velocity&lt;/strong&gt;: See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability&lt;/strong&gt;: Reuse code across iOS, Android, and &lt;a href="https://reactnative.dev/docs/out-of-tree-platforms" rel="noopener noreferrer"&gt;other platforms&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estimated time to learn:- 20 – 30 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/react-native" rel="noopener noreferrer"&gt;React Native official DOC.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=0-S5a0eXPoc" rel="noopener noreferrer"&gt;React Native Tutorial for Beginners – Build a React Native App [2020]&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cordova.apache.org/" rel="noopener noreferrer"&gt;Cordova&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ionicframework.com/" rel="noopener noreferrer"&gt;Ionic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Desktop App Development – Electron JS &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Not only mobile apps but using HTML, CSS, JavaScript you can now build desktop apps as well. The most popular framework for it right now is &lt;a href="https://www.electronjs.org/" rel="noopener noreferrer"&gt;ElectronJs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;ElectronJs combines the &lt;a href="https://en.wikipedia.org/wiki/Chromium_(web_browser)" rel="noopener noreferrer"&gt;Chromium rendering engine&lt;/a&gt; and the &lt;a href="https://en.wikipedia.org/wiki/Node.js" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; runtime allowing for the development of desktop GUI applications using web technologies.&lt;/p&gt;

&lt;p&gt;Electron applications comprise multiple processes. There is the “main” process and several “renderer” processes. The main process runs the application logic, and can then launch multiple renderer processes, rendering the windows that appear on a user’s screen rendering HTML and CSS.&lt;/p&gt;

&lt;p&gt;Both the main and renderer processes can run with Node.js integration if enabled.&lt;/p&gt;

&lt;p&gt;Most of Electron’s APIs are written in C++ or Objective-C and then exposed directly to the application code through JavaScript bindings.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 20 – 30 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=mr9Mtm_TRpw" rel="noopener noreferrer"&gt;An Intro To Electron – Desktop Apps with JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=kN1Czs0m1SU" rel="noopener noreferrer"&gt;Build an Electron App in Under 60 Minutes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nwjs.io/" rel="noopener noreferrer"&gt;NW.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://appjs.com/" rel="noopener noreferrer"&gt;AppJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.meteor.com/" rel="noopener noreferrer"&gt;Meteor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Server Side Rendering – Next.js &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It is still a viable option to do server side rendering while leveraging the decoupled development capability of server and client or the best of both, some part can be rendered on server side, while some can be updated as per requirement on client side. It really helps enhancing the applications performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt; is an open-source development framework built on top of Node.js enabling React based web applications functionalities such as server-side rendering and generating static websites. React documentation mentions Next.js among “Recommended Toolchains” advising it to developers as a solution when “building a server-rendered website with Node.js”. Traditional React apps render all their content in the client-side browser, Next.js is used to extend this functionality to include applications rendered on the server side.&lt;/p&gt;

&lt;p&gt;Estimated time to learn:- 10 – 20 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nextjs.org/learn/basics/create-nextjs-app" rel="noopener noreferrer"&gt;Create a Next.js App&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=MFuwkrseXVE" rel="noopener noreferrer"&gt;Next.js Crash Course for Beginners 2021&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=mTz0GXj8NN0" rel="noopener noreferrer"&gt;Next.js Crash Course 2021&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alternatives
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/" rel="noopener noreferrer"&gt;Gatsbyjs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nuxtjs.org/" rel="noopener noreferrer"&gt;NuxtJS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Progressive Web Apps (PWA): The future of web development. &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;A progressive web application (PWA) is a type of application software delivered through the web, built using common web technologies including HTML, CSS and JavaScript. It is intended to work on any platform that uses a standards-compliant browser, including both desktop and mobile devices.&lt;/p&gt;

&lt;p&gt;Progressive Web Apps (PWA) are built and enhanced with modern APIs to deliver enhanced capabilities, reliability, and installability while reaching anyone, anywhere, on any device with a single codebase.&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%2Fweb-dev.imgix.net%2Fimage%2FtcFciHGuF3MxnTr1y5ue01OGLBn2%2F1DKtUFjXLJbiiruKA9P1.svg" 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%2Fweb-dev.imgix.net%2Fimage%2FtcFciHGuF3MxnTr1y5ue01OGLBn2%2F1DKtUFjXLJbiiruKA9P1.svg" alt="PWA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three app pillars of a PWA:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Capable&lt;/strong&gt;: Between modern APIs, WebAssembly, and new and upcoming APIs, web applications are more capable than ever, and those capabilities are only growing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reliable&lt;/strong&gt;: A reliable Progressive Web App feels fast and dependable regardless of the network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Installable&lt;/strong&gt;: Installed Progressive Web Apps run in a standalone window instead of a browser tab. They’re launchable from on the user’s home screen, dock, taskbar, or shelf. It’s possible to search for them on a device and jump between them with the app switcher, making them feel like part of the device they’re installed on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What makes a good Progressive Web App?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Starts fast, stays fast&lt;/strong&gt;: Performance plays a significant role in the success of any online experience, because high performing sites engage and retain users better than poorly performing ones. Sites should focus on optimizing for user-centric performance metrics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Works in any browser&lt;/strong&gt;: Users can use any browser they choose to access your web app before it’s installed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive to any screen size&lt;/strong&gt;: Users can use your PWA on any screen size and all of the content is available at any viewport size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provides a custom offline page&lt;/strong&gt;: When users are offline, keeping them in your PWA provides a more seamless experience than dropping back to the default browser offline page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is installable&lt;/strong&gt;: Users who install or add apps to their device tend to engage with those apps more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is fully accessible&lt;/strong&gt;: All user interactions pass WCAG 2.0 accessibility requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can be discovered through search&lt;/strong&gt;: Your PWA can be easily discovered through search.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Works with any input type&lt;/strong&gt;: Your PWA is equally usable with a mouse, a keyboard, a stylus, or touch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provides context for permission requests&lt;/strong&gt;: When asking permission to use powerful APIs, provide context and ask only when the API is needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Follows best practices for healthy code&lt;/strong&gt;: Keeping your codebase healthy makes it easier to meet your goals and deliver new features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estimated time to learn:- 7 – 15 days (3 – 4 hrs daily).&lt;/p&gt;

&lt;h4&gt;
  
  
  Study Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://web.dev/progressive-web-apps/" rel="noopener noreferrer"&gt;Web.dev&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Miscellaneous articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.infoq.com/articles/state-of-javascript-2016" rel="noopener noreferrer"&gt;State of the JavaScript Landscape: A Map for Newcomers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://marcobotto.com/the-hitchhikers-guide-to-the-modern-front-end-development-workflow/" rel="noopener noreferrer"&gt;The Hitchhiker’s guide to the modern front end development workflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://trackchanges.postlight.com/modern-javascript-for-ancient-web-developers-58e7cae050f9" rel="noopener noreferrer"&gt;Modern JavaScript for Ancient Web Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.freecodecamp.com/a-study-plan-to-cure-javascript-fatigue-8ad3a54f2eb1#.c0wnrrcwd" rel="noopener noreferrer"&gt;A Study Plan To Cure JavaScript Fatigue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/verekia/js-stack-from-scratch" rel="noopener noreferrer"&gt;JS Stack from Scratch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.freecodecamp.com/a-beginners-javascript-study-plan-27f1d698ea5e#.bgf49xno2" rel="noopener noreferrer"&gt;A Beginner’s JavaScript Study Plan&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article was based on &lt;a href="https://github.com/grab/front-end-guide" rel="noopener noreferrer"&gt;Grab’s – Frontend Guide&lt;/a&gt; and I have just add few extra things to it.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Fullstack (Nodejs + Reactjs) interview experience at Nutanix</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Tue, 10 Aug 2021 05:50:40 +0000</pubDate>
      <link>https://dev.to/learnersbucket/fullstack-nodejs-reactjs-interview-experience-at-nutanix-403i</link>
      <guid>https://dev.to/learnersbucket/fullstack-nodejs-reactjs-interview-experience-at-nutanix-403i</guid>
      <description>&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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FFullstack-Nodejs-ReactJs-SASS-Nutanix-Interview-Experience-1.png%3Fw%3D768%26ssl%3D1" 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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FFullstack-Nodejs-ReactJs-SASS-Nutanix-Interview-Experience-1.png%3Fw%3D768%26ssl%3D1" alt="Fullstack interview experience at Nutanix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your JavaScript interview. You will find DSA, System Design and JavaScript Questions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I had applied for the MTS-3 Fullstack – SAAS (Nodejs + Reactjs) on Nutanix’s career section and got the shortlisting email on 21’st April 2021. It was for the Bangalore location.&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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FNutanix-hiring.png%3Fw%3D709%26ssl%3D1" 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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FNutanix-hiring.png%3Fw%3D709%26ssl%3D1" alt="Shortlisting email from Nutanix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the email, the recruiter called me and we had brief introduction about myself, my experience, etc and what are they looking for in the candidate and about the Nutanix and role.&lt;/p&gt;

&lt;h2&gt;
  
  
  1st Round: Phone screen (SDE2 – Full Stack)
&lt;/h2&gt;

&lt;p&gt;I was asked what I do on a daily basis, followed by some JavaScript questions and some Rest API questions.&lt;/p&gt;

&lt;p&gt;It went well.&lt;/p&gt;

&lt;h2&gt;
  
  
  2nd Round: JavaScript Platform &amp;amp; DSA. (SDE3 – Full Stack)
&lt;/h2&gt;

&lt;p&gt;Don’t remember about the interviewer.&lt;/p&gt;

&lt;p&gt;In this round I was asked to implement programs based on Closure, Promise and Objects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/interview/deep-flatten-object-in-javascript-1" rel="noopener noreferrer"&gt;Deep Flatten an object&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/array/how-to-flat-an-array-in-javascript" rel="noopener noreferrer"&gt;Flat an array&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/interview/what-is-debouncing-in-javascript" rel="noopener noreferrer"&gt;Debounce&lt;/a&gt; and its variations using promise.&lt;/li&gt;
&lt;li&gt;Where do we need to use async code in Nodejs, why?. Etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was a good round, and I learned lots of things. Went good.&lt;/p&gt;

&lt;h2&gt;
  
  
  3rd Round: System Design (Frontend + Backend) (Team lead – Full Stack)
&lt;/h2&gt;

&lt;p&gt;The interviewer had around 9 years of experience and was leading the team which I was being hired for, we exchanged introductions and started the interview.&lt;/p&gt;

&lt;p&gt;As I was being hired for the Payment &amp;amp; Pricing team.&lt;/p&gt;

&lt;p&gt;This round was mainly focused towards creating dynamic form and handling the payment and pricing based on the features selected.&lt;/p&gt;

&lt;p&gt;Security, CORs, XSS.&lt;/p&gt;

&lt;p&gt;How to secure your API, Server side vs Client Side, which to use for security purposes?. What if the same has to be achieved on the alternate side &amp;amp; vice versa.&lt;/p&gt;

&lt;p&gt;Lots of discussion of form handling and uncontrolled and controlled form components. Select box, etc.&lt;/p&gt;

&lt;p&gt;I haven’t read about security still it went well.&lt;/p&gt;

&lt;h2&gt;
  
  
  4th round: System Design (Javascript) (Manager – Pricing &amp;amp; Payment Team)
&lt;/h2&gt;

&lt;p&gt;The interviewer was quite nice, he first introduced himself and what they are looking for in a candidate who will join this team, what type of work will be there, etc.&lt;/p&gt;

&lt;p&gt;I was asked to implement a &lt;a href="https://learnersbucket.com/examples/interview/number-increment-counter-in-javascript-react" rel="noopener noreferrer"&gt;Number increment counter in JS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this round, I came up with a solution using &lt;a href="https://learnersbucket.com/examples/javascript/javascript-settimeout-method" rel="noopener noreferrer"&gt;setTimeout&lt;/a&gt; and &lt;a href="https://learnersbucket.com/examples/javascript/javascript-setinterval-method" rel="noopener noreferrer"&gt;setInterval&lt;/a&gt;, even though it was not perfect he pushed me to the next round.&lt;/p&gt;

&lt;h2&gt;
  
  
  5th round: DSA (VP – Pricing &amp;amp; Payment Team)
&lt;/h2&gt;

&lt;p&gt;The interviewer was from San Jose and he was a little strange.&lt;/p&gt;

&lt;p&gt;He asked me to introduce myself and when I was done, after a pause he unmuted and asked that’s it?. Please elaborate a little. I thought he was doing something else simultaneously and not concentrating towards the interview.&lt;/p&gt;

&lt;p&gt;Later he asked me to implement an algorithm to count all possible subarrays in an array with sum k. (Note:- They are not consecutive).&lt;/p&gt;

&lt;p&gt;As I had to find all the possible sub arrays, I thought of using Dynamic Programming first.&lt;/p&gt;

&lt;p&gt;But the interviewer asked me to implement an O(N ^ 2) algorithm.&lt;/p&gt;

&lt;p&gt;Failed in this. He showed me the solution using the bitwise operator.&lt;/p&gt;

&lt;p&gt;At the end he was constantly asking me from where I come?, where I am living. In Spite of repeatedly telling him that I live in Mumbai and having been born and brought up here. He was not ready to accept it. I was getting a feeling that he has some personal issue with name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;NOT SELECTED.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I guess because my 4th round went okay and 5th round went bad they dropped me. Interviewer asked me to apply in different verticals, but I lost my interest and so I left it.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Frontend Interview Experience at Amazon Germany</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Mon, 02 Aug 2021 07:08:39 +0000</pubDate>
      <link>https://dev.to/learnersbucket/frontend-interview-experience-at-amazon-germany-2lom</link>
      <guid>https://dev.to/learnersbucket/frontend-interview-experience-at-amazon-germany-2lom</guid>
      <description>&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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FFrontend-Interview-Experience-At-Amazon-Germany.-1.png%3Fw%3D768%26ssl%3D1" 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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FFrontend-Interview-Experience-At-Amazon-Germany.-1.png%3Fw%3D768%26ssl%3D1" alt="Frontend Interview Experience at Amazon Germany"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your JavaScript interview. You will find DSA, System Design and JavaScript Questions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After applying at Amazon India through different means and not hearing back from them, I one day randomly applied at Amazon Germany for frontend role directly in the career section and luckily my resume got shortlisted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note:- As I have signed an NDA, I cannot share the exact questions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I received the email regarding the shortlist and was asked to fill availability for the phone screen.&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%2Fi1.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon_Shortlisting-1.png%3Fw%3D795%26ssl%3D1" 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%2Fi1.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon_Shortlisting-1.png%3Fw%3D795%26ssl%3D1" alt="Shortlisting email"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1st round : Phone Interview.
&lt;/h2&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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon-1st-round-1.png%3Fw%3D786%26ssl%3D1" 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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon-1st-round-1.png%3Fw%3D786%26ssl%3D1" alt="Phone interview confirmation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was scheduled on 14th June and I had a general discussion with the technical recruiter regarding what I do on a day to day basis followed by a behavioral question and after that he asked me if I was willing to relocate and what are my salary expectations, etc.&lt;/p&gt;

&lt;p&gt;He said that your final interview will be scheduled only after your second round goes well.&lt;/p&gt;

&lt;h2&gt;
  
  
  2nd round: Phone screen with Manager.
&lt;/h2&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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon-2nd-round-1.png%3Fw%3D1013%26ssl%3D1" 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%2Fi0.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F08%2FAmazon-2nd-round-1.png%3Fw%3D1013%26ssl%3D1" alt="2nd Round: Managerial"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second round was on 2nd July and it was taken by the manager. He asked me to create a web component followed by lots of questions and changes and one CSS styling question. At the end there was a behavioral question.&lt;/p&gt;

&lt;p&gt;After that he said will you relocate or work from India?. We are looking for a team member to join us here.&lt;/p&gt;

&lt;h2&gt;
  
  
  3rd &amp;amp; Final round
&lt;/h2&gt;

&lt;p&gt;It was composed of 5 technical rounds to be done on a single day. The decided date was 28th of July.&lt;/p&gt;

&lt;p&gt;I was very nervous before this as I knew I am not well prepared.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.a:- OOPs (Backend engineer with 9+ years of experience) (same team).
&lt;/h3&gt;

&lt;p&gt;We had a formal introduction followed by one behavioral question and then an oops question, In the end there were two more behavioral questions.&lt;/p&gt;

&lt;p&gt;The implementation had to be scalable, otherwise it does not meets the criteria of the question.&lt;/p&gt;

&lt;p&gt;This round did not go well because I haven’t prepared for OOPS.&lt;/p&gt;

&lt;p&gt;My confidence took a toll.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.b:- Frontend (Frontend engineer 5+ years of experience) (same team).
&lt;/h3&gt;

&lt;p&gt;I was asked to create a component, followed by lots of questions on accessibility, styling, events, etc.&lt;/p&gt;

&lt;p&gt;In the end 3 behavioral questions.&lt;/p&gt;

&lt;p&gt;Finished this round in half an hour, It went superb. Boosted my confidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.c:- Cultural fit (BI data engineer) (different team).
&lt;/h3&gt;

&lt;p&gt;Taken by an external team member for unbiased opinion. Solely based on behavioral questions, 6 of them.&lt;/p&gt;

&lt;p&gt;All were very different, Had to think about everything I have done in my past experiences and then answer it.&lt;/p&gt;

&lt;p&gt;It went okay.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.d:- Managerial (System design) (same team).
&lt;/h3&gt;

&lt;p&gt;He said let’s start by answering your questions first and then move forward. After that he asked me to implement a frontend system.&lt;/p&gt;

&lt;p&gt;Discussed the following points&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Layout&lt;/li&gt;
&lt;li&gt;Styling&lt;/li&gt;
&lt;li&gt;Accessibility&lt;/li&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;li&gt;Tracking user activity&lt;/li&gt;
&lt;li&gt;Recommendations&lt;/li&gt;
&lt;li&gt;Preferences&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Followed by 3 behavioral questions.&lt;/p&gt;

&lt;p&gt;This round went nice, the manager seemed to be happy.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.e:- DSA (FullStack engineer) (Sister team).
&lt;/h3&gt;

&lt;p&gt;Was asked to implement a two way algorithm based on trees. Tree to HTML and HTML to Tree parser with lots of constraints.&lt;/p&gt;

&lt;p&gt;Which tree will you choose, why?. How to differentiate nodes and text, etc.&lt;/p&gt;

&lt;p&gt;Followed by 3 behavioral questions.&lt;/p&gt;

&lt;p&gt;This round did not go well, I had tough time understanding the question. After 1st implementation, the interviewer said there is some misunderstanding and explained the question again and asked me to re-implement the solution.&lt;/p&gt;

&lt;p&gt;After second implementation, he asked me to implement the second parser (vice versa).&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;NOT SELECTED.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The recruiter called me next day and personally gave the feedback, he said there a lots of strong points and push but the team thinks that you need some improvements majorly on writing scalable and maintainable code.&lt;/p&gt;

&lt;p&gt;The recruiter had already told me to go through leadership principles and STAR technique because you will be grilled a lot on that.&lt;/p&gt;

&lt;p&gt;I was already hesitant that I won’t be able to make it. Still I did my best.&lt;/p&gt;

&lt;h3&gt;
  
  
  My strength
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Frontend components.&lt;/li&gt;
&lt;li&gt;System design.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  My weakness
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;OOPs&lt;/li&gt;
&lt;li&gt;DSA&lt;/li&gt;
&lt;li&gt;Behavioral questions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have noted where I have to improve and will work on it.&lt;/p&gt;

&lt;p&gt;Long way to go. Life long learning. Keep Hustling 🤞.&lt;/p&gt;

&lt;p&gt;PS:- I have 5 more interview experiences which I will share in the coming weeks.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Dream11 – SDE2 – Frontend Interview Experience</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Tue, 06 Apr 2021 05:10:12 +0000</pubDate>
      <link>https://dev.to/learnersbucket/dream11-sde2-frontend-interview-experience-5a65</link>
      <guid>https://dev.to/learnersbucket/dream11-sde2-frontend-interview-experience-5a65</guid>
      <description>&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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F03%2FDream11-SDE2-Frontend-Interview-Experience-1.png%3Fw%3D768%26ssl%3D1" 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%2Fi2.wp.com%2Flearnersbucket.com%2Fwp-content%2Fuploads%2F2021%2F03%2FDream11-SDE2-Frontend-Interview-Experience-1.png%3Fw%3D768%26ssl%3D1" alt="Dream11 - SDE2 - Frontend Interview Experience"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Visit &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; If you are preparing for your Javascript interview. I have written solutions for more than 300+ solved algorithms and implementation of all important data structures in JS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I had applied on Dream11 career section for SDE2 Frontend position in March 2021.&lt;/p&gt;

&lt;h3&gt;
  
  
  Round 1: Hacker rank test
&lt;/h3&gt;

&lt;p&gt;3 questions to be solved in 90 minutes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert binary linked list to decimal.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/algorithms/coin-change-problem" rel="noopener noreferrer"&gt;Coin change problem&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/last-stone-weight/" rel="noopener noreferrer"&gt;Last stone weight&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Round 2: DSA
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://learnersbucket.com/examples/algorithms/find-the-largest-sum-of-contiguous-subarray" rel="noopener noreferrer"&gt;Largest contiguous subarray&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Common nodes in two binary search tree.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Round 3: Platform round (Javascript)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Implement a function &lt;strong&gt;onlyTwice&lt;/strong&gt; which stores two instances a function invocation and returns first on odd calls and second on even calls. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was based on singleton design pattern.&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;addTwoNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFancyAdd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;onlyTwice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addTwoNumbers&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="nf"&gt;myFancyAdd&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="c1"&gt;// 5&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="nf"&gt;myFancyAdd&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="c1"&gt;// 3&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="nf"&gt;myFancyAdd&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="c1"&gt;// 5&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="nf"&gt;myFancyAdd&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;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  My answer
&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;onlyTwice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&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;let&lt;/span&gt; &lt;span class="nx"&gt;isOdd&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;first&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;second&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="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&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;isOdd&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;isOdd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;first&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="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="nx"&gt;second&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;second&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;isOdd&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;second&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create &lt;a href="https://learnersbucket.com/examples/javascript/what-is-throttling-in-javascript" rel="noopener noreferrer"&gt;throttle&lt;/a&gt; function. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a polyfill for promise which should handle following edge cases.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;prom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyPromise&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="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="s2"&gt;Done&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;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;span class="nx"&gt;prom&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="kd"&gt;function&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;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;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Prints "1 Done" after 1 second&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;prom&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="kd"&gt;function&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;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;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Prints "2 Done" after 1 second&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="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;prom&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="kd"&gt;function&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;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;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Prints "3 Done" after 2 seconds&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&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;nwPromise&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onReadyStateChange&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 

  &lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;nwPromise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  My code
&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;MyPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;// Code here&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;error&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;thenCallBackFunction&lt;/span&gt; &lt;span class="o"&gt;=&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;resolveState&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;resolveState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&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;thenCallBackFunction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&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;fn&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;thenCallBackFunction&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nf"&gt;fn&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="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;thenCallBackFunction&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="nx"&gt;resolveState&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="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt; &lt;span class="o"&gt;=&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;error&lt;/span&gt; &lt;span class="o"&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn2&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;thenCallBackFunction&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="nx"&gt;fn2&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;fn2&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="p"&gt;}&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="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;errorFn&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;errorFn&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cancelFn&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolveState&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="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;fn&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I did not implemented the .cancel() as there was no time left.&lt;/p&gt;

&lt;h3&gt;
  
  
  Round 4: System design
&lt;/h3&gt;

&lt;p&gt;Given the following API endpoints create a book reader.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/books (List of books with book IDs)
/book/:book_id/page_count (Returns page count for the requested book)
/book/:book_id/page/:page_number (Returns content for the requested page in RTE)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;It will show the list of books&lt;/li&gt;
&lt;li&gt;On click open the selected book&lt;/li&gt;
&lt;li&gt;Scroll to the next page (no pagination)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lots of cross question on&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle latency&lt;/li&gt;
&lt;li&gt;Debounce&lt;/li&gt;
&lt;li&gt;Direct jump to random page&lt;/li&gt;
&lt;li&gt;Caching pages&lt;/li&gt;
&lt;li&gt;Pre-loading data&lt;/li&gt;
&lt;li&gt;Buffer zone&lt;/li&gt;
&lt;li&gt;Optimization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I failed in the final in this round as the interviewer asked me that if I use debounce (2ms) to load the next page and consider that you are on a 2g network and there is delay of 10ms for response then how will you handle it. I got stuck here.&lt;/p&gt;

&lt;p&gt;Also he asked me that suppose your RAM will be able to store only 20 pages at a time then how would you jump to 300th page from the 100th page, when will you make the api call to fetch the page, will you show blank page or not, your scroll should end at 300th page, etc, etc.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>How I got my first job as a developer after failing for 300 times</title>
      <dc:creator>Prashant Yadav</dc:creator>
      <pubDate>Wed, 03 Jun 2020 05:37:40 +0000</pubDate>
      <link>https://dev.to/learnersbucket/how-i-got-my-first-job-as-a-developer-after-failing-for-300-times-1pko</link>
      <guid>https://dev.to/learnersbucket/how-i-got-my-first-job-as-a-developer-after-failing-for-300-times-1pko</guid>
      <description>&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%2Fi%2Fbm7941xcmq0lbyg1loln.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%2Fi%2Fbm7941xcmq0lbyg1loln.png" alt="How I got my first job as a developer after failing for 300 times"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hi, I am Prashant Yadav, Technical writer at &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had recently tweeted about what I had to go through for finding my first job as developer.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1265318896938221575-952" src="https://platform.twitter.com/embed/Tweet.html?id=1265318896938221575"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1265318896938221575-952');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1265318896938221575&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;After getting such a overwhelming response for my tweet, many people asked me to share my experience about how I got my first job after applying for more than 300 times.&lt;/p&gt;

&lt;p&gt;It was one of the most difficult phase which I have went through and I can only say one thing that you should not give up yet.&lt;/p&gt;

&lt;p&gt;Here is my journey of finding my first job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Indian education system&lt;/li&gt;
&lt;li&gt;My Background&lt;/li&gt;
&lt;li&gt;Struggle to find a job&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Indian education system &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;India is the second most populous country in the world with majority of young peoples which fall in the age group of 18 – 60.&lt;/p&gt;

&lt;p&gt;The total of numbers of students who become job eligible every year are more than the populations of many countries.&lt;/p&gt;

&lt;p&gt;According to a survey in the year 2016 – 17 there were 35705905 students passed out who were looking for a job.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Course&lt;/th&gt;
&lt;th&gt;Number Of Students&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Phd&lt;/td&gt;
&lt;td&gt;141037&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M.Phil&lt;/td&gt;
&lt;td&gt;43267&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Post Graduate&lt;/td&gt;
&lt;td&gt;4007570&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Under Graduate&lt;/td&gt;
&lt;td&gt;28348197&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PG Diploma&lt;/td&gt;
&lt;td&gt;213051&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Diploma&lt;/td&gt;
&lt;td&gt;2612209&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Certificate&lt;/td&gt;
&lt;td&gt;166617&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Integrated&lt;/td&gt;
&lt;td&gt;173957&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Students who study from top institutions such as IIT’s, NIT’s, BIT’s, IIM’s, IIIT’s, IIS, etc get some priority because it really difficult to get admission into these institutions and one has to crack hard entrance exams for it.&lt;/p&gt;

&lt;p&gt;Those who made it to them are some of the brilliant minds on earth.&lt;/p&gt;

&lt;p&gt;The students in India often classify themselves as they have studied from Tier1, Tier2, Tier3 colleges.&lt;/p&gt;

&lt;p&gt;Tier1 &amp;gt; Tier2 &amp;gt; Tier3. This is how order of priority works mainly for top companies and well funded startups because everyone seek value for money and they want to hire best talent for their work.&lt;/p&gt;

&lt;p&gt;Students who are from different streams from these colleges also go for IT jobs because they pay well. So some who has done BTech (4 year Engineering course) from Tier3 college face more difficulty in finding a job than their top levels.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Background &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;I live in Mumbai(Bombay) suburbs and done my schooling here only. Me and my brother both were computer geeks from early age.&lt;/p&gt;

&lt;p&gt;I was a very average student and had no future goal what so ever. After getting 50% in my 12th or high school, I was not getting admission in any college so using the in-house quota I took BSC(CS) course which is 3 year degree program in the same college.&lt;/p&gt;

&lt;p&gt;I never passed any of my semesters in a single attempt and but I think I was lucky enough of not getting failed in any year, some how I used to clear the semesters in the next attempt with god graces 🙏🏻 by just getting the passing marks.&lt;/p&gt;

&lt;p&gt;My brother (He is a BTech from Tier 3) recommended me that I should get certain certifications done because a BSC graduate has no value at all in India or I will have to pursue post graduation which is another 3 years of course which was not possible for me (Hard times).&lt;/p&gt;

&lt;p&gt;So I did a C++ and Java certification from Aptech for 12000 rupees because the only interest I had was in computers. I became good at problem solving and used to understand things quickly but the course was not so good as it had to be.&lt;/p&gt;

&lt;p&gt;It was the last year of the college in which I had to build a project in the final semester (There is no internship for a 3 years course).&lt;/p&gt;

&lt;p&gt;Out of 60 peoples in my batch there were only few who did their project by themselves while others have bought the projects. I was one of the few who built the project by their own, PHP was very hot back in 2015 and because everyone was building their projects in JAVA, I decided to use PHP to bring a change and by watching youtube tutorials I have built-ed an online Pet Food Shop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Struggle to find a job &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;t was June 2015 when my result came out and I got to know that I have failed in 2 subjects in written exam but for my project I got 90/100.&lt;/p&gt;

&lt;p&gt;There is buzz in Indian education system that if you fail for few marks then during re-checking they pass you, so I applied for re-checking of the papers and was waiting for the new result.&lt;/p&gt;

&lt;p&gt;Meanwhile because of the financial uncertainties in the family, I decided to look for a job.&lt;/p&gt;

&lt;p&gt;Some of my college friends had enrolled in higher education while others had started working in call center, because they didn’t had any knowledge of programming, they just had a degree and getting a job in call centers were not so hard.&lt;/p&gt;

&lt;p&gt;I didn’t wanted to join a call center because I knew if get into these then I will never be able to get out of it.&lt;/p&gt;

&lt;p&gt;So I decided to try my luck in the IT industry. I took reference from my brothers resume and created a one for myself and then started applying for jobs.&lt;/p&gt;

&lt;p&gt;As I had my certification done in JAVA so I decided to apply for JAVA related jobs.&lt;/p&gt;

&lt;p&gt;I created my profile on the online job portals like Monster.com, Indeed, Shine.com, etc and after few days I started receiving emails regarding the walk in interviews at different places in Mumbai.&lt;/p&gt;

&lt;p&gt;I went for my first walk-in interview and when I reached the place, I saw around 500 students has came for the same position, even after waiting for 10 hours straight I did not even got a chance for the first round of interview.&lt;/p&gt;

&lt;p&gt;Next day I went for another walk-in and same happened then again and so on.&lt;/p&gt;

&lt;p&gt;After going for around 70 – 75 walk-ins I gave up, I thought I am not going to get a job like this where for a single position so many peoples are applying.&lt;/p&gt;

&lt;p&gt;After discussing things with my brother I got to know that as JAVA is the only programming that is thought to the students in engineering that is why so many of them are showing up for walk-ins for JAVA related jobs.&lt;/p&gt;

&lt;p&gt;To bring a change, I updated my resume and started applying for PHP job because this was the only other language I knew.&lt;/p&gt;

&lt;p&gt;This worked for me and for around next 20 walk-ins to which I went for, I was at least able to give few rounds of interviews but never heard back from them.&lt;/p&gt;

&lt;p&gt;I was really getting depressed and frustrated at the same time, you know If I am doing one walk-in in a day then it was already around 100 days which was more than 3 months and I didn’t got a job.&lt;/p&gt;

&lt;p&gt;The major problem here was how the companies hire in India, these walk-ins are only done by service based companies who provide service to the clients, products based companies hire limited peoples and they do it directly from campus.&lt;/p&gt;

&lt;p&gt;As services based works for different clients, these clients want to know what they are paying for.&lt;/p&gt;

&lt;p&gt;So these companies hire students with better degree to show that the best peoples are working on their projects. That is why a BTech grad was getting priority over a BSC(cs) grad because for the same amount of money, someone with better degree will be hired.&lt;/p&gt;

&lt;p&gt;That was one of the reason I think that I was not getting any job offer because I had only 3 year degree. Maybe I was also not up to the mark for these companies, I cannot deny it either.&lt;/p&gt;

&lt;p&gt;I realized it after sometime, but I was in a no mood to give up. I thought that there would be at least one company who will willing to hire someone on their knowledge rather than degree.&lt;/p&gt;

&lt;p&gt;In between I got a call from a consultancy agency that they will help me to get a job by connecting directly to companies which are hiring but I have to pay certain amount of money to them after getting shortlisted.&lt;/p&gt;

&lt;p&gt;I did try this but later realized that it is a scam because only after the first interview they selected me and asked me to pay money as a security deposit.&lt;/p&gt;

&lt;p&gt;After failing in all these things again I decided to change my strategy and instead of going for walk-ins I decided to apply directly for the companies on their career section.&lt;/p&gt;

&lt;p&gt;I used to search for following and related terms on google.&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%2Fi%2Fiurhgijai58nqs0fwrcx.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%2Fi%2Fiurhgijai58nqs0fwrcx.png" alt="Google Search 1"&gt;&lt;/a&gt;&lt;br&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%2Fi%2Fm8lqjkh8aa44jdl894cd.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%2Fi%2Fm8lqjkh8aa44jdl894cd.png" alt="Google Search 2"&gt;&lt;/a&gt;&lt;br&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%2Fi%2F6nzl13ppupotpe827lme.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%2Fi%2F6nzl13ppupotpe827lme.png" alt="Google Search 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And open all the website then apply on their career section. I even used to go on next pages on google and apply even on those websites too.&lt;/p&gt;

&lt;p&gt;I have also searched and applied for companies in specific regions in the suburbs of the Mumbai and applied to them, I don’t exactly remember how many job applications I have given but to my bad luck I didn’t got a response from any them.&lt;/p&gt;

&lt;p&gt;It was already November mid and I had lost all my hope, but then one day I got a message on my Monster.com’s profile that a startup is interested in me.&lt;/p&gt;

&lt;p&gt;Without wasting anytime I got into the discussion with them and next day I went for the interview. It was a startup mainly into web and e-commerce development with WordPress and Magento. As I had created a Online Pet Food Shop for my final year project, the founder asked me different question on it and later told me that we could have someone like you.&lt;/p&gt;

&lt;p&gt;I was very happy, he told me to join his company on 1st of December but I will have to keep my 12th and final year mark sheet as a security deposit to him for 1 year after which he will give them back to me.&lt;/p&gt;

&lt;p&gt;It was basically a bond for 1 year to make sure I don’t leave the company quickly.&lt;/p&gt;

&lt;p&gt;I came home and shared the news with Dad and my brother. My brother said some companies do ask for these in way or other and freshers have to at least work for sometime in a organization because they invest in their training and they want to recover that value.&lt;/p&gt;

&lt;p&gt;So we agreed on it and then Dad asked what will be the salary?, Oh Damn!. I said I forgot to ask about it, I was so desperate to get the job that I did not even think about it.&lt;/p&gt;

&lt;p&gt;I called the founder next day and asked him about the salary and he said that it will be 72000 rupees/per year which was 6000 rupees / per month.&lt;/p&gt;

&lt;p&gt;My dad did not agree to it, he said no way you should work on such an amount, the basic income in India is 18000 rupees per month. You will be ruining your career.&lt;/p&gt;

&lt;p&gt;I took some time to think and later on decided to join the company. I explained my dad that see I don’t have a BTech degree and no one is willing to hire me, even if he is paying 6000 it is better than nothing. Once I start working and gather some experience it will be really helpful for me.&lt;/p&gt;

&lt;p&gt;He understood me and said it is up to you. Take your chance.&lt;/p&gt;

&lt;p&gt;I was the third employee in that company and it was self-bootstrapped by the owner so he not able to afford to the people with higher salary. I took this opportunity and worked for 6-7 days a week for the next 1.5 years.&lt;/p&gt;

&lt;p&gt;These 1.5 years was the best of my life, being a small team with small budget we use to try to build everything ourselves and use open source as much as possible. It taught me many lessons which I could have never learned anywhere else.&lt;/p&gt;

&lt;p&gt;From client handling to building and deploying website on cloud and learning new things in short span to woo the clients to get their projects and what not.&lt;/p&gt;

&lt;p&gt;The projects I did here shined in my resume which let me get better jobs in my career. From following tutorials to build a project I went on creating a website using wordpress as headless CMS and Reactjs as frontend (Solo).&lt;/p&gt;

&lt;p&gt;I was good at handling stuffs and in these 1.5 years got two promotions and while leaving that organization I was already making 18000 / per month.&lt;/p&gt;

&lt;p&gt;It has been four years since I have been working and my currently salary in 15x more than my initial salary. I now work with some of the brightest mind in India who have came from these top institutes or as we say Tier1 institutes of country.&lt;/p&gt;

&lt;p&gt;When I look back, I feel that it was my best decision to join that organization. I joined it to learn things rather than earning money. I had only one thought in my mind that if I worked hard, I would learn more here than in the next 3 years in my post graduation and it did pay off.&lt;/p&gt;

&lt;p&gt;Many people think that it is necessary to have better degree to get a good job and I am not denying it. But not everyone can have the same thing in life, still you can make your own way. It will not be same initially but with time things will get normal.&lt;/p&gt;

&lt;p&gt;I found my way after failing so many times and from this I can only suggest one thing to you, Don’t give up yet the best is waiting for you.&lt;/p&gt;

&lt;p&gt;I will end this with this quote in Hindi:-&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Zindagi inti takleef deti hain&lt;br&gt;
Dil me phir bhi umeed bani rehti hai&lt;br&gt;
Dil kehta hai ki kuch nahi hoga&lt;br&gt;
Par kuch to hoga ye umeed kehti hai&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keep Hustling 😎.&lt;/p&gt;

&lt;p&gt;If you want to learn more about how to crack interviews then you can follow me on &lt;a href="https://twitter.com/LearnersBucket" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; for some tips and tricks.&lt;/p&gt;

&lt;p&gt;Also I have switched from PHP to Frontend development later and if you want to prepare for Full stack web development with javascript then keep visiting my blog &lt;a href="https://learnersbucket.com" rel="noopener noreferrer"&gt;learnersbucket.com&lt;/a&gt; 😁😁.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
