<?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: Himanshu Sahni</title>
    <description>The latest articles on DEV Community by Himanshu Sahni (@mrhimanshusahni).</description>
    <link>https://dev.to/mrhimanshusahni</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%2F1470303%2Ff02ac008-3478-4321-86b1-61593e44868d.jpg</url>
      <title>DEV Community: Himanshu Sahni</title>
      <link>https://dev.to/mrhimanshusahni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrhimanshusahni"/>
    <language>en</language>
    <item>
      <title>Debouncing ⏳ Vs Throttling ⏱</title>
      <dc:creator>Himanshu Sahni</dc:creator>
      <pubDate>Sat, 06 Jul 2024 18:56:10 +0000</pubDate>
      <link>https://dev.to/mrhimanshusahni/debouncing-vs-throttling-2p22</link>
      <guid>https://dev.to/mrhimanshusahni/debouncing-vs-throttling-2p22</guid>
      <description>&lt;p&gt;Debouncing and throttling are both used to enhance the website performance by limiting the number of times the events are triggered. Debouncing and throttling are not provided by JavaScript. They’re just concepts that can be implemented using the setTimeout web API.&lt;/p&gt;




&lt;h2&gt;
  
  
  Debouncing ⏳
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In the debouncing technique, no matter how many Times the user fires the event, the attached function will be executed only after The specified time once the user stops firing the event.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Throttling ⏱
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Throttling is a Technique in which, no matter how many times the user fires The event, the attached function will be executed only once in a given time interval.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Comparison between Debouncing and Throttling
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x9e8uxuh2vnyqfuet0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x9e8uxuh2vnyqfuet0t.png" alt="debouncing_vs_throttling"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Real life Scenarios
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Debounce in Action: Live Search&lt;/strong&gt;&lt;br&gt;
Consider a live search feature where users see search results as they type. Debouncing ensures that the search function is triggered only after the user pauses, preventing unnecessary server requests during rapid typing.&lt;/p&gt;

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

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




&lt;p&gt;&lt;strong&gt;Throttle in Action: Scrolling Animation&lt;/strong&gt;&lt;br&gt;
Imagine a scroll-triggered animation. Throttling can be applied to update the animation at a controlled rate, preventing a flood of updates and ensuring a smoother visual experience.&lt;/p&gt;

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

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




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Debounce and throttle are indispensable tools in a developer's toolkit, offering precise control over the execution of code in response to user actions. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Debounce is your patient friend, waiting for the right moment, while throttle is the regulator, maintaining a steady pace.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Understanding when and how to apply these concepts can significantly enhance the performance and user experience of your web applications.&lt;/p&gt;




&lt;p&gt;I hope you liked this article 😀&lt;br&gt;
Happy_Coding 😎&lt;/p&gt;

&lt;p&gt;Follow me for more tutorials and tips on web development. Feel free to leave comments or questions below!&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow and Subscribe 🤗
&lt;/h2&gt;

&lt;p&gt;Twitter - &lt;a href="https://twitter.com/mrHimanshuSahni" rel="noopener noreferrer"&gt;https://twitter.com/mrHimanshuSahni&lt;/a&gt;&lt;br&gt;
Linkedin - &lt;a href="https://www.linkedin.com/in/mrhimanshusahni/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/mrhimanshusahni/&lt;/a&gt;&lt;br&gt;
Github - &lt;a href="https://github.com/mrhimanshusahni" rel="noopener noreferrer"&gt;https://github.com/mrhimanshusahni&lt;/a&gt;&lt;br&gt;
Youtube - &lt;a href="https://www.youtube.com/@mrhimanshusahni" rel="noopener noreferrer"&gt;https://www.youtube.com/@mrhimanshusahni&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Throttling in JavaScript ⏱🚀</title>
      <dc:creator>Himanshu Sahni</dc:creator>
      <pubDate>Sat, 06 Jul 2024 18:55:48 +0000</pubDate>
      <link>https://dev.to/mrhimanshusahni/throttling-in-javascript-2019</link>
      <guid>https://dev.to/mrhimanshusahni/throttling-in-javascript-2019</guid>
      <description>&lt;p&gt;As a developer, making your website user-friendly is important. This goes a long way toward the product's success, and a key part of the user experience is the website's performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents 📃
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is Throttling in JavaScript?&lt;/li&gt;
&lt;li&gt;How to implement Throttling in JavaScript&lt;/li&gt;
&lt;li&gt;Implement Throttling using a Custom Hook&lt;/li&gt;
&lt;li&gt;Implementations of throttling in JavaScript libraries&lt;/li&gt;
&lt;li&gt;Why use Throttling?&lt;/li&gt;
&lt;li&gt;Use Cases for Throttling&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  What is Throttling? 🙄
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Throttling is a technique that limits how often a function can be called in a given period of time.&lt;/strong&gt; It is useful for improving the performance and responsiveness of web pages that have event listeners that trigger heavy or expensive operations, such as animations, scrolling, resizing, fetching data, etc. &lt;/p&gt;

