<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rishav Pandey on Medium]]></title>
        <description><![CDATA[Stories by Rishav Pandey on Medium]]></description>
        <link>https://medium.com/@thenomadtechie?source=rss-319389bdb1cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rxVyiKwg5QjMo_vu6-pp7g.jpeg</url>
            <title>Stories by Rishav Pandey on Medium</title>
            <link>https://medium.com/@thenomadtechie?source=rss-319389bdb1cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:25:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thenomadtechie/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Asynchronous JavaScript: A Comprehensive Guide to Callbacks, Promises , async/await — Part 1]]></title>
            <link>https://thenomadtechie.medium.com/asynchronous-javascript-a-comprehensive-guide-to-callbacks-promises-async-await-part-1-f8237a330265?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8237a330265</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 11:43:07 GMT</pubDate>
            <atom:updated>2024-01-07T11:43:07.349Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1: A Guide to Callbacks, Promises, and Async/Await in Asynchronous JavaScript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3E5Je47qecPECGR5w4VOg.png" /></figure><h3>Introduction</h3><p>When I began my programming journey with JavaScript, one of the first complexities I encountered was its asynchronous behavior. Concepts like callbacks, promises, and async-await in JavaScript were daunting at first, but as I delved deeper, they became fascinating pieces of the asynchronous puzzle.</p><p>In this two-part series, we will start by unraveling the mysteries of asynchronous JavaScript, from the foundational use of callbacks to the notorious challenges of callback hell. We’ll then explore how promises revolutionized asynchronous operations and how the introduction of async-await has made JavaScript a powerhouse in the realm of asynchronous programming. Let’s start this journey to understand and master these crucial aspects of JavaScript.</p><h3>A Market Adventure: A Metaphor for Synchronous and Asynchronous Processes</h3><p>Yesterday, two friends, Ram and Shyam, went to the market to complete a few tasks independently. The way they completed these tasks will teach us about an important topic in JavaScript: asynchronous behavior.</p><h3>Ram’s approach</h3><p>When Ram went to the shopkeeper, he learned that Task 1 would take a few minutes. He waited for it to finish before moving on to Task 2, and then did the same with Task 3. This resulted in Ram taking a lot of time to complete all the tasks, as they were done in a synchronous manner.</p><h3>Shyam’s approach</h3><p>Unlike Ram, when Shyam discovered that Task 1 would take some extra time, he went to another stall and executed Task 2. By then, Task 1 was ready for execution, which he completed before moving on to Task 3. This way, he was able to finish all the tasks more quickly using an asynchronous approach.</p><h3>Diving into Asynchronous Javascript</h3><p>Now that we understood what is asynchronous behaviour, let’s see this in action -</p><pre>function doSomeAsyncTask() {<br>  setTimeout(() =&gt; {<br>    console.log(&#39;Task is now complete after 10 seconds&#39;);<br>  }, 5000)<br>}<br><br>console.log(&#39;Task is going to start&#39;);<br>doSomeAsyncTask();<br>console.log(&#39;Task has now ended.&#39;);<br><br><br>// Output:<br>&#39;Task is going to start&#39;<br>&#39;Task has now ended.&#39;<br>&#39;Task is now complete after 10 seconds&#39; // printed out after 5seconds.</pre><p>This is how asynchronous behavior works in JavaScript. When doSomeAsyncTask() takes extra time to execute, it is sent to a queue, and the next line is executed, and when this asynchronous task is completed, it executed. In contrast, if doSomeAsyncTask() were executed synchronously, the next line would have to wait(here 10 seconds) until doSomeAsyncTask() finished executing. This approach is not ideal for creating real-world interactive applications, as they often have several tasks that require time to execute. Blocking the thread would result in the application freezing, which is not desirable.</p><h3>How to handle asynchronous code in Javascript</h3><p>Let’s imagine we clicked a button to fetch data from an API. Since the API call is asynchronous, the next synchronous line of code executes immediately without waiting for the API call to complete. Once the API call is successful, we need to perform a dependent task, such as rendering the received data to the UI or performing some computation on the newly fetched data.</p><p>There are three ways to handle asynchronous tasks in JavaScript, and we’ll dive deep into each of them:</p><h3>Callbacks in Javascript</h3><p>Callbacks are a kind of function we send as a argument to another function which when completes it’s execution executes that callback immediately. In this way, we ensure that once our desired task is completed asynchronously we can perform it’s dependent task.</p><p>Let’s take an example where our API call returns a data in 2 seconds, and we want to console it.</p><pre>function fetchingApiDataAsync(callback) {<br>  const data = [1, 2, 3, 4];<br>  setTimeout(() =&gt; {<br>    callback(data);<br>  }, 2000)<br>}<br><br>function printApiDataWhenFetched(data) {<br>  console.log(data);<br>}<br><br>console.log(&quot;Application started&quot;);<br>fetchingApiDataAsync(printApiDataWhenFetched)<br><br>// Output:<br>&#39;Application started&#39;<br>[ 1, 2, 3, 4 ] // after 2 seconds</pre><p>Here we sent our printApiDataWhenFetched function as a callback inside fetchingApiDataAsync so that as soon as data is fetched asynchronously, we can call our dependent task which is not synchronous in nature.</p><p>This is how we handle asynchronous tasks in JS.</p><p>Now, suppose there are multiple cases with us, like API can either successfully return the data or fail with some error, all these can be handled using callback.</p><pre>function fetchDataFromServer(callback) {<br>  // Simulating a delay like an API call<br>  setTimeout(() =&gt; {<br>    // Simulating a response<br>    const response = {<br>      code: 200, // Change this to a non-200 code to simulate an error<br>      data: &quot;Fetched Data&quot;,<br>      error: &quot;Error occurred&quot;<br>    };<br>    callback(response);<br>  }, 2000);<br> }<br><br>function fetchingApiDataAsync(success, error) {<br>  fetchDataFromServer((res) =&gt; {<br>    if (res.code === 200) {<br>      // API has successfully returned the data<br>      success(res.data);<br>    } else {<br>      // API returned an error<br>      error(res.error);<br>    }<br>  });<br>}<br><br>function printData(data) {<br>  console.log(&quot;Data:&quot;, data);<br>}<br><br>function printError(error) {<br>  console.log(&quot;Error:&quot;, error);<br>}<br><br>console.log(&quot;Application started&quot;);<br>fetchingApiDataAsync(printData, printError);<br><br><br>// Output: <br>&#39;Application started&#39;<br>&#39;Data:&#39; &#39;Fetched Data&#39; // after 2 seconds</pre><p>In the code above, we can see how callbacks are used to handle both success and error scenarios.</p><p>However, imagine if there is another task 2 dependent on a callback, followed by task 3 dependent on task 2, and so on. This situation, where consecutive callbacks depend on previous ones, creating a chain of callbacks, is commonly known as <strong>callback hell</strong>. In this case, callbacks are nested within a parent callback and can extend to n-levels deep.</p><h3>Callback hell</h3><pre>// A callback is a function passed as an argument to another function. This technique allows a function to call another function when a specific task is completed.<br><br>function exampleCallback(message, callback) {<br>  console.log(message);<br>  callback();<br>}<br><br>exampleCallback(&quot;Hello, World!&quot;, function() {<br>  console.log(&quot;This is a callback function being executed.&quot;);<br>});<br><br>// Callback Hell refers to a situation where callbacks are nested within other callbacks, making the code difficult to read and maintain.<br>function firstTask(callback) {<br>  setTimeout(function() {<br>    console.log(&quot;First task completed.&quot;);<br>    callback();<br>  }, 1000);<br>}<br><br>function secondTask(callback) {<br>  setTimeout(function() {<br>    console.log(&quot;Second task completed.&quot;);<br>    callback();<br>  }, 1000);<br>}<br><br>function thirdTask(callback) {<br>  setTimeout(function() {<br>    console.log(&quot;Third task completed.&quot;);<br>    callback();<br>  }, 1000);<br>}<br><br>firstTask(function() {<br>  secondTask(function() {<br>    thirdTask(function() {<br>      console.log(&quot;All tasks completed. This is an example of callback hell.&quot;);<br>    });<br>  });<br>});</pre><p>In the code snippet above, we can see how challenging it can become when we have multiple tasks depending on one another. This nesting can be difficult to maintain and may lead to bugs if not handled properly.</p><p>Before Promises were introduced in ES6, callbacks were our go-to solution for handling all asynchronous tasks in Javascript.</p><p>In the next part of this blog, we’ll delve into <strong>Promises</strong> and <strong>async/await</strong>.</p><h3>Summary</h3><blockquote>In this article, we explored asynchronous behavior in JavaScript. Through the story of Ram and Shyam, we gained an understanding of this concept, as well as the principles of callbacks and the challenges posed by callback hell.</blockquote><blockquote>We began by grasping the concept and then delved deeper into asynchronous behavior and how it is managed using callbacks in JavaScript, which in turn helps us create functional applications in this asynchronous world.</blockquote><blockquote>In the upcoming second part of the article, we’ll examine the remaining two methods of handling asynchronous behavior, i.e using <strong>Promises</strong> and <strong>async/await</strong>.</blockquote><p>🌟 Enjoyed the read? I’d love to hear your thoughts! Share your takeaways and let’s start a conversation. Your insights make this journey richer for all of us.</p><p>👏 If you found this helpful, a clap or two would mean the world — it helps more folks find these guides!</p><p>🔜 What’s next? I’m already brewing the next topic, packed with more insights and a-ha moments. Stay tuned!</p><p>🙏 A big thank you for spending time with my words. Your support fuels my passion for sharing knowledge.</p><p>👋 Until next time, keep coding and keep exploring!</p><p>💬 Let’s stay connected! Follow me on Medium for more adventures in coding: <a href="https://thenomadtechie.medium.com/"><strong>Rishav Pandey: Medium</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8237a330265" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Javascript Hoisting: A Starter’s Guidebook]]></title>
            <link>https://thenomadtechie.medium.com/understanding-javascript-hoisting-a-starters-guidebook-aef91a6c6d2a?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef91a6c6d2a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[hoisting]]></category>
            <category><![CDATA[hoisting-in-javascript]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 12:24:22 GMT</pubDate>
            <atom:updated>2023-12-08T12:24:22.910Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xo6pf41sPpDaonTH" /><figcaption>Photo by <a href="https://unsplash.com/@acton_crawford?utm_source=medium&amp;utm_medium=referral">Acton Crawford</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Hoisting is one of the most commonly asked topics when starting with our programming journey in the world of Javascript. Understanding Hoisting is very important before we deep dive into variables, and functions which are the basic yet powerful building blocks in any programming language, especially in Functional programming.</p><blockquote><em>Hoisting is a concept/behavior in JavaScript, where declarations of variables, functions, or classes are moved to the top within their scope when the code is interpreted.</em></blockquote><p>Let’s take an example -</p><pre>function hey() {<br>  console.log(&quot;Hey there!&quot;)<br>}<br><br>hey() // Output: Hey there!</pre><p>We received the desired string in the console, but what if we attempt to call the function before its declaration? Let’s witness the magic:</p><pre>hey() // Output: Hey there!<br><br>function hey() {<br>  console.log(&quot;Hey there!&quot;)<br>}</pre><p>We received the same string, and voilà, there was no error. We can successfully call the function before its declaration.</p><p>This is the magic of Hoisting, which we just witnessed. It is a feature not commonly found in other popular programming languages, except for Python.</p><h3>Hoisting with variables in Javascript</h3><p>Let’s first understand how JavaScript performs this method of moving all the declarations to the top.</p><p>Suppose we have the following code -</p><pre>console.log(a)<br><br>var a = &quot;hello&quot;;</pre><p>We’re now assuming that code will execute as per the sequence of lines, but while interpreting this is how due to hoisting our above code will be converted -</p><pre>var a;<br><br>console.log(a)<br>a = &quot;hello&quot;;</pre><p>It’s crucial to recognize that only lines with declarations are moved to the top of their scope, while all other lines stay in place.</p><p>When the first line executes, a new variable a is declared with the default value of undefined. That&#39;s why we see undefined in the second line of the console. The actual value is assigned to the variable when the line containing the original declaration is executed.</p><h3>var vs let in Hoisting</h3><p>We already know that there are three ways to declare any variables inside Javascript, but when it comes to hoisting it behaves differently with var and let/const.</p><p>Let’s check the following code -</p><pre>// Hoisting with var<br>console.log(a) // Output: undefined<br>var a = &quot;hello&quot;;<br>console.log(a); // Output: &quot;hello&quot;<br><br>// ------------------------------------------<br><br>// Hoisting with let<br>console.log(b) // ReferenceError: b is not defined<br>let b = &quot;World&quot;;</pre><p>We can see that with var, the variable is automatically hoisted to the top with a default value of undefined. However, in this case of let, we receive a reference error stating that the variable is not defined.</p><p><strong>Now, there is a misconception that hoisting doesn’t occur with let/const. But this is not true.</strong></p><blockquote><em>While working with </em><em>var, variables are hoisted to the top with default value of </em><em>undefined, but with </em><em>let/const variables are also hoisted to the top but without any default value and thus it goes to TDZ (Temporal Dead Zone)</em></blockquote><p>Let’s visualize:</p><pre>console.log(a) // Output: undefined<br>var a;<br>a = &quot;hello&quot;;<br><br><br>console.log(b) // ReferenceError: Cannot access &#39;b&#39; before initialization<br>let b;<br>b = &quot;World&quot;;<br><br><br>console.log(c) // ReferenceError: c is not defined</pre><p>Here, we observed that when we attempted to access b it before its declaration, we received a reference error stating that it could not be accessed before initialization.</p><p>However, when we tried to access another variable, c, we encountered an error indicating that the variable is not defined. This is because the interpreter could not find any such variables declared later in the code.</p><p>It’s worth noting that in some cases, certain interpreters may return the same “variable not defined” error even though the variable was hoisted with let.</p><h3>Temporal Dead Zone (TDZ)</h3><p>TDZ of any variable is a zone that starts from the top of the scope where the declaration of any variables happens and ends till the assignment of any value is done for that variable.</p><p>This was the reason why we got the reference error while accessing the variable before its assignment because it was present in TDZ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hL8uCxGY3sPYbsE8.png" /><figcaption>explaining temporal dead zone</figcaption></figure><h3>Hoisting with functions in Javascript</h3><p>Similar to variables, hoisting also occurs in the function declaration.</p><pre>foo() // Output: &quot;foo&quot;<br><br>function foo() {<br>  console.log(&quot;foo&quot;)<br>}</pre><p>We can see that with function declarations, we were able to call the function before declaring it.</p><p>This time, unlike variables, we got the correct output, as the declaration was hoisted to the top.</p><pre>foo() // TypeError: foo is not a function<br><br>var foo = function () {<br>  console.log(&quot;foo&quot;)<br>}</pre><blockquote><em>However, in the case of function expressions, this is not the case. It acts just like a normal variable assignment where a function is assigned to a variable, so we get </em><em>undefined and, technically, an error when calling functions if called before their declarations.</em></blockquote><p>If we try to check the type of foo -</p><pre>console.log(typeof foo) // Output: undefined<br><br>var foo = function () {<br>  console.log(&quot;foo&quot;)<br>}</pre><p>We can observe that with function expressions, hoisting follows the variable principle, resulting in undefined being returned because the function was in the Temporal Dead Zone (TDZ).</p><h3>Hoisting in strict mode in javascript</h3><p>Till now we have already figured out that despite hoisting being the default behavior of javascript, if not handled properly can result in bugs and faulty code. That’s why we have always heard that we should write the code in strict mode.</p><p>Let’s figure out, how hoisting plays its game in strict mode -</p><pre>&#39;use strict&#39;;<br><br>console.log(a) // //ReferenceError: a is not defined<br>var a = &quot;hello&quot;;</pre><p>When writing the code in <strong>strict mode, the </strong>Javascript engine prevents the usage of any variable/function before its declaration, and thus technically hoisting is prevented in strict mode.</p><h3>Summary</h3><p>This article discusses the concept of Hoisting in JavaScript, which is the default behavior of moving all declarations to the top of their respective scopes during the code interpretation. It begins with the basic understanding of hoisting, followed by its application with variables and functions. It also explains the difference in hoisting behavior with var, let, and const declarations. The concept of Temporal Dead Zone (TDZ) is introduced, explaining why we get a reference error while accessing a variable before its assignment. The article further explores hoisting in function declarations and expressions, and finally, discusses how hoisting is prevented in strict mode.</p><p>🌟 Enjoyed the read? I’d love to hear your thoughts! Share your takeaways and let’s start a conversation. Your insights make this journey richer for all of us.</p><p>👏 If you found this helpful, a clap or two would mean the world — it helps more folks find these guides!</p><p>🔜 What’s next? I’m already brewing the next topic, packed with more insights and a-ha moments. Stay tuned!</p><p>🙏 A big thank you for spending time with my words. Your support fuels my passion for sharing knowledge.</p><p>👋 Until next time, keep coding and keep exploring!</p><p>💬 Let’s stay connected! Follow me on Medium for more adventures in coding: <a href="https://thenomadtechie.medium.com/">https://thenomadtechie.medium.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef91a6c6d2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering JavaScript Event Handling Techniques: Bubbling, Capturing, Delegation, and Propagation]]></title>
            <link>https://thenomadtechie.medium.com/mastering-javascript-event-handling-techniques-bubbling-capturing-delegation-and-propagation-0cdbe56f0b39?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/0cdbe56f0b39</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[dom]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Sat, 25 Nov 2023 11:51:50 GMT</pubDate>
            <atom:updated>2023-11-25T12:17:54.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iNrEV2n60GHyJWD2FTa-rw.png" /></figure><h3>Introduction</h3><p><strong>Events</strong> in JavaScript are essential and fundamental for creating interactive web pages. They can be considered the driving force behind a browser, enabling it to perform actions on behalf of the user. When you find a button and want to click it, you hover over it and press the mouse button. This action triggers a response within the browser, which identifies the type of event (in this case, a click) and executes a corresponding function, often in the form of a callback.</p><p>Let’s see the code below -</p><pre>&lt;button onclick=&quot;clickMe()&quot;&gt;Click Me&lt;/button&gt;<br><br>function clickMe() {<br>  alert(&quot;I&#39;m button, and I was clicked.&quot;);<br>}jj</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*snUhGDTbl_5JJvVH.png" /></figure><p>We can see that the browser alerted our text when clicked.</p><p>Let’s dive deep into different concepts revolving around event handling in DOM.</p><h3>Event Bubbling</h3><p><strong>Event bubbling</strong> is what an event does, when an event is triggered on any DOM element, it travels up to its parent element and continues this process until it reaches the topmost HTML element and triggers events attached to all it’s parent elements. This propagation to all parent elements allows events attached to a child element to automatically become available to all parent elements present in the DOM.</p><p>This is the HTML code we have —</p><pre>&lt;body&gt;<br>  &lt;div id=&quot;div&quot;&gt;<br>    &lt;p id=&quot;p&quot;&gt;<br>      &lt;span id=&quot;span&quot;&gt;<br>        &lt;button id=&quot;btn&quot;&gt;<br>          Click Me<br>        &lt;/button&gt;<br>      &lt;/span&gt;<br>    &lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;</pre><p>When the DOM tree is created, we get something like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LTgf4iH-Uw2MpV65.png" /></figure><p>As soon as we click on button, it fires the event associated with it and then triggers the event attached to its parent element span which then triggers p that again triggers an event on div and this goes top to the HTML.</p><p>Here we need to make sure, that <strong>event bubbling</strong> goes from bottom to top only. It’ll never trigger events of children element when fired from any parent.</p><pre>function clickMe(target) {<br>  console.log(`${target} is clicked`);<br>}<br><br>document.getElementById(&quot;div&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;div&quot;);<br>});<br><br>document.getElementById(&quot;p&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;paragraph&quot;);<br>});<br>document.getElementById(&quot;span&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;span&quot;);<br>});<br>document.getElementById(&quot;btn&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;button&quot;);<br>});</pre><p>Here we get the following scenarios -</p><ol><li>If we click on the div, we get -</li></ol><pre>&quot;div is clicked&quot;</pre><p>2. If we click on the p, we get -</p><pre>&quot;paragraph is clicked&quot;<br>&quot;div is clicked&quot;</pre><p>3. If we click on the span, we get -</p><pre>&quot;span is clicked&quot;<br>&quot;paragraph is clicked&quot;<br>&quot;div is clicked&quot;</pre><p>4. If we click on the button, we get -</p><pre>&quot;button is clicked&quot;<br>&quot;span is clicked&quot;<br>&quot;paragraph is clicked&quot;<br>&quot;div is clicked&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g2v-iRGQLPqJcv-U.png" /></figure><p>We can visualize, how the event was propagated to the top and all the subsequent events present in parent elements were fired too.</p><h3>Event Capturing</h3><p><strong>Event Capturing</strong> is a method of applying event delegation to events that don’t bubble.</p><p>There are several events, such as blur, focus, load, and unload, that does not bubble and cannot be delegated when necessary. For these types of events, we use event capturing to simulate the bubbling of an event.</p><p>This is similar to event bubbling, with one key difference: in this case, we navigate from top to bottom, while in event bubbling, we go from bottom to top. The commonality is that events are never fired on any child elements.</p><p>If we have a structure like this — div &gt; p &gt; button - and we click on the button, the sequence of events fired will be the same as the tree, i.e., event on div, then on p, and finally on the button.</p><p>To make this happen, we need to pass the third argument as true while adding an event like this: document.getElementById(&quot;btn&quot;).addEventListener(&quot;click&quot;, () =&gt; { clickMe(&quot;button&quot;); }, true);</p><p>If we modify our previous code, we get this response when the button is clicked:</p><pre>&quot;div is clicked&quot;<br>&quot;paragraph is clicked&quot;<br>&quot;span is clicked&quot;<br>&quot;button is clicked&quot;</pre><h3>Event Delegation</h3><p><strong>Event Delegation</strong> is a pattern that relies on Event Bubbling. It is an event-handling approach where we manage the event on the parent element rather than the location where the event was initially triggered.</p><p>Let’s consider a use case where we have multiple buttons inside any element. Ideally, we would need to add a separate event listener to each button, which is quite common. However, what if we have dozens of buttons, and all of them need to trigger the same callback? In this scenario, we can employ the event delegation pattern to achieve our desired result by binding a single event to just the parent element.</p><pre>&lt;body&gt;<br>  &lt;div id=&quot;div&quot;&gt;<br>    &lt;p id=&quot;p&quot;&gt;<br>      &lt;button id=&quot;btn1&quot;&gt;<br>        Button 1<br>      &lt;/button&gt;<br>      &lt;button id=&quot;btn2&quot;&gt;<br>        Button 2<br>      &lt;/button&gt;<br>    &lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;</pre><p>We can add a single event to the div element, and delegate the events to the buttons without adding multiple events separately -</p><pre>document.getElementById(&quot;div&quot;).addEventListener(&quot;click&quot;, (e) =&gt; {<br>  if (e.target.tagName === &quot;BUTTON&quot;) {<br>    console.log(e.target.innerText);<br>  }<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*SiwAt6DkdxCdftCM.gif" /></figure><h3>Benefits of Event Delegation</h3><p>There are several benefits to using this pattern when writing elegant code, including:</p><ol><li>It helps in writing less code by attaching fewer events inside the DOM.</li><li>If multiple DOM elements share similar logic inside event callbacks, they can be handled and maintained in the same place.</li><li>Using fewer event listeners helps in minimizing the risk of memory leaks and helps in overall application optimization.</li><li>If we attach a large number of events inside the DOM on a single page, it results in the unresponsiveness of the page and slows down the whole page. Event delegation helps a lot in these kinds of scenarios.</li></ol><h3>Event Propagation</h3><p><strong>Event Propagation</strong> is a concept of DOM, on which event bubbling occurs within the browser. It is a bi-directional method on which the lifecycle of any event relies. Every time any event is fired, event propagation occurs internally to complete the execution.</p><p>This is divided into a total of three phases -</p><ol><li><strong>Capturing Phase</strong> — The first phase begins when an event is triggered. In this phase, the event travels from the window to the specific element where the event was initiated, notifying every element in its path.</li><li><strong>Targeting Phase</strong> — This phase only occurs on the target element where the event was triggered. The event is registered here.</li><li><strong>Bubbling Phase</strong> — This is the last phase which starts from the element where the event was actually fired and propagates to the top till Window. Now event starts triggering from the target element, and all other events present to other parent elements are also triggered.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KdKQNsY2pSMKHbub.png" /></figure><h3>stopPropagation()</h3><p>Now, what if multiple events are attached to both the parent and child elements?</p><p>In this case, If we try to trigger the element on any of the child elements then other events attached to the parent element will also be triggered which can lead to unexpected behavior if not handled properly.</p><p>To fix this issue, we have an in-built method stopPropagation() which prevents to bubble of the event to the top and only the event that is associated with the element firing triggering the event is executed.</p><pre>// HTML - <br>&lt;body&gt;<br>  &lt;div id=&quot;div&quot;&gt;<br>    &lt;button id=&quot;btn&quot;&gt;<br>      Button<br>    &lt;/button&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br><br>// JS - <br>function clickMe(target) {<br>  console.log(`${target} is clicked`);<br>}<br>document.getElementById(&quot;div&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;div&quot;);<br>});<br>document.getElementById(&quot;btn&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  clickMe(&quot;button&quot;);<br>});</pre><p>If we click on a button, we get the following output -</p><pre>&quot;button is clicked&quot;<br>&quot;div is clicked&quot;</pre><p>Let’s modify our JS code by adding stopPropagation() -</p><pre>document.getElementById(&quot;btn&quot;).addEventListener(&quot;click&quot;, (e) =&gt; {<br>  e.stopPropagation();<br>  clickMe(&quot;button&quot;);<br>});</pre><p>This will be output now -</p><pre>&quot;button is clicked&quot;</pre><p>This is how we terminated the default bubbling of the event by using stopPropagation().</p><h3>Summary</h3><blockquote><em>In this article, we discuss the fundamentals of event handling in JavaScript, focusing on concepts like event bubbling, event capturing, event delegation, and event propagation. We also explore the benefits of event delegation and the use of stopPropagation() to prevent unexpected behavior in our applications.</em></blockquote><p>🌟 Enjoyed the read? I’d love to hear your thoughts! Share your takeaways and let’s start a conversation. Your insights make this journey richer for all of us.</p><p>👏 If you found this helpful, a clap or two would mean the world — it helps more folks find these guides!</p><p>🔜 What’s next? I’m already brewing the next topic, packed with more insights and a-ha moments. Stay tuned!</p><p>🙏 A big thank you for spending time with my words. Your support fuels my passion for sharing knowledge.</p><p>👋 Until next time, keep coding and keep exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0cdbe56f0b39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Call, Apply, and Bind in JavaScript: A Guide]]></title>
            <link>https://thenomadtechie.medium.com/mastering-call-apply-and-bind-in-javascript-a-guide-55513f7b2906?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/55513f7b2906</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[oop]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 13:49:01 GMT</pubDate>
            <atom:updated>2023-11-24T13:49:01.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlAaqP6vNZs-itgV1OmJDQ.png" /></figure><p>In our previous blog post, we discussed the unique nature of ‘this’ in JavaScript and unveiled its magical power, as well as how it operates differently from other programming languages. If you’re interested in learning more about ‘this’ in the simplest way possible, check out our blog post: “<a href="https://medium.com/@thenomadtechie/decoding-the-this-keyword-in-javascript-a-simplified-guide-a6544fb5353a">Decoding ‘this’ Keyword</a>”</p><p>During our exploration of ‘this,’ we discovered three built-in methods in JavaScript: <strong>.call()</strong>, <strong>.apply()</strong>, and <strong>.bind()</strong>.</p><p>In JavaScript, <strong>.call()</strong>, <strong>.apply()</strong>, and <strong>.bind()</strong> are methods used to alter the reference of ‘this’ within a function and subsequently invoke it. This approach enables the explicit binding of ‘this’ for any given function.</p><h3>Let’s begin -</h3><p>Let’s check out the code -</p><pre>const student1 = {<br>  firstName: &quot;Rishav&quot;,<br>  lastName: &quot;Pandey&quot;,<br>  getName() {<br>    console.log(`${this.firstName} ${this.lastName}`)<br>  }<br>}<br><br>student1.getName() // Output: &#39;Rishav Pandey&#39;</pre><p>Here, we have a function called getName() where this points to its parent object, allowing us to retrieve the name. However, what if we have another student object with different values and we want to obtain the name?</p><p>We would end up creating another object, similar to this:</p><pre>const student2 = {<br>  firstName: &quot;John&quot;,<br>  lastName: &quot;Doe&quot;,<br>  getName() {<br>    console.log(`${this.firstName} ${this.lastName}`)<br>  }<br>}<br><br>student2.getName() // Output: &#39;John Doe&#39;</pre><p>We can see that we’ve ended up writing redundant code. So, what’s the solution?</p><p>Here comes our saviour — <strong>call()</strong>, <strong>apply()</strong>, and <strong>bind()</strong></p><h3>call() and apply()</h3><p>call and apply are in-built methods that are automatically created whenever we create a regular function. We need to note that in the case of the arrow function, we don’t have this leverage.</p><p>Whenever we want to change the context of this, we can call/invoke that function with these two above methods and we’re done.</p><pre>function getName() {<br>  console.log(`${this.firstName} ${this.lastName}`)<br>}<br><br>const student1 = {<br>  firstName: &quot;Rishav&quot;,<br>  lastName: &quot;Pandey&quot;,<br>}<br>const student2 = {<br>  firstName: &quot;Ram&quot;,<br>  lastName: &quot;Krishna&quot;,<br>}<br>getName.call(student1) // Output: &#39;Rishav Pandey&#39;<br>getName.call(student2) // Output: &#39;Ram Krishna&#39;</pre><p>Now without creating a getName() multiple times we can access the properties of any object just by passing it as a reference of this for a function every time it’s invoked.</p><h3>Difference between call() and apply()</h3><p>In terms of functionality and usage, both the <strong>call()</strong> and <strong>apply()</strong> behave in the same manner. It only differs on how the arguments are passed in terms of syntax if present.</p><p><strong>call -</strong></p><ul><li>Arguments are passed as a comma-separated value</li></ul><p><strong>apply-</strong></p><ul><li>Arguments are passed as a single array with all arguments within it.</li></ul><pre>function getAnimal(food1, food2, food3) {<br>  console.log(`${this.name} is ${this.mealPreference}, and likes to eat ${food1}, ${food2}, and ${food3}`)<br>}<br><br>const animal1 = {<br>  name: &quot;Lion&quot;,<br>  mealPreference: &quot;carnivorous&quot;<br>}<br>const animal2 = {<br>  name: &quot;Deer&quot;,<br>  mealPreference: &quot;herbivorous&quot;<br>}<br>getAnimal.call(animal1, &quot;cheetahs&quot;, &quot;crocodiles&quot;, &quot;giraffes&quot;) // Output: &#39;Lion is carnivorous, and likes to eat cheetahs, crocodiles, and giraffes&#39;<br>getAnimal.apply(animal2, [&quot;Grasses&quot;, &quot;sedges&quot;, &quot;leaves&quot;]) // Output: &#39;Deer is herbivorous, and likes to eat Grasses, sedges, and leaves&#39;</pre><h3>bind() in Javascript</h3><p><strong>bind</strong> is also used to change the reference of this inside any function, but it’s completely different in terms of functionality and usage when compared to <strong>call/apply</strong>.</p><p><strong>bind</strong> is used to create a new function expression instead of invoking the function immediately which we usually see in <strong>call/apply.</strong></p><pre>function getName() {<br>  console.log(`${this.firstName} ${this.lastName}`)<br>}<br><br>const student1 = {<br>  firstName: &quot;Rishav&quot;,<br>  lastName: &quot;Pandey&quot;,<br>}<br>const myName = getName.bind(student1)<br>myName()</pre><p>In the code above, we can see that bind creates a new copy of the function to be invoked later, which is not the case with call/apply, where the function is immediately invoked.</p><h3>Summary</h3><p>In this article, we explored how to change the reference of ‘this’ using call, apply, and bind in JavaScript. Let’s briefly review each of them:</p><ol><li>call/apply — These two built-in methods are used to change the reference of ‘this’ within a function and invoke that function. The only difference between call and apply lies in how arguments are passed: call accepts parameters as comma-separated-values, while apply takes arguments in the form of an array.</li><li>bind — This method differs when it comes to invoking a function. With bind, we obtain a new copy of the function that can be invoked later.</li><li>All three methods are employed to change the reference of ‘this’ within the execution context of any function when it is invoked.</li></ol><p>🌟 Enjoyed the read? I’d love to hear your thoughts! Share your takeaways and let’s start a conversation. Your insights make this journey richer for all of us.</p><p>👏 If you found this helpful, a clap or two would mean the world — it helps more folks find these guides!</p><p>🔜 What’s next? I’m already brewing the next topic, packed with more insights and a-ha moments. Stay tuned!</p><p>🙏 A big thank you for spending time with my words. Your support fuels my passion for sharing knowledge.</p><p>👋 Until next time, keep coding and keep exploring!</p><p>💬 Let’s stay connected! Follow me on Medium for more adventures in coding: <a href="https://thenomadtechie.medium.com/">https://thenomadtechie.medium.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55513f7b2906" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding var, let, and const in JavaScript: A Simple Guide]]></title>
            <link>https://thenomadtechie.medium.com/understanding-var-let-and-const-in-javascript-a-simple-guide-ba3c025a9e88?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba3c025a9e88</guid>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Wed, 15 Nov 2023 12:09:41 GMT</pubDate>
            <atom:updated>2023-11-15T12:09:41.763Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WZFoLUOOUPz5XAEJ" /><figcaption>Photo by <a href="https://unsplash.com/@piggybank?utm_source=medium&amp;utm_medium=referral">PiggyBank</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hey there fellow code enthusiasts! 🚀 In our coding adventure, one golden rule always shines through: nail the basics!</p><p>Whether it’s picking up a new programming language or any other skill in life, a solid grasp of the fundamentals is our secret weapon for long-term success. 🛠️ So, in this blog, we’re going back to the basics of JavaScript — but trust me, it’s anything but basic! We’re diving deep into the three musketeers of variable declaration: <strong>var</strong>, <strong>let</strong>, and <strong>const</strong>. 🧐</p><p>You know, I’ve been on the hot seat for countless interviews, even for senior frontend roles, I’ve seen the questions about <strong>var</strong>, <strong>let</strong>, and <strong>const</strong> pop up more often than you&#39;d think! 🤔</p><p>So, today, we’re going to unravel the mysteries behind these three and get you prepped and confident for your next coding interview or project. Let’s get started! 💻</p><h3>What is this var, let, and const in Javascript first of all?</h3><p>So, like in any other programming language, we need variables to store some data and in Javascript, we have three different ways to do so.</p><p>Now, you’ll say why three different ways for a single task?</p><p>Hold on, we’ll cover everything!</p><p>🕒 <strong>Before ES6:</strong> We just had <strong>var</strong>. But as JavaScript evolved, <strong>let</strong> and <strong>const</strong> came along to solve <strong>var</strong>&#39;s issues.</p><h3>💬 Breaking It Down</h3><p>Let’s note one thing first, in the whole blog we’ll be diving deep into var and let for simplicity, as const and let are almost similar with only a single difference which we will cover at last.</p><p><strong>var:</strong> The old-school way. It’s flexible but can lead to bugs.</p><ul><li>Function-level scope</li><li>Re-declarable</li></ul><p><strong>let</strong> — The new approach. More controlled and less error-prone.</p><ul><li>Block-level scope</li><li>Not re-declarable</li></ul><h3>Declaration of variables via var and let</h3><p>Let’s check the code below —</p><pre>var a = &quot;Hello&quot;<br>var a = &quot;world&quot;<br>console.log(a)// Output: &quot;world&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*4klt5z8fsF8eoAoVfxMmSQ.png" /><figcaption>The variable’s value is updated.</figcaption></figure><pre>let a = &quot;Hello&quot;<br>let a = &quot;world&quot;<br>console.log(a) // SyntaxError: Identifier &#39;a&#39; has already been declared.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*VbNLNX36_13-TWSiNhg7JA.png" /><figcaption>Error: variable already been declared</figcaption></figure><p>We can clearly see here that while re-declaring a new variable with the same name we got the error with the let keyword.</p><p>This flexibility of re-declaring a variable with the same name always made the program prone to bugs and thus it was later fixed with a let keyword.</p><h3>🔍 Scope and Accessibility</h3><p>When we hear about the scope of any variable, it means the boundary in which any variable is accessible once defined. Like If you define any variable inside any function it can’t be accessed outside it.</p><p>Let’s check the code below —</p><pre>if(true) {<br>  var a = 10;<br>}<br><br>console.log(a) // Output: 10</pre><p>We can access our variable a outside the if statement, as it was scoped to the main function and still accessible in the scope of the function, now check another code -</p><pre>if(true) {<br>  let a = 10;<br>}<br><br>console.log(a)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*pMCiL3xS-jbo1DW7Ts5GgA.png" /><figcaption>Error: Accessing variable outside it’s scope</figcaption></figure><p>When we try to do the same, we get the ReferenceError of our variable not defined.</p><p>Now let’s first understand Block-scoping vs Function-scoping.</p><p><strong>Block Scope</strong> — Whenever a variable is defined with let/const its scope is limited to the block which is usually defined by opening and closing curly brackets <strong>{}.</strong> This is called Block-level scoping, where variables are only available under the curly braces.</p><p>Whereas in the case of variables defined through var, it doesn’t care about any brackets and extends its scope to the function where it’s defined.</p><p>| <em>That means the variable exists </em><strong><em>everywhere in the function</em></strong><em> if defined via </em><em>var keyword despite of blocks present there but in case of variables defined via </em><em>let they’re restricted to the block where they’re defined.</em></p><h3>⬆️ Hoisting</h3><p>Now here comes something that every interviewer wants to hear from you when listening about the difference between var, let, and const.</p><p><strong>Hoisting</strong> is the concept of javascript, in which whenever we declare any variable or function its definition is hoisted on the top when the program starts its execution.</p><p>Variables declared with the var keywords are subject to hoisting. If we declare a variable (but do not initialize it) at the end of the function, the JavaScript runtime will move it to the top of its scope and, therefore, there will be no complaint by the runtime if we use that variable before being declared.</p><p>But in the case of variables declared via let, the case is different. It’s not hoisting. This means you cannot use a variable unless it is declared and initialized.</p><h3>🆚 let vs const in Javascript.</h3><p>As we read earlier variable declaration by both the let and cons are the same with only a single difference that once a variable is declared via const it can’t be re-defined or in other words the value is always constant and it can’t be changed later on.</p><p>Let’s understand via code —</p><pre>let a = 10;<br>console.log(a) // Output: 10<br>a = 20;<br>console.log(a) // Output: 20<br>/* ------------------------------------------------------------------- */<br>const b = 10;<br>console.log(b) // Output: 10<br>b = 20;<br>console.log(b) // TypeError: Assignment to constant variable.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*2JpWEhPktYvRk0Y7dvw27g.png" /><figcaption>Error: assignment to constant variable.</figcaption></figure><p>Here we can clearly see that we’re not allowed to change the value of a variable once defined which has been declared via const.</p><p>Now let’s check another code -</p><pre>const x = {<br>  a: 10,<br>  b: 20<br>}<br><br>console.log(x.a) // Output: 10<br>x.a = 50<br>console.log(x.a) // Output: 50</pre><p>However, we can see here that we were able to successfully change the value of x.a despite being defined via const. Now the point to keep in mind is that again we were never able to change the value of x instead we changed the property inside an object since it’s still possible to be a property of the object. If you want to prevent the updation of the internal property too, you can try something like Object.freeze(x), and then the internal property will also be prevented from updating.</p><h3>📌 Summary</h3><p>And that’s <strong>var</strong>, <strong>let</strong>, and <strong>const</strong> for you! They may seem small, but they&#39;re mighty important.</p><p>Let’s recap once again —</p><ol><li>Variables defined via var are function-level scoped whereas variables defined via let or const are block-level scoped.</li><li>Variables can be re-defined again if created via var, but it’s not possible if created via let or const.</li><li>Hoisting is only possible for variables created through var.</li></ol><p>🌟 Enjoyed the read? I’d love to hear your thoughts! Share your takeaways and let’s start a conversation. Your insights make this journey richer for all of us.</p><p>👏 If you found this helpful, a clap or two would mean the world — it helps more folks find these guides!</p><p>🔜 What’s next? I’m already brewing the next topic, packed with more insights and a-ha moments. Stay tuned!</p><p>🙏 A big thank you for spending time with my words. Your support fuels my passion for sharing knowledge.</p><p>👋 Until next time, keep coding and keep exploring!</p><p>💬 Let’s stay connected! Follow me on Medium for more adventures in coding: <a href="https://thenomadtechie.medium.com/">https://thenomadtechie.medium.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba3c025a9e88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoding the this Keyword in JavaScript: A Simplified Guide]]></title>
            <link>https://thenomadtechie.medium.com/decoding-the-this-keyword-in-javascript-a-simplified-guide-a6544fb5353a?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6544fb5353a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[this-keyword]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Tue, 14 Nov 2023 04:34:20 GMT</pubDate>
            <atom:updated>2023-11-14T04:34:20.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l7-6Usof1hwMJ2kJ" /><figcaption>Photo by <a href="https://unsplash.com/@srz?utm_source=medium&amp;utm_medium=referral">sydney Rae</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>🔍 <strong>THIS</strong> has always been confusing for all the developers in the history of Javascript, and I believe no one is untouched by its mighty confusion. I was also once very confused and always tried to avoid this keyword as much as possible and needless to say it cost me a lot when I faced <strong>this</strong> in interviews. But believe me, it’s super easy when you understand it, and becomes one of the handy ways of writing elegant code in Javascript. We will together unfold the mystery of this keyword in Javascript.</p><h3>Let’s understand THIS in the easiest way possible.</h3><p>🚀OK, let’s start by first defining it. <strong>This</strong> is a reserved keyword in Javascript that references an <strong>object</strong>. Now you’ll ask what that object refers to.</p><p>And this is where things get a little tricky and we get confused. So, basically, this always refers to the object where the function was invoked whose value differs on how and where it was called.</p><p>Basically, this keyword stores the value of the execution context where the function was called and it always varies and can be even explicitly changed.</p><p>Now let’s understand different scenarios where this works differently.</p><h3>Different scenarios of this in javascript</h3><p>Whenever we execute our code in javascript, a new execution context(we will cover this another interesting topic later in another blog) is created in the stack of the JS engine and its behavior always varies on how that function was invoked.</p><p>We’ll explore them one by one —</p><h4>1. Default binding 🌐</h4><p>Let’s first console this and see what it returns.</p><pre>console.log(this)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*OyZWteGDO13968gBvxnolw.png" /><figcaption>global object as a `this`</figcaption></figure><p>So, we can clearly see when we’re calling this it’s returning the global windows object which is the current execution context of the main function running the console. Just note one more thing in strict mode it returns null because <strong>default binding</strong> is not allowed.</p><p>Now we can say by default this refers to the global window object in default binding. Let’s understand it via code.</p><pre>var firstName = &#39;John&#39;;<br>function getName() {<br>  console.log(`My name is ${this.firstName}`);<br>}<br>getName(); // Output: &#39;My name is John&#39;</pre><p>Here we can clearly see that firstName was defined under the global windows context as per the default binding of this to global windows, this.firstName returned John.</p><p>Let’s get over another example now —</p><pre>var firstName = &#39;John&#39;;<br><br>function getName() {<br>  var firstName = &#39;Jane&#39;;<br>  getMyName(); // or this.getMyName()<br>}<br>function getMyName() {<br>  console.log(`My name is ${this.firstName}`);<br>}<br>getName(); // Output: &#39;My name is John&#39;</pre><p>Here nothing changed, despite the fact that the new function getMyName was called under the execution context of getName() function, and instead of Jane we got John.</p><p>When you declare a regular function in JavaScript (like foo and bar), the value of this inside that function is not bound to the function itself or the function&#39;s lexical scope. It&#39;s determined entirely by how the function is called. But in case these were methods bound to some objects, then the scenario would be entirely different, which we will explore in the next topic, i.e. <strong>Implicit Binding.</strong></p><h4>2. Implicit Binding 🔗</h4><p>Let’s first go through the code written below —</p><pre>const obj = {<br>  firstName: &quot;Rishav&quot;,<br>  getName: function() {<br>    console.log(`My name is ${this.firstName}`);<br>  }<br>}<br><br>obj.getName(); // Output: &#39;My name is Rishav&#39;</pre><p>Here, I got my name Rishav printed since this was referring to the obj object instead of the global object this time. This is internal binding.</p><p>Now you might wonder what happened here. So, let’s dig it a little bit.</p><p>Whenever we create any method that is not a regular function, and if this is called within it, then the value of this is bound automatically to the parent object where that particular method was created. In this case, getName() was that method. This is called an <strong><em>Implicit binding</em></strong><em> of </em><em>this</em> when called inside methods.</p><p>Let’s tweak our code a little bit —</p><pre>const obj = {<br>  firstName: &quot;Rishav&quot;,<br>  getName: function() {<br>    console.log(`My name is ${this.firstName}`);<br>  }<br>}<br><br>const myName = obj.getName;<br>myName() // Output: &#39;My name is undefined&#39;</pre><p>WHAT THE HECK?????</p><p>How come we’re getting undefined here instead of Rishav now?</p><p>So, If you read the line const myName = obj.getName;, this is called a function expression. Now, when we wrote this code it created a regular function named myName which has a global execution context and this keyword now points to a global window object abiding by the concept of <strong>default binding.</strong></p><h4>3. Explicit Binding 🎯</h4><p>Now you might be wondering what if I want to change the reference object where this is pointing to?</p><p>Here are those three beautiful methods that make this possible, i.e <strong>.bind()</strong>, <strong>.call()</strong>, and <strong>.apply().</strong></p><p>Using these above methods, you can force the function invocation to use the given particular object as a reference</p><p>Let’s take the previous example and fix it to get my name —</p><pre>const obj = {<br>  firstName: &quot;Rishav&quot;,<br>  getName: function() {<br>    console.log(`My name is ${this.firstName}`);<br>  }<br>}<br><br>const myName = obj.getName.bind(obj);<br>myName(); // Output: &#39;My name is Rishav&#39;</pre><p>And, here we are with my name again being consoled out. Hurrayyy!</p><p>Similar to <strong>.bind()</strong>, we have <strong>.call()</strong> and <strong>.apply()</strong>. In the case of these two methods function is immediately called with a new reference of this passed as an argument instead of <strong>.bind()</strong> where a new function invocation was created.</p><p><strong>.call()</strong> and <strong>.apply()</strong> just differ in how they’re called. <strong>.call()</strong> takes the function arguments as a separated by comma, whereas <strong>.apply()</strong> takes arguments as an array.</p><p>Let’s write one example for these too —</p><pre>function getMyName(friend) {<br>  console.log(`Hey ${friend}, my name is ${this.firstName}`);<br>}<br><br>const obj = {<br>  firstName: &#39;Rishav&#39;,<br>};<br>getMyName.call(obj, &#39;Jack&#39;); // &#39;Hey Jack, my name is Rishav&#39;<br>getMyName.apply(obj, [&#39;Joe&#39;]); // &#39;Hey Joe, my name is Rishav&#39;</pre><h4>4. New Binding 🆕</h4><p>Let’s first write a code and then understand this more clearly —</p><pre>function getName() {<br>  console.log(this) // ??<br>}<br><br>const myName = new getName();<br>console.log(myName)</pre><p>What do you think, we get as a value of this here?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*ccgEvvrat6uQEmjT7m_2Pg.png" /></figure><p>Surprising isn’t it?</p><p>This is something completely new this is referring to.</p><p>So, whenever we use new constructor of a function, its prime duty is to create a new empty object in the background and return it. And in this whole process, it sets the reference of this to that newly created object itself.</p><p>Let’s see this truth practically —</p><pre>function details(firstName, lastName) {<br>  this.firstName = firstName;<br>  this.lastName = lastName;<br>  this.getName = function () {<br>    console.log(`My name is ${this.firstName} ${this.lastName}`);<br>  };<br>}<br><br>const myName = new details(&#39;Rishav&#39;, &#39;Pandey&#39;);<br>myName.getName(); // Output: &#39;My name is Rishav Pandey&#39;</pre><p>Can you see, our getName function is now acting as a method of a brand-new object that has been created by new constructor, and this points to that newly created object itself stored in the myName variable.</p><p>I guess, this was it. We understood all 4 different scenarios on how this works when dealing with Javascript. But here’s a catch when it comes to the <strong>arrow function</strong>, things changes completely which we will explore now.</p><h3>Arrow Function and it’s chemistry with THIS</h3><p>➡️ In the arrow function, Javascript sets this lexically. That means when it comes to this, the execution context is not taken into consideration and the arrow function inherits the value of this from the outer function where that arrow function was defined.</p><p>Let’s look at the code below —</p><pre>const obj = {<br>  name: &quot;Rishav Pandey&quot;,<br>  innerFunction() {<br>    const getName = () =&gt; {<br>      console.log(`My name is ${this.name}`);<br>    }<br>    getName()<br>  }<br>}<br><br>obj.innerFunction() // Output: &#39;My name is Rishav Pandey&#39;</pre><p>I get my name printed here, as this inherits the value of the object whose reference was created for the execution context of the innerFunction() function, instead of getName(). Instead, if we had created getName() as a regular function this would have been pointing to a global object. <strong>Try this as a homework.</strong></p><p>Let’s go through another code here —</p><pre>const outerThis = this;<br><br>const func = () =&gt; {<br>    console.log(this === outerThis);<br>};<br><br>func.call(null);        //true<br>func.apply(undefined);  //true<br>func.bind({})();       //true</pre><p><strong><em>this</em></strong> will always refer to the lexical scope and not be impacted by any rule from the 4 rules such as explicit binding in the above example.</p><h3>Summary</h3><p>📝I hope we were able to decode <strong>this</strong> mystery in JavaScript and are now ready to explain this beautiful concept to others. Let’s recap things once again -</p><ol><li>This value of <strong>this</strong> generally depends on the execution context of a function.</li><li>In general, it will always refer to global objects as a part of <strong>default binding.</strong></li><li>We can change the reference of this if needed via <strong>.bind()</strong>, <strong>.call()</strong>, and <strong>.apply().</strong></li><li>For <strong>arrow functions</strong>, rules change a little bit. It’ll inherit the value from the other function where that particular arrow function was created.</li></ol><p>I understand the blog went a little bit, but I hope it was worth it and we learned something new together.</p><p>Sending my love to all the readers, and do show your love and support and give some claps if you found this really useful.</p><p>I will be coming soon again with a new interactive blog covering a new topic.</p><p>Thanks again for reading, till then bye and take care.</p><p><em>Connect with me on </em><strong><em>Medium</em></strong><em> ✍ :</em> <a href="https://medium.com/@thenomadtechie">https://medium.com/@thenomadtechie</a> for more such amazing learning</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6544fb5353a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Prototypal Inheritance in JavaScript: A Comprehensive Guide]]></title>
            <link>https://thenomadtechie.medium.com/mastering-prototypal-inheritance-in-javascript-a-comprehensive-guide-8ec2e92afba8?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ec2e92afba8</guid>
            <category><![CDATA[prototypal-inheritance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 09:20:15 GMT</pubDate>
            <atom:updated>2023-11-12T09:22:26.587Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding Prototypal inheritance in Javascript is the key concept to understand how objects really work in Javascript which has always been tricky when compared to other traditional OOPS patterns in different programming languages. Prototypal inheritance is a way in which our objects in JS can inherit properties/methods from other objects.</p><p><strong>This is one of the most commonly asked questions in Senior Frontend Interviews</strong></p><p>Let’s first go through a code snippet and understand it —</p><pre>//We have an object `person1` with two properties `name` and `place`<br>const person1 = {<br>  name: &quot;bob&quot;,<br>  place: &quot;Amsterdam&quot;<br>}<br><br>// we have another object `person2` with property `name` <br>const person2 = {<br>  name: &quot;john&quot;<br>}<br><br>console.log(person2.name) // john<br>console.log(person2.place) // undefined</pre><p>The above code snippet is pretty clear about how we created two different objects while logging person2.place we get undefined which is correct and expected, let’s add something magical to the above code -</p><pre><br>person2.__proto__ = person1<br><br>console.log(person2.place) // Amsterdam</pre><p>WHAT? Now we’re getting Amsterdam a value of person2.place that was never defined by us earlier. So, what’s going on here?</p><p>Let’s confirm if there’s any property place existing in person2 the object via hasOwnProperty the method —</p><pre>console.log(person2.hasOwnProperty(&quot;place&quot;)) // false</pre><p>So, what’s really going on here? We do not have any place property defined in the person2 object but still, it’s returning a value when we’re trying to access it.</p><p>If you remember we wrote a magical line person2.__proto__ = person1 and this is where everything happened, now let&#39;s understand how.</p><h3>Understanding Prototypal Inheritance in Javascript</h3><p>In Javascript, all the objects have a hidden property [[Prototype]] which either stores null within it or stores references to another object, and then we’ve another method __proto__ (proto property) which is a getter/setter of the hidden [[Prototype]] property of the object.</p><p>Whenever we try to fetch any property/method from any object, it has a default tendency to look over its own property, and if not found it checks within its [[Prototype]] property and returns the value. This is why we were able to get place property inside person2 object which was originally defined inside person1 object.</p><p>Let’s verify our concept and try to console person2 —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*j7z-2XKMqm-1QzvTKm3UUg.png" /><figcaption>person2 has [[Prototype]] property</figcaption></figure><p>We can clearly see in the above image that we’ve [[Prototype]] object inside person2 which stores the reference of person1 object created earlier.</p><h3>Prototype Chain</h3><p>You might be wondering why is there another [[Prototype]] property inside the [[Prototype]] property of person2 object. And first of all, what&#39;s this [[Prototype]] in the object that we never defined?</p><p>This is the concept of a prototype chain in which an object looks over its [[Prototype]] to fetch the property/method and if not found it iterates to the [[Prototype]] of its own [[Prototype]] and if again not found it goes on till it finds the null.</p><p>Isn’t it confusing, let’s understand by another example —</p><pre>let animal = {<br>  eats: true<br>};<br><br>let rabbit = {<br>  jumps: true,<br>  __proto__: animal<br>};<br><br>let kangaroo = {<br>  swims: true,<br>    __proto__: rabbit<br>}<br><br>console.log(kangaroo.eats) // true</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBlnvjooX8qdbb3wA-ugag.png" /><figcaption>visualization of prototypal chaining</figcaption></figure><p>This is how chained prototypal inheritance looks like when consoled out —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*oDHf6nGQWukmnmZPkMhsGQ.png" /><figcaption>prototypal chaining in picture</figcaption></figure><h3>Things to note about Prototypal Inheritance in object</h3><ol><li>The reference of the prototype can’t be like a loop, like creating a circle. Javascript will throw an error if we try to assign __proto__ in a circle.</li><li>The value of __proto__ can be either an object or null. Other types are ignored.</li><li>An object can only have a single [[Protype]] property within it, it never inherits from two objects at the same time.</li><li>Prototype chaining ends only when it encounters null, or else it’ll go to the n level of depth to the top finding the requested property in the object.</li><li>An object always looks first within itself to search for any property before looking to its [[Prototype]], if it gets the same property both within itself and [[Prototype]], it’ll give priority to its own property.</li></ol><h3>Creating prototypal inheritance using Object.create()</h3><p>We already saw a way in which we can inherit the property defined in any object to another object via the __proto__ keyword. But we can do this in other ways too.</p><p>We can use Object.create() method to create any object and bind another object to its prototype. Let’s visualize how —</p><pre>let animal = {<br>  eats: true<br>};<br><br>let rabbit = Object.create(animal, {jumps: {value: true}})<br><br>console.log(rabbit.eats) // true</pre><h3>Summary</h3><p>In JavaScript, we have the ability to use properties defined in one object to be used by different objects, which is known as <strong>Prototypal Inheritance.</strong></p><p>JavaScript looks for inherited properties in the prototype of the object, but also in the prototype of the prototype, and so on in the chain of prototypes.</p><p>This is one of the classic ways of using OOPS in javascript and it’s very useful when used effectively.</p><p><strong><em>Have any questions about prototypal inheritance? Let’s connect in a comment box!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ec2e92afba8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My VS Code setting for Web Development in 2022]]></title>
            <link>https://thenomadtechie.medium.com/my-vs-code-setting-for-web-development-in-2022-16a094d94675?source=rss-319389bdb1cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a094d94675</guid>
            <category><![CDATA[development-tips]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Rishav Pandey]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 13:46:50 GMT</pubDate>
            <atom:updated>2022-07-30T13:46:50.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wRL2vgOwXmj3ILvA_XyHg.jpeg" /><figcaption>Image by Pexels from Pixabay</figcaption></figure><p>After using VS Code for the last 5–6 years, I’ve tried tons of customization and setup in my Editor. No doubt VS code is expensive in terms of its memory usage of the system but with lots of features and being a Developer centric Editor it’s worth trying.</p><p>I’ve been now obsessed with the configuration and setup I’ve done which has undoubtedly increased my overall productivity a lot, and now would love to share my this setup with you all.</p><h3><strong>Appearance</strong></h3><h4><strong>Theme</strong></h4><p>I’ve been using the <strong>Dark</strong> color scheme from the start when I started using sublime(again one excellent editor you can try).</p><p>Now, this is a personal choice and you can try the Light theme also.</p><p>I’ve tried several different themes, and now using <a href="https://draculatheme.com/visual-studio-code"><strong>Dracula</strong></a> for quite a long. There are other themes also worth trying like <strong>Monokai, Tokyo Night, Ayu, Night Owl, Cobalt2</strong>.</p><figure><img alt="Dracula Theme VS Code" src="https://cdn-images-1.medium.com/max/1024/1*-wg34k8ieAlSrYcydzQvwA.png" /></figure><h4>Font and Styling</h4><p>Choosing a good font and its styling is very important if you’re planning to spend most of your time on the editor itself.</p><p>My personal choice here is <a href="https://github.com/microsoft/cascadia-code/wiki/Installing-Cascadia-Code"><strong>Cascadia Code</strong></a><strong> </strong>or <a href="https://github.com/tonsky/FiraCode/wiki/VS-Code-Instructions"><strong>Fira Code</strong></a>. You’re going to get some very cool interactive styling while writing the code. This even increases the readability of the code a lot. Few other fonts worth trying here are <strong>Source Code Pro, JetBrains Mono, Monolisa</strong>(paid).</p><figure><img alt="Cascadia Code VS Code" src="https://cdn-images-1.medium.com/max/1024/1*bn2Yx7NvbTkvO2JkFbxa3Q.png" /></figure><h3>Extensions</h3><p>Now comes the real power of VSCode. Let me introduce you to some of the coolest extensions ones can use for writing efficient code while creating some cool web applications.</p><p>Those marked with an asterisk(*) should be definitely tried once.</p><p>1. <a href="https://marketplace.visualstudio.com/items?itemName=apollographql.vscode-apollo">Apollo GraphQL</a> — Rich editor support for GraphQL client and server development that seamlessly integrates with the Apollo platform<br>2. <a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag">Auto Rename Tag</a> — Automatically rename paired HTML/XML tag *<br>3. <a href="https://marketplace.visualstudio.com/items?itemName=mgmcdermott.vscode-language-babel">Babel JavaScript</a> — VSCode syntax highlighting for today’s JavaScript. *<br>4. <a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments">Better Comments</a> — Improve your code commenting by annotating with alerts, informational, TODOs, and more!<br>5. <a href="https://marketplace.visualstudio.com/items?itemName=softwaredotcom.swdc-vscode">Code Time</a> — Code Time is an open source plugin that provides programming metrics right in Visual Studio Code.<br>6. <a href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight">Color Highlight</a> — Highlight web colors in your editor<br>7. <a href="https://marketplace.visualstudio.com/items?itemName=pranaygp.vscode-css-peek">CSS Peek</a> — Allow peeking to CSS ID and class strings as definitions from HTML files to respective CSS. Allows peek and goto definition.<br>8. <a href="https://marketplace.visualstudio.com/items?itemName=IronGeek.vscode-env">ENV</a> — Adds formatting and syntax highlighting support for env files (.env) to Visual Studio Code<br>9. <a href="https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens">Error Lens</a> — Improve highlighting of errors, warnings, and other language diagnostics. *<br>10. <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">Eslint</a> — Find and fix problems in your JavaScript code. *<br>11. <a href="https://marketplace.visualstudio.com/items?itemName=GitHub.copilot">GitHub Copilot</a> — Your AI pair programmer<br>12. <a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens">GitLens</a> — Supercharge Git within VS Code *<br>13. <a href="https://marketplace.visualstudio.com/items?itemName=kumar-harsh.graphql-for-vscode">GraphQL for VSCode</a> — GraphQL syntax highlighting, linting, auto-complete, and more!<br>14. <a href="https://marketplace.visualstudio.com/items?itemName=ecmel.vscode-html-css">HTML CSS Support</a> — CSS Intellisense for HTML<br>15. <a href="https://marketplace.visualstudio.com/items?itemName=bradgashler.htmltagwrap">htmltagwrap</a> — Wraps selected code with HTML tags<br>16. <a href="https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost">Import Cost</a> — Display import/require package size in the editor *<br>17. <a href="https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets">JavaScript (ES6) code snippets</a> — Code snippets for JavaScript in ES6 syntax *<br>18. <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Live Server</a> — Launch a local development Server with live reload feature for static &amp; dynamic pages *<br>19. <a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense">npm Intellisense</a> — Visual Studio Code plugin that autocompletes npm modules in import statements *<br>20. <a href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console">Nx Console</a> — Nx Console for Visual Studio Code<br>21. <a href="https://marketplace.visualstudio.com/items?itemName=pnp.polacode">Polacode</a> — 📸 Polaroid for your code<br>22. <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">Prettier</a> — Code formatter using prettier *<br>23. <a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager">Project Manager</a> — Easily switch between projects *<br>24. <a href="https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync">Settings Sync</a> — Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces, and Extensions Across Multiple Machines Using GitHub Gist. *<br>25. <a href="https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint">Stylelint</a> — Official Stylelint extension for Visual Studio Code<br>26. <a href="https://marketplace.visualstudio.com/items?itemName=SimonSiefke.svg-preview">Svg Preview</a> — Preview for SVG files.<br>27. <a href="https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons">vscode-icons</a> — Icons for Visual Studio Code</p><h3>Frequently used shortcuts (in Mac) which ease my development</h3><p>1. Toggle Explorer — CMD+B<br>2. Global search — CMD+SHIFT+F<br>3. Global search and Replace — CMD+SHIFT+H<br>4. Opening list of projects (Project Manager) — CMD+OPTION+P<br>5. Selecting line of codes in all the directions from the cursor — CMD+SHIFT+ARROW_KEY<br>6. Navigating the whole line UP/DOWN — OPTION+TOP/BOTTOM ARROW KEY<br>7. Copying the whole line beneath it — SHIFT+OPTION+DOWN_ARROW<br>8. Selecting any word in all the places present in the file — Double click on that word and CMD+D.<br>9. Multiple cursors — CMD+LEFT_CLICK<br>10. Emmet shortcuts — checkout to the <a href="https://code.visualstudio.com/docs/editor/emmet">link</a> <br>11. Faster navigation with keyboard — Try using arrow_keys with OPTION/CMD Keys.</p><h3>Recommended Settings/Configs I follow.</h3><ol><li>Set <strong>Require config </strong>to<strong> <em>true</em></strong> to avoid unnecessary formatting when working on a collaborative project.</li></ol><figure><img alt="Prettier config" src="https://cdn-images-1.medium.com/max/1024/1*cyCTh9HJsiYE4sSACB3klA.png" /></figure><p>2. Set <strong>Auto Save</strong> to <strong><em>onWindowChange</em></strong> and avoid losing the changes made while switching the editor.</p><figure><img alt="File AutoSave" src="https://cdn-images-1.medium.com/max/1024/1*eYEeuQj7j2lEPEmwfkKVfA.png" /></figure><p>3. Use the <strong>Project Manager</strong> extension and add frequently used projects there. You can easily switch between multiple projects despite their location with a few keystrokes.<br>4. Configure terminal with <strong><em>code</em></strong> command and use VSCode inbuilt terminal. It saves a lot of time.<br>5. Never hesitate of using good extensions just to save some space on the system, It helps a lot in our day-to-day work.<br>6. Use CLI for every possible thing, and avoid GUI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a094d94675" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>