&lt;p&gt;For example, if you have a function that fetches some data from an API every time the user scrolls the page, you might want to throttle it so that it only makes one request every second, instead of making hundreds of requests as the user scrolls. This way, you can avoid overloading the server or the browser with unnecessary requests and reduce the bandwidth consumption.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pictorial Representation
&lt;/h2&gt;

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




&lt;h2&gt;
  
  
  How to implement Throttling in JavaScript
&lt;/h2&gt;

&lt;p&gt;Let's Take a function &lt;strong&gt;&lt;code&gt;myFunction(a, b)&lt;/code&gt;&lt;/strong&gt; having two arguments.&lt;/p&gt;

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

&lt;p&gt;We want to modify this function so that it can only be called once in &lt;strong&gt;&lt;code&gt;500ms&lt;/code&gt;&lt;/strong&gt;. So, throttling will take &lt;strong&gt;&lt;code&gt;myFunction()&lt;/code&gt;&lt;/strong&gt; as an input, and return a modified (throttled) function &lt;strong&gt;&lt;code&gt;throttledFun()&lt;/code&gt;&lt;/strong&gt;  that can only be executed &lt;strong&gt;&lt;code&gt;500ms&lt;/code&gt;&lt;/strong&gt; after the previous function was executed.&lt;/p&gt;

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

&lt;p&gt;By using the above throttled function, we now can have &lt;strong&gt;&lt;code&gt;throttledFun()&lt;/code&gt;&lt;/strong&gt; based on &lt;strong&gt;&lt;code&gt;myFunction()&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Implement Throttling using a Custom Hook
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a new file called as &lt;strong&gt;&lt;code&gt;useThrottle.js&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Add the below custom function that we have made above.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Usage of throttling and &lt;strong&gt;&lt;code&gt;myFunction()&lt;/code&gt;&lt;/strong&gt; with custom throttled hook.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Throttling &amp;amp; Debouncing with JavaScript libraries
&lt;/h2&gt;

&lt;p&gt;Libraries such as &lt;strong&gt;Lodash&lt;/strong&gt; offer &lt;code&gt;_.debounce&lt;/code&gt; and &lt;code&gt;_.throttle&lt;/code&gt; functions, providing a more robust and cross-browser compatible solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Throttling?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Performance Enhancement:&lt;/strong&gt; Reduces the number of function executions, prevents Overloading the server or the browser with too many requests or calculations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Management:&lt;/strong&gt; To manage the bandwidth or resources on operations that are not visible or relevant to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistent Updates:&lt;/strong&gt; Ensures regular updates at specified intervals, useful for tasks like updating a position indicator during scrolling.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Use Cases for Throttling
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scroll event listeners:&lt;/strong&gt; Many web applications utilize a scroll event listener to keep track of the scroll position and load or animate the content appropriately. In these cases, the scroll event may have a negative performance impact if we scroll it too frequently since it contains many videos and images. Thus, we must use throttling for the scroll event.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;In Gaming:&lt;/strong&gt; In games, a player needs to push the button to trigger any action, such as punching, shooting but during playtime, the user can hit the button more than one time in a second, and we want to trigger an action at the rate per second then the concept of Throttling will be useful for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Calls:&lt;/strong&gt; In some cases, we may wish to limit how frequently our application calls an external API. In this case, throttling can be advantageous. By rate limiting the calling function, it would eliminate unnecessary API requests to the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Throttling&lt;/strong&gt; is a powerful technique for optimizing web applications by controlling the frequency of function executions. By ensuring functions are called at regular intervals, throttling helps manage performance and resource usage effectively. Whether dealing with scrolling, resizing, or other rapid events, throttling is an essential tool in your JavaScript toolkit.&lt;/p&gt;




&lt;p&gt;I hope you found this blog helpful and learned something new about throttling in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can check out my recent articles on&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Debouncing in JavaScirpt &lt;div class="ltag__link"&gt;
  &lt;a href="/mrhimanshusahni" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1470303%2Ff02ac008-3478-4321-86b1-61593e44868d.jpg" alt="mrhimanshusahni"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrhimanshusahni/debouncing-in-javascript-2p3o" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Debouncing in JavaScript&lt;/h2&gt;
      &lt;h3&gt;Himanshu Sahni ・ Jun 9&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#learning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Debouncing vs Throttling &lt;div class="ltag__link"&gt;
  &lt;a href="/mrhimanshusahni" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1470303%2Ff02ac008-3478-4321-86b1-61593e44868d.jpg" alt="mrhimanshusahni"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/mrhimanshusahni/debouncing-vs-throttling-2p22" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Debouncing ⏳ Vs Throttling ⏱&lt;/h2&gt;
      &lt;h3&gt;Himanshu Sahni ・ Jul 6&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;I hope you liked this article 😀&lt;br&gt;
Happy_Coding 😎&lt;/p&gt;

&lt;p&gt;Follow me for more tutorials and tips on web development. Feel free to leave comments or questions below!&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow and Subscribe 🤗
&lt;/h2&gt;

&lt;p&gt;Twitter - &lt;a href="https://twitter.com/mrHimanshuSahni" rel="noopener noreferrer"&gt;https://twitter.com/mrHimanshuSahni&lt;/a&gt;&lt;br&gt;
Linkedin - &lt;a href="https://www.linkedin.com/in/mrhimanshusahni/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/mrhimanshusahni/&lt;/a&gt;&lt;br&gt;
Github - &lt;a href="https://github.com/mrhimanshusahni" rel="noopener noreferrer"&gt;https://github.com/mrhimanshusahni&lt;/a&gt;&lt;br&gt;
Youtube - &lt;a href="https://www.youtube.com/@mrhimanshusahni" rel="noopener noreferrer"&gt;https://www.youtube.com/@mrhimanshusahni&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Debouncing in JavaScript</title>
      <dc:creator>Himanshu Sahni</dc:creator>
      <pubDate>Sun, 09 Jun 2024 10:03:10 +0000</pubDate>
      <link>https://dev.to/mrhimanshusahni/debouncing-in-javascript-2p3o</link>
      <guid>https://dev.to/mrhimanshusahni/debouncing-in-javascript-2p3o</guid>
      <description>&lt;h2&gt;
  
  
  Debouncing in General term
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Debouncing&lt;/strong&gt; is a technique in programming that helps prevent time-consuming tasks from being triggered so frequently that they slow down the performance of a web page. In simpler terms, it controls how often a function is called. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Debouncing in JavaScript? 🤔
&lt;/h2&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;debouncing&lt;/strong&gt; is commonly used to enhance browser performance. Sometimes, certain actions on a web page involve complex computations that take up time. If these actions are triggered too frequently, it can significantly impact the browser's performance, especially since JavaScript operates on a single thread.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For Example:&lt;/strong&gt; Suppose we have a Search Input on the main page of a website that shows suggestions as the user types. Let's call a function to fetch suggestions on every keystroke. We might end up making too many requests to the backend server, which can slow down the application, waste resources, and, more importantly, affect User Experience. Instead, we can use debouncing to wait until the user has stopped typing for a while before making the request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How to implement debouncing in JavaScript? 😮
&lt;/h2&gt;

&lt;p&gt;The most common way to implement debouncing in JavaScript is to use a &lt;strong&gt;wrapper function that returns a new function that delays the execution of the original function.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Debouncing accepts a function and transforms it in to an updated (debounced) function so that the code inside the original function is executed after a certain period of time. If the debounced function is called again within that period, the previous timer is reset and a new timer is started for this function call. The process repeats for each function call.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Suppose we have a function &lt;code&gt;getData()&lt;/code&gt; that needs to execute after say's &lt;code&gt;300ms&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Let's implement a debounce wrapper&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;strong&gt;&lt;code&gt;index.js&lt;/code&gt;&lt;/strong&gt; file&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;&lt;strong&gt;How to use debounce function to use with original &lt;code&gt;getData()&lt;/code&gt; function&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Debounce Implementation using a Custom Hook
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The advantage of custom hooks is that you can reuse the same logic throughout your application. It is highly advisable to do so.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;&lt;strong&gt;Usage of debounce in hook with the above example&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;In the above example:&lt;/strong&gt;, we have type &lt;strong&gt;&lt;code&gt;laptop&lt;/code&gt;&lt;/strong&gt; as the input keyword, it has 6 words so 6 times &lt;strong&gt;&lt;code&gt;onChange&lt;/code&gt;&lt;/strong&gt; Event is triggered &lt;strong&gt;&lt;em&gt;but using the debounce technique we delay this function call after the user has finished typing or delay between 2 key press is greater than delay timer pass in debounce function.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case of Debouncing/Real-life examples of Debouncing
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Google Search:&lt;/strong&gt; Auto-complete functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elevator:&lt;/strong&gt; When you press the button to call the elevator, it doesn’t move immediately, but waits for a few seconds to see if anyone else wants to get on or off. This way, it avoids going up and down too frequently and saves energy and time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Debouncing&lt;/strong&gt; is a useful technique to optimize web applications by reducing unnecessary or repeated function calls that might affect the performance or user experience.&lt;br&gt;
Debouncing uses the important concept of &lt;strong&gt;&lt;em&gt;closures&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I hope you found this blog helpful and learned something new about Debouncing in JavaScript. &lt;/p&gt;

&lt;p&gt;KeepLearning, Happy_Coding&lt;/p&gt;

&lt;p&gt;Thanks for Reading 😀🤩&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Currying in JavaScript</title>
      <dc:creator>Himanshu Sahni</dc:creator>
      <pubDate>Sat, 01 Jun 2024 12:56:16 +0000</pubDate>
      <link>https://dev.to/mrhimanshusahni/currying-in-javascript-20d5</link>
      <guid>https://dev.to/mrhimanshusahni/currying-in-javascript-20d5</guid>
      <description>&lt;h2&gt;
  
  
  What is Function Currying in JavaScript ? 🙄🙄
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Currying&lt;/strong&gt; is an advanced technique of working with functions. It’s used not only in JavaScript, but in other languages as well.&lt;/p&gt;

&lt;p&gt;It is a technique in functional programming, that transforms the function of multiple arguments into several functions of a single argument in sequence. &lt;/p&gt;

&lt;p&gt;The translation of function happens something like this,&lt;/p&gt;

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

&lt;p&gt;Currying is a transformation of functions that translates a function from callable as &lt;code&gt;f(a, b, c)&lt;/code&gt; into callable as &lt;code&gt;f(a)(b)(c)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Please note: Currying doesn’t call a function. It just transforms it.&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to achieve Currying in JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Currying is not built-in by default in JavaScript. We can implement currying by following the ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be achieved by using the &lt;strong&gt;&lt;code&gt;bind()&lt;/code&gt;&lt;/strong&gt; method.&lt;/li&gt;
&lt;li&gt;It can be achieved by using the &lt;strong&gt;closures&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Using Third-party libraries such as &lt;strong&gt;Lodash&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1) Currying using &lt;strong&gt;&lt;code&gt;bind()&lt;/code&gt;&lt;/strong&gt; method&lt;/p&gt;

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

&lt;p&gt;2) Currying using &lt;strong&gt;closures&lt;/strong&gt; in JavaScript&lt;/p&gt;

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

&lt;p&gt;3) Currying using Third-party Library &lt;strong&gt;Lodash&lt;/strong&gt;&lt;/p&gt;

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




&lt;p&gt;&lt;strong&gt;Why is currying useful in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code re-usability&lt;/strong&gt;: Curried functions can be used to create reusable code that can be used in different contexts. Since curried functions can be partially applied, they can be reused with different arguments to create new functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved code readability&lt;/strong&gt;: Curried functions can make code more readable and expressive by breaking down complex logic into smaller, more manageable pieces. This can make it easier for developers to understand and maintain code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It helps us to avoid passing the same variable multiple times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Promotes functional programming&lt;/strong&gt;: Currying is a key concept in functional programming, and using curried functions in your code can promote functional programming practices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It reduces the chances of error in our function by dividing it into multiple smaller functions that can handle one responsibility&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Noted Points: The currying requires the function to have a fixed number of arguments.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A function that uses rest parameters, such as &lt;strong&gt;&lt;code&gt;f(...args)&lt;/code&gt;&lt;/strong&gt;, can’t be curried this way.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Currying in JavaScript is a technique that does the transform and makes &lt;code&gt;f(a,b,c)&lt;/code&gt; callable as &lt;code&gt;f(a)(b)(c)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Currying is a great technique that can bring many benefits to JavaScript programming. &lt;/p&gt;

&lt;p&gt;By using the currying technique, you can create more &lt;strong&gt;re-usable&lt;/strong&gt;, &lt;strong&gt;maintainable&lt;/strong&gt;, and &lt;strong&gt;modular code&lt;/strong&gt; that is better suited to the challenges of modern web development.&lt;/p&gt;

&lt;p&gt;Thanks for Reading 🙏😇&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Monkey Patching in JavaScript</title>
      <dc:creator>Himanshu Sahni</dc:creator>
      <pubDate>Mon, 27 May 2024 19:08:46 +0000</pubDate>
      <link>https://dev.to/mrhimanshusahni/monkey-patching-in-javascript-19c8</link>
      <guid>https://dev.to/mrhimanshusahni/monkey-patching-in-javascript-19c8</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Monkey Patching 🐵&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The term “&lt;strong&gt;monkey patching&lt;/strong&gt;” is borrowed from the world of software development, where it refers to the practice of modifying or extending code at runtime. In JavaScript, it allows developers to alter or extend the behavior of existing objects or classes without directly modifying their source code.&lt;/p&gt;

&lt;p&gt;In simple term's it is : &lt;u&gt;&lt;em&gt;&lt;strong&gt;Monkey patching&lt;/strong&gt;&lt;/em&gt; is a technique to add, modify, or suppress the default behavior of a piece of code at runtime without changing its original source code.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Monkey patching involves making changes to existing code, typically by adding new methods or properties to objects or classes, or by modifying existing ones. This can be done at runtime, allowing developers to augment functionality without altering the original code base. Monkey patching is often used to fix bugs, add missing features, or adapt third-party libraries to better suit specific requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let's see a basic example to understand this concept&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Pros of Monkey Patching&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Monkey patching allows developers to extend or modify existing code without directly altering its source, providing flexibility in adapting libraries or frameworks to specific requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Developers can experiment with new features or enhancements without committing to permanent changes in the code base.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It enables quick fixes to issues or bugs in third-party code without waiting for official updates or patches.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Cons of Monkey Patching&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Overuse of monkey patching can lead to code base complexity and reduced readability, making it harder to understand and maintain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modifying existing code at runtime can introduce unintended side effects or conflicts, especially in large or collaborative projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Scope Pollution&lt;/strong&gt;: Global scope pollution refers to a situation where too many variables, functions, or objects are introduced into the global scope. This makes it cluttered and can potentially lead to unintended behaviors. Monkey patching can introduce global scope pollution by adding or modifying properties and methods on built-in prototypes or objects. This can lead to naming conflicts and bugs, especially when using multiple libraries or codebases.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Traditional Monkey Patching and Why It Is it is Dangerous&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;The author of &lt;code&gt;Array&lt;/code&gt; could add a different implementation of &lt;code&gt;logAllMembers&lt;/code&gt;, which could break your code which relies on your implementation.&lt;/li&gt;
&lt;li&gt;Elsewhere in your codebase, someone could add a different implementation of &lt;code&gt;logAllMembers&lt;/code&gt;, leading to fragile code.&lt;/li&gt;
&lt;li&gt;Elsewhere in your codebase, it will be hard to tell whether &lt;code&gt;Array&lt;/code&gt; has been patched or not, so other programmers (or you) could accidentally depend on &lt;code&gt;Array&lt;/code&gt; being patched or not-patched.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Monkey patching&lt;/strong&gt; is a powerful technique for extending or modifying existing code dynamically. However, it comes with considerations like understanding the prototype chain, avoiding global scope pollution. While implementing monkey patching, you must exercise caution, document changes, and thoroughly test patches to mitigate compatibility issues and security risks.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>learning</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
