<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kiran </title>
    <description>The latest articles on Forem by Kiran  (@kiransm).</description>
    <link>https://forem.com/kiransm</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%2F657378%2Fe0aa65ef-7727-4342-b253-132bee5f1fb9.png</url>
      <title>Forem: Kiran </title>
      <link>https://forem.com/kiransm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kiransm"/>
    <language>en</language>
    <item>
      <title>JavaScript Design Patterns</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Fri, 17 Apr 2026 12:40:19 +0000</pubDate>
      <link>https://forem.com/kiransm/javascript-design-patterns-cg1</link>
      <guid>https://forem.com/kiransm/javascript-design-patterns-cg1</guid>
      <description>&lt;p&gt;Design patterns are reusable solutions to commonly occurring problems in software design. They fall into 3 categories:&lt;/p&gt;

&lt;p&gt;🏗️ &lt;strong&gt;&lt;u&gt;Creational Patterns&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
How objects are created&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Singleton&lt;/strong&gt;
Ensures only one instance of a class exists throughout the app.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptclass&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;db1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;db2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use when: Managing a shared resource like a DB connection or config object.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Factory&lt;/strong&gt;
A function/class that creates objects without specifying the exact class.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptfunction&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;write&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;delete&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;guest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;guest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;guest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;Use when: You need to create different object types based on a condition.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Builder&lt;/strong&gt;
Constructs complex objects step by step.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptclass&lt;/span&gt; &lt;span class="nx"&gt;QueryBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SELECT &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;` FROM &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;` WHERE &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueryBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;age &amp;gt; 18&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use when: Building complex objects like SQL queries, form configs, or request options.&lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;&lt;u&gt;Structural Patterns&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How objects are composed/organized&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Module&lt;/strong&gt;
Encapsulates code into self-contained units with private and public parts.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptconst&lt;/span&gt; &lt;span class="nx"&gt;CartModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; &lt;span class="c1"&gt;// private&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;getItems&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;

&lt;span class="nx"&gt;CartModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shoes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CartModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;total&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use when: You want to avoid polluting the global scope (very common in JS).&lt;/p&gt;

&lt;p&gt;5.** Decorator**&lt;br&gt;
Adds new behavior to an object without modifying the original.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptfunction&lt;/span&gt; &lt;span class="nf"&gt;withLogging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Calling with`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loggedAdd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;withLogging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;loggedAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// logs: Calling with [2, 3] → returns 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use when: Adding features like logging, caching, or auth checks to functions.&lt;/p&gt;

&lt;p&gt;🔔 &lt;strong&gt;&lt;u&gt;Behavioral Patterns&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How objects communicate&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Observer&lt;/strong&gt;
One object (subject) notifies multiple subscribers when something changes.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptclass&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listeners&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listeners&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;[]).&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listeners&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emitter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; logged in`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Alice logged in&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use when: Building event systems, real-time updates, or state management.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Strategy&lt;/strong&gt;
Defines a family of algorithms and makes them interchangeable at runtime.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptconst&lt;/span&gt; &lt;span class="nx"&gt;sorter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;bubble&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* bubble sort logic */&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;quick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* quick sort logic */&lt;/span&gt;  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sortData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;strategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sorter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use when: You need to switch between different implementations of the same behavior (sorting, payment methods, validation rules).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Reference&lt;/strong&gt;&lt;/p&gt;

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

</description>
      <category>architecture</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Cross-Site Scripting (XSS) Prevention</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Mon, 13 Apr 2026 18:07:19 +0000</pubDate>
      <link>https://forem.com/kiransm/cross-site-scripting-xss-prevention-mbk</link>
      <guid>https://forem.com/kiransm/cross-site-scripting-xss-prevention-mbk</guid>
      <description>&lt;p&gt;&lt;strong&gt;🔐 Cross-Site Scripting (XSS) Prevention&lt;/strong&gt; — What Every Frontend Dev Must Know&lt;/p&gt;

&lt;p&gt;XSS is one of the most common web attacks.&lt;/p&gt;

&lt;p&gt;👉 It allows attackers to run malicious JavaScript in your app&lt;br&gt;
👉 Can steal cookies, tokens, and user data&lt;/p&gt;

&lt;p&gt;🧠 &lt;strong&gt;What is XSS?&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt;stealCookies()&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If your app renders this → attacker code runs ❌&lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Types of XSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1️⃣ Stored XSS → saved in DB&lt;br&gt;
2️⃣ Reflected XSS → comes from URL/input&lt;br&gt;
3️⃣ DOM-based XSS → happens in browser&lt;/p&gt;

&lt;p&gt;🚨 &lt;strong&gt;How XSS Happens&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 Rendering untrusted input directly&lt;/p&gt;

&lt;p&gt;&lt;code&gt;div.innerHTML = userInput; // ❌ dangerous&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🛡️ &lt;strong&gt;How to Prevent XSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1️⃣ Escape / Sanitize Input&lt;br&gt;
✔ Never trust user input&lt;br&gt;
✔ Use libraries like DOMPurify&lt;/p&gt;

&lt;p&gt;2️⃣ Avoid Dangerous APIs&lt;br&gt;
❌ innerHTML&lt;br&gt;
❌ dangerouslySetInnerHTML in React&lt;/p&gt;

&lt;p&gt;✔ Use safe rendering ({data} in JSX)&lt;/p&gt;

&lt;p&gt;3️⃣ Use Content Security Policy (CSP)&lt;br&gt;
Content-Security-Policy: script-src 'self'&lt;br&gt;
👉 Blocks unauthorized scripts&lt;/p&gt;

&lt;p&gt;4️⃣ Secure Cookies&lt;br&gt;
✔ Use httpOnly&lt;br&gt;
✔ Use Secure flag&lt;/p&gt;

&lt;p&gt;👉 Prevents JS from accessing cookies&lt;br&gt;
5️⃣ Validate on Backend Frontend is not enough.&lt;/p&gt;

&lt;p&gt;✔ Always sanitize on server too&lt;/p&gt;

&lt;p&gt;6️⃣ Avoid Inline Scripts&lt;/p&gt;

&lt;p&gt;❌ alert()&lt;br&gt;
✔ Use external JS files&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Real Impact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;XSS can:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Steal JWT tokens&lt;/li&gt;
&lt;li&gt;Hijack sessions&lt;/li&gt;
&lt;li&gt;Perform actions as user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 It’s a serious production risk&lt;/p&gt;

&lt;p&gt;🚨 &lt;strong&gt;Interview Trap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ “React apps are safe from XSS”&lt;br&gt;
✔ React escapes by default, but unsafe APIs can still break it&lt;/p&gt;

&lt;p&gt;🎯 &lt;strong&gt;Interview One-Liner&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;XSS is a vulnerability where malicious scripts are injected into a web app, and it can be prevented by sanitizing input, avoiding unsafe DOM APIs, and enforcing CSP.&lt;/p&gt;

&lt;h1&gt;
  
  
  WebSecurity #XSS #Frontend #JavaScript #ReactJS #CyberSecurity #InterviewPrep #EngineeringMindset
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Redux: Complete Guide from Zero to Hero</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Wed, 08 Apr 2026 15:24:20 +0000</pubDate>
      <link>https://forem.com/kiransm/redux-complete-guide-from-zero-to-hero-4311</link>
      <guid>https://forem.com/kiransm/redux-complete-guide-from-zero-to-hero-4311</guid>
      <description>&lt;p&gt;Redux &amp;amp; React-Redux: Complete Deep Dive 🚀&lt;br&gt;
Let me break this down from absolute basics to advanced, the way you'd explain it confidently in an interview.&lt;/p&gt;

&lt;p&gt;🧠 The Core Problem Redux Solves&lt;br&gt;
Imagine a React app with 50 components. Component A needs data that lives in Component Z. Without Redux, you'd have to pass props down through every component in between — this is called prop drilling, and it's a nightmare.&lt;br&gt;
Redux gives you a single global store — think of it as a big JavaScript object that any component can read from or write to directly.&lt;/p&gt;

&lt;p&gt;🏛️ The 3 Sacred Principles of Redux&lt;/p&gt;

&lt;p&gt;Single source of truth — the entire app state lives in ONE store object&lt;br&gt;
State is read-only — you can NEVER directly mutate state (state.name = "John" ❌)&lt;br&gt;
Changes are made with pure functions — those functions are called reducers&lt;/p&gt;

&lt;p&gt;🔑 Core Building Blocks&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Store
The single JavaScript object holding your entire app's state.
jsimport { createStore } from 'redux';
const store = createStore(rootReducer);&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;store.getState()      // Read the current state&lt;br&gt;
store.dispatch(action) // Send an action to change state&lt;br&gt;
store.subscribe(fn)   // Listen for state changes&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Action
A plain JavaScript object that describes what happened. It MUST have a type field.
js// Action
{ type: 'ADD_ITEM', payload: { id: 1, name: 'Laptop' } }&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;// Action Creator (a function that returns an action)&lt;br&gt;
const addItem = (item) =&amp;gt; ({&lt;br&gt;
  type: 'ADD_ITEM',&lt;br&gt;
  payload: item&lt;br&gt;
});&lt;br&gt;
Interview tip: Action is just a messenger — it says what happened, not how to handle it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reducer
A pure function that takes (currentState, action) and returns a new state. Never mutates the old state.
jsconst initialState = { items: [], loading: false };&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;function cartReducer(state = initialState, action) {&lt;br&gt;
  switch (action.type) {&lt;br&gt;
    case 'ADD_ITEM':&lt;br&gt;
      return { ...state, items: [...state.items, action.payload] }; // NEW object!&lt;br&gt;
    case 'REMOVE_ITEM':&lt;br&gt;
      return { ...state, items: state.items.filter(i =&amp;gt; i.id !== action.payload) };&lt;br&gt;
    default:&lt;br&gt;
      return state; // Always return state in default!&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
Why pure? Same input → always same output. No side effects (no API calls, no random numbers). This makes Redux predictable and testable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dispatch
The only way to trigger a state change.
jsstore.dispatch(addItem({ id: 1, name: 'Laptop' }));&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔗 Connecting Redux to React (react-redux)&lt;br&gt;
Provider&lt;br&gt;
Wraps your entire app and makes the store available to all components.&lt;br&gt;
jsximport { Provider } from 'react-redux';&lt;/p&gt;

&lt;p&gt;root.render(&lt;br&gt;
  &lt;br&gt;
    &lt;br&gt;
  &lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;useSelector — Read from store&lt;br&gt;
jsxconst items = useSelector((state) =&amp;gt; state.cart.items);&lt;br&gt;
// state = entire Redux store, you pick what you need&lt;br&gt;
Interview tip: useSelector re-renders the component ONLY when the selected value changes. It's optimized.&lt;/p&gt;

&lt;p&gt;useDispatch — Write to store&lt;br&gt;
jsxconst dispatch = useDispatch();&lt;/p&gt;

&lt;p&gt;const handleAdd = () =&amp;gt; {&lt;br&gt;
  dispatch(addItem({ id: 1, name: 'Laptop' }));&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;Old way: connect() (you might be asked this)&lt;br&gt;
jsxconst mapStateToProps = (state) =&amp;gt; ({ items: state.cart.items });&lt;br&gt;
const mapDispatchToProps = { addItem };&lt;/p&gt;

&lt;p&gt;export default connect(mapStateToProps, mapDispatchToProps)(CartComponent);&lt;br&gt;
Modern code uses hooks (useSelector/useDispatch), but legacy codebases still use connect.&lt;/p&gt;

&lt;p&gt;⚙️ Middleware — The Most Important Advanced Topic&lt;br&gt;
What is Middleware?&lt;br&gt;
Middleware sits between dispatch and the reducer. It intercepts every action before it reaches the reducer.&lt;br&gt;
dispatch(action) → [Middleware 1] → [Middleware 2] → Reducer → New State&lt;br&gt;
This is where you handle side effects — API calls, logging, analytics, etc.&lt;br&gt;
Middleware signature (this impresses interviewers):&lt;br&gt;
jsconst myMiddleware = (store) =&amp;gt; (next) =&amp;gt; (action) =&amp;gt; {&lt;br&gt;
  // Do something before&lt;br&gt;
  console.log('Before:', action);&lt;br&gt;
  next(action); // Pass to next middleware or reducer&lt;br&gt;
  // Do something after&lt;br&gt;
  console.log('After:', store.getState());&lt;br&gt;
};&lt;br&gt;
Applied like this:&lt;br&gt;
jsimport { createStore, applyMiddleware } from 'redux';&lt;br&gt;
const store = createStore(rootReducer, applyMiddleware(myMiddleware));&lt;/p&gt;

&lt;p&gt;🔥 Redux Thunk (They WILL Ask This)&lt;br&gt;
The Problem&lt;br&gt;
By default, dispatch() only accepts plain objects. But what if you need to make an API call first, THEN dispatch?&lt;br&gt;
jsdispatch(fetchUser()); // ❌ fetchUser returns a function, not an object!&lt;br&gt;
What Thunk Does&lt;br&gt;
Redux Thunk is middleware that lets you dispatch a function instead of an object. That function receives dispatch and getState as arguments.&lt;br&gt;
bashnpm install redux-thunk&lt;br&gt;
jsimport thunk from 'redux-thunk';&lt;br&gt;
const store = createStore(rootReducer, applyMiddleware(thunk));&lt;br&gt;
Thunk in Action&lt;br&gt;
js// This is a "thunk" — a function that returns a function&lt;br&gt;
const fetchUsers = () =&amp;gt; async (dispatch, getState) =&amp;gt; {&lt;br&gt;
  dispatch({ type: 'FETCH_USERS_START' });  // Show loading spinner&lt;/p&gt;

&lt;p&gt;try {&lt;br&gt;
    const response = await fetch('/api/users');&lt;br&gt;
    const data = await response.json();&lt;br&gt;
    dispatch({ type: 'FETCH_USERS_SUCCESS', payload: data }); // Save data&lt;br&gt;
  } catch (error) {&lt;br&gt;
    dispatch({ type: 'FETCH_USERS_ERROR', payload: error.message }); // Handle error&lt;br&gt;
  }&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;// Usage in component&lt;br&gt;
dispatch(fetchUsers());&lt;br&gt;
Interview answer for "What is Thunk?"&lt;/p&gt;

&lt;p&gt;"Thunk is middleware that extends Redux's dispatch to accept functions. This lets us handle async operations like API calls. The thunk function receives dispatch and getState, so we can dispatch multiple actions — like a loading action, then a success or failure action — based on async results."&lt;/p&gt;

&lt;p&gt;⚡ Redux Saga (The "Chunk" They Mentioned)&lt;/p&gt;

&lt;p&gt;They likely said "Saga" not "chunk" — this is the other popular middleware.&lt;/p&gt;

&lt;p&gt;Thunk vs Saga&lt;br&gt;
Redux ThunkRedux SagaStyleAsync/await functionsGenerator functions (function*)ComplexitySimple, easy to learnSteeper learning curvePowerGood for simple asyncBetter for complex flowsTestingHarderEasier (pure effects)&lt;br&gt;
Saga Basics&lt;br&gt;
jsimport { call, put, takeEvery } from 'redux-saga/effects';&lt;/p&gt;

&lt;p&gt;// Worker saga — does the actual work&lt;br&gt;
function* fetchUsersSaga() {&lt;br&gt;
  try {&lt;br&gt;
    const data = yield call(fetch, '/api/users'); // call is like await&lt;br&gt;
    yield put({ type: 'FETCH_SUCCESS', payload: data }); // put is like dispatch&lt;br&gt;
  } catch (error) {&lt;br&gt;
    yield put({ type: 'FETCH_ERROR', payload: error });&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Watcher saga — watches for actions&lt;br&gt;
function* watchFetchUsers() {&lt;br&gt;
  yield takeEvery('FETCH_USERS_REQUEST', fetchUsersSaga);&lt;br&gt;
  // takeEvery = run saga for every matching action&lt;br&gt;
  // takeLatest = only run for the most recent action (cancels previous)&lt;br&gt;
}&lt;br&gt;
Interview answer for "Thunk vs Saga?"&lt;/p&gt;

&lt;p&gt;"Thunk is simpler — great for straightforward async operations. Saga uses generator functions and is better for complex scenarios like debouncing, cancelling requests, or running tasks in parallel. In most projects, Thunk is sufficient, but Saga shines in enterprise apps with complex async workflows."&lt;/p&gt;

&lt;p&gt;🏆 Redux Toolkit (RTK) — Modern Redux&lt;br&gt;
This is how everyone writes Redux today. If you're not using RTK, you're writing too much boilerplate.&lt;br&gt;
bashnpm install @reduxjs/toolkit&lt;br&gt;
createSlice — Replaces actions + reducer&lt;br&gt;
jsimport { createSlice } from '@reduxjs/toolkit';&lt;/p&gt;

&lt;p&gt;const cartSlice = createSlice({&lt;br&gt;
  name: 'cart',&lt;br&gt;
  initialState: { items: [] },&lt;br&gt;
  reducers: {&lt;br&gt;
    addItem: (state, action) =&amp;gt; {&lt;br&gt;
      state.items.push(action.payload); // RTK uses Immer — you CAN mutate here!&lt;br&gt;
    },&lt;br&gt;
    removeItem: (state, action) =&amp;gt; {&lt;br&gt;
      state.items = state.items.filter(i =&amp;gt; i.id !== action.payload);&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;export const { addItem, removeItem } = cartSlice.actions; // Auto-generated action creators&lt;br&gt;
export default cartSlice.reducer;&lt;br&gt;
Big deal: RTK uses Immer internally, so you can write "mutating" code that actually creates a new state. No more ...spread everywhere!&lt;/p&gt;

&lt;p&gt;createAsyncThunk — Async with RTK&lt;br&gt;
jsimport { createAsyncThunk, createSlice } from '@reduxjs/toolkit';&lt;/p&gt;

&lt;p&gt;// Creates the thunk + action types automatically&lt;br&gt;
export const fetchUsers = createAsyncThunk(&lt;br&gt;
  'users/fetchAll', // action type prefix&lt;br&gt;
  async () =&amp;gt; {&lt;br&gt;
    const res = await fetch('/api/users');&lt;br&gt;
    return res.json(); // This becomes action.payload on success&lt;br&gt;
  }&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;const usersSlice = createSlice({&lt;br&gt;
  name: 'users',&lt;br&gt;
  initialState: { data: [], loading: false, error: null },&lt;br&gt;
  reducers: {},&lt;br&gt;
  extraReducers: (builder) =&amp;gt; {&lt;br&gt;
    builder&lt;br&gt;
      .addCase(fetchUsers.pending, (state) =&amp;gt; { state.loading = true; })&lt;br&gt;
      .addCase(fetchUsers.fulfilled, (state, action) =&amp;gt; {&lt;br&gt;
        state.loading = false;&lt;br&gt;
        state.data = action.payload;&lt;br&gt;
      })&lt;br&gt;
      .addCase(fetchUsers.rejected, (state, action) =&amp;gt; {&lt;br&gt;
        state.loading = false;&lt;br&gt;
        state.error = action.error.message;&lt;br&gt;
      });&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;configureStore — Store setup&lt;br&gt;
jsimport { configureStore } from '@reduxjs/toolkit';&lt;/p&gt;

&lt;p&gt;const store = configureStore({&lt;br&gt;
  reducer: {&lt;br&gt;
    cart: cartReducer,&lt;br&gt;
    users: usersReducer,&lt;br&gt;
  },&lt;br&gt;
  // RTK includes thunk middleware by default!&lt;br&gt;
  // Redux DevTools Extension enabled by default!&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;🔄 Complete Data Flow (Say This in Interviews)&lt;br&gt;
User clicks button&lt;br&gt;
    ↓&lt;br&gt;
Component calls dispatch(action)&lt;br&gt;
    ↓&lt;br&gt;
Middleware intercepts (Thunk runs async, then dispatches again)&lt;br&gt;
    ↓&lt;br&gt;
Reducer receives (currentState, action) → returns newState&lt;br&gt;
    ↓&lt;br&gt;
Store saves newState&lt;br&gt;
    ↓&lt;br&gt;
useSelector detects change → component re-renders&lt;/p&gt;

&lt;p&gt;💡 Key Interview Answers&lt;br&gt;
"Why Redux over Context API?"&lt;/p&gt;

&lt;p&gt;Context re-renders ALL consumers when value changes. Redux is optimized — useSelector only re-renders when the specific piece of state changes. Also, Redux has DevTools, middleware support, and better structure for large apps.&lt;/p&gt;

&lt;p&gt;"What is a pure function?"&lt;/p&gt;

&lt;p&gt;A function that always returns the same output for the same input, and has no side effects (no API calls, no state mutation, no console logs).&lt;/p&gt;

&lt;p&gt;"Can you have multiple reducers?"&lt;/p&gt;

&lt;p&gt;Yes! Use combineReducers (or RTK's configureStore with a reducer object). Each reducer manages its own slice of state. They're combined into one root reducer.&lt;/p&gt;

&lt;p&gt;"What is the Redux DevTools?"&lt;/p&gt;

&lt;p&gt;A browser extension that lets you inspect every action dispatched, see the state before and after, and even time-travel debug — replay actions to reproduce bugs.&lt;/p&gt;

&lt;p&gt;🗺️ Quick Mental Map&lt;br&gt;
Redux = Store + Actions + Reducers&lt;br&gt;
React-Redux = Provider + useSelector + useDispatch&lt;br&gt;
Async = Thunk (simple) or Saga (complex)&lt;br&gt;
Modern = Redux Toolkit (RTK) — use this always&lt;br&gt;
Go through these concepts once more out loud and you'll walk into that interview owning the Redux topic. 💪&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>𝗦𝗲𝗰𝘂𝗿𝗲 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗖𝗵𝗲𝗰𝗸𝗹𝗶𝘀𝘁</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Tue, 31 Mar 2026 05:38:24 +0000</pubDate>
      <link>https://forem.com/kiransm/-3lhi</link>
      <guid>https://forem.com/kiransm/-3lhi</guid>
      <description>&lt;p&gt;🔐 𝗦𝗲𝗰𝘂𝗿𝗲 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗖𝗵𝗲𝗰𝗸𝗹𝗶𝘀𝘁 — Every Developer Should Follow&lt;/p&gt;

&lt;p&gt;Frontend security is often ignored…&lt;br&gt;
until something breaks in production 🚨&lt;/p&gt;

&lt;p&gt;Here’s a practical checklist every frontend dev should know 👇&lt;/p&gt;

&lt;p&gt;🧠 1️⃣ 𝗣𝗿𝗼𝘁𝗲𝗰𝘁 𝗔𝗴𝗮𝗶𝗻𝘀𝘁 𝗫𝗦𝗦&lt;br&gt;
👉 Never trust user input&lt;br&gt;
✔ Escape/sanitize inputs&lt;br&gt;
✔ Avoid dangerouslySetInnerHTML in React&lt;br&gt;
✔ Use Content Security Policy (CSP)&lt;/p&gt;

&lt;p&gt;🧠 2️⃣ 𝗦𝗲𝗰𝘂𝗿𝗲 𝗧𝗼𝗸𝗲𝗻 𝗦𝘁𝗼𝗿𝗮𝗴𝗲&lt;br&gt;
👉 Don’t expose tokens to JavaScript&lt;br&gt;
✔ Use httpOnly cookies for refresh tokens&lt;br&gt;
✔ Avoid storing sensitive data in localStorage&lt;br&gt;
✔ Use short-lived access tokens&lt;/p&gt;

&lt;p&gt;🧠 3️⃣ 𝗘𝗻𝗮𝗯𝗹𝗲 𝗛𝗧𝗧𝗣𝗦 𝗘𝘃𝗲𝗿𝘆𝘄𝗵𝗲𝗿𝗲&lt;br&gt;
👉 No exceptions&lt;br&gt;
✔ Prevent data interception&lt;br&gt;
✔ Required for secure cookies&lt;/p&gt;

&lt;p&gt;🧠 4️⃣ 𝗛𝗮𝗻𝗱𝗹𝗲 𝗖𝗢𝗥𝗦 𝗣𝗿𝗼𝗽𝗲𝗿𝗹𝘆&lt;br&gt;
👉 Don’t allow everything&lt;br&gt;
❌ Access-Control-Allow-Origin: * (dangerous in prod)&lt;br&gt;
✔ Restrict to trusted domains&lt;/p&gt;

&lt;p&gt;🧠 5️⃣ 𝗖𝗦𝗥𝗙 𝗣𝗿𝗼𝘁𝗲𝗰𝘁𝗶𝗼𝗻&lt;br&gt;
👉 Prevent unwanted actions&lt;br&gt;
✔ Use CSRF tokens&lt;br&gt;
✔ Use SameSite cookies&lt;/p&gt;

&lt;p&gt;🧠 6️⃣ 𝗔𝘃𝗼𝗶𝗱 𝗦𝗲𝗻𝘀𝗶𝘁𝗶𝘃𝗲 𝗗𝗮𝘁𝗮 𝗘𝘅𝗽𝗼𝘀𝘂𝗿𝗲&lt;br&gt;
👉 Frontend is public&lt;br&gt;
❌ Don’t store:&lt;br&gt;
  • API secrets&lt;br&gt;
  • Private keys&lt;br&gt;
  • Sensitive configs&lt;br&gt;
✔ Use environment variables properly&lt;/p&gt;

&lt;p&gt;🧠 7️⃣ 𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗲 𝗼𝗻 𝗕𝗼𝘁𝗵 𝗦𝗶𝗱𝗲𝘀&lt;br&gt;
👉 Frontend validation is NOT enough&lt;br&gt;
✔ Always validate on backend&lt;br&gt;
✔ Frontend is just UX layer&lt;/p&gt;

&lt;p&gt;🧠 8️⃣ 𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆&lt;br&gt;
👉 Your app is only as secure as your dependencies&lt;br&gt;
✔ Keep packages updated&lt;br&gt;
✔ Use npm audit&lt;br&gt;
✔ Avoid unknown libraries&lt;/p&gt;

&lt;p&gt;🧠 9️⃣ 𝗣𝗿𝗲𝘃𝗲𝗻𝘁 𝗖𝗹𝗶𝗰𝗸𝗷𝗮𝗰𝗸𝗶𝗻𝗴&lt;br&gt;
👉 Protect UI from being embedded&lt;br&gt;
✔ Use headers:&lt;br&gt;
X-Frame-Options: DENY&lt;/p&gt;

&lt;p&gt;🧠 🔟 𝗘𝗿𝗿𝗼𝗿 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴&lt;br&gt;
👉 Don’t leak internal details&lt;br&gt;
❌ Stack traces in UI&lt;br&gt;
✔ Show user-friendly messages&lt;/p&gt;

&lt;p&gt;💡 𝗦𝗲𝗻𝗶𝗼𝗿-𝗟𝗲𝘃𝗲𝗹 𝗜𝗻𝘀𝗶𝗴𝗵𝘁&lt;br&gt;
"Security is not a feature. It’s a layered system"&lt;/p&gt;

&lt;p&gt;Real apps combine:&lt;br&gt;
  • Auth (JWT / Sessions)&lt;br&gt;
  • CSP + CORS&lt;br&gt;
  • Input sanitization&lt;br&gt;
  • Secure cookies&lt;/p&gt;

&lt;p&gt;🎯 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗢𝗻𝗲-𝗟𝗶𝗻𝗲𝗿&lt;/p&gt;

&lt;p&gt;Frontend security involves protecting against XSS, securing tokens, enforcing HTTPS, validating inputs, and ensuring safe communication with the backend.&lt;/p&gt;

&lt;h1&gt;
  
  
  LearnToCode #CodingTips #DeveloperLife #TechCareers #SoftwareEngineering #InterviewPrep #TechInterview #CareerGrowth #CodingJourney #Developers
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>How to Start Contributing to Open Source (Frontend Developer Guide)</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:20:51 +0000</pubDate>
      <link>https://forem.com/kiransm/how-to-start-contributing-to-open-source-frontend-developer-guide-1dpd</link>
      <guid>https://forem.com/kiransm/how-to-start-contributing-to-open-source-frontend-developer-guide-1dpd</guid>
      <description>&lt;p&gt;Most frontend developers want to contribute to open source…&lt;/p&gt;

&lt;p&gt;But they get stuck at one question:&lt;br&gt;
&lt;strong&gt;“Where do I even start?”&lt;/strong&gt; 🤔&lt;/p&gt;

&lt;p&gt;Here’s a practical, no-fluff roadmap to get started 👇&lt;/p&gt;




&lt;p&gt;🚀 &lt;strong&gt;How to Start Contributing to Open Source (Frontend Developer Guide)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔎 &lt;strong&gt;1. Where to Find Open Source Projects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with these platforms:&lt;/p&gt;

&lt;p&gt;• GitHub (main hub)&lt;br&gt;
Search using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;good first issue&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;frontend&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;react&lt;/code&gt;, &lt;code&gt;vite&lt;/code&gt;, &lt;code&gt;nextjs&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;is:issue is:open label:"good first issue" react&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;label:"help wanted" frontend&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;• First Timers Only – beginner-friendly issues with guidance&lt;br&gt;
• Up For Grabs – curated list of projects&lt;br&gt;
• CodeTriage – get issues in your inbox daily&lt;br&gt;
• Awesome for Beginners – handpicked beginner repos&lt;/p&gt;

&lt;p&gt;💡 Also explore real-world frontend ecosystems like React-based libraries, UI frameworks, and tooling projects.&lt;/p&gt;




&lt;p&gt;🛠️ &lt;strong&gt;2. How to Start Contributing (Step-by-step)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Pick the right project&lt;br&gt;
Look for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Active commits&lt;/li&gt;
&lt;li&gt;Clear documentation&lt;/li&gt;
&lt;li&gt;Labels like &lt;code&gt;good first issue&lt;/code&gt;, &lt;code&gt;beginner friendly&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Understand the codebase&lt;br&gt;
Focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Component structure&lt;/li&gt;
&lt;li&gt;State management&lt;/li&gt;
&lt;li&gt;API handling&lt;/li&gt;
&lt;li&gt;Styling approach&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Start SMALL&lt;br&gt;
Avoid complex features initially. Instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fix UI bugs 🐛&lt;/li&gt;
&lt;li&gt;Improve responsiveness 📱&lt;/li&gt;
&lt;li&gt;Add loading states ⏳&lt;/li&gt;
&lt;li&gt;Fix UI text/typos 📝&lt;/li&gt;
&lt;li&gt;Improve accessibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Workflow&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fork → Clone → Create branch&lt;/li&gt;
&lt;li&gt;Make changes → Commit&lt;/li&gt;
&lt;li&gt;Create PR with clear explanation&lt;/li&gt;
&lt;li&gt;Add screenshots (before/after)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Handle reviews&lt;br&gt;
Feedback from maintainers = real learning 🔥&lt;/p&gt;




&lt;p&gt;🔥 &lt;strong&gt;3. What Should You Contribute?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have experience, don’t limit yourself to beginner tasks.&lt;/p&gt;

&lt;p&gt;💡 Intermediate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Refactor components&lt;/li&gt;
&lt;li&gt;Optimize re-renders&lt;/li&gt;
&lt;li&gt;Improve state logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Advanced:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build features&lt;/li&gt;
&lt;li&gt;Improve accessibility (high impact!)&lt;/li&gt;
&lt;li&gt;Performance optimization&lt;/li&gt;
&lt;li&gt;Create reusable components&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🎯 &lt;strong&gt;4. Smart Strategy (Most People Miss This)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t jump between random repos.&lt;/p&gt;

&lt;p&gt;👉 Pick 1–2 projects and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contribute consistently&lt;/li&gt;
&lt;li&gt;Build relationships with maintainers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to:&lt;br&gt;
⭐ Recognition&lt;br&gt;
🤝 Networking&lt;br&gt;
💼 Potential job referrals&lt;/p&gt;




&lt;p&gt;⚠️ &lt;strong&gt;Common Mistakes to Avoid&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ Jumping into massive repos too early&lt;br&gt;
❌ Ignoring contribution guidelines&lt;br&gt;
❌ Creating PRs without context&lt;br&gt;
❌ Taking complex issues too soon&lt;/p&gt;




&lt;p&gt;🧠 &lt;strong&gt;Pro Tip&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're strong in React + UI:&lt;/p&gt;

&lt;p&gt;👉 Focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;UI libraries (buttons, modals, forms)&lt;/li&gt;
&lt;li&gt;Admin dashboards&lt;/li&gt;
&lt;li&gt;Developer tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are:&lt;br&gt;
✔ Easier to contribute to&lt;br&gt;
✔ Highly visible&lt;br&gt;
✔ Great for showcasing in interviews&lt;/p&gt;




&lt;p&gt;📌 &lt;strong&gt;What Recruiters Actually Look For&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When they check your GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clean, meaningful commits&lt;/li&gt;
&lt;li&gt;Well-explained PRs&lt;/li&gt;
&lt;li&gt;Real contributions (not just side projects)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Start small. Stay consistent. Build in public.&lt;/p&gt;

&lt;p&gt;That’s how open source starts working &lt;em&gt;for you&lt;/em&gt; 🚀&lt;/p&gt;




&lt;p&gt;💬 Are you contributing to open source yet, or still planning to start?&lt;/p&gt;

&lt;h1&gt;
  
  
  OpenSource #FrontendDevelopment #ReactJS #JavaScript #GitHub #GoodFirstIssue #BuildInPublic #SoftwareEngineering #TechCareers #FrontendDev #Programming
&lt;/h1&gt;

</description>
      <category>beginners</category>
      <category>frontend</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Still using npm for everything? Time to level up your JavaScript game 🚀</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Tue, 24 Jun 2025 01:23:00 +0000</pubDate>
      <link>https://forem.com/kiransm/still-using-npm-for-everything-time-to-level-up-your-javascript-game-f84</link>
      <guid>https://forem.com/kiransm/still-using-npm-for-everything-time-to-level-up-your-javascript-game-f84</guid>
      <description>&lt;p&gt;The JS ecosystem has evolved MASSIVELY. Here's your 2025 cheat sheet:&lt;br&gt;
📦 PACKAGE MANAGERS&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npm&lt;/strong&gt; - The reliable classic&lt;br&gt;
✅ Comes with Node.js (zero setup)&lt;br&gt;
✅ Massive ecosystem, battle-tested&lt;br&gt;
❌ Slower installs, bloated node_modules&lt;br&gt;
Best for: Teams wanting stability over speed&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yarn&lt;/strong&gt; - The Meta powerhouse&lt;br&gt;
✅ Lightning-fast installs + smart caching&lt;br&gt;
✅ Plug'n'Play mode = no node_modules chaos&lt;br&gt;
❌ Yarn 2+ syntax changes might trip you up&lt;br&gt;
Best for: Speed-obsessed teams with CI/CD focus&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pnpm&lt;/strong&gt; - The efficiency king&lt;br&gt;
✅ Fastest traditional manager + saves 70% disk space&lt;br&gt;
✅ Symlinks = one global store, multiple projects&lt;br&gt;
❌ Still the "new kid" (but growing fast)&lt;br&gt;
Best for: Monorepos and storage-conscious devs&lt;/p&gt;

&lt;p&gt;⚙️ &lt;strong&gt;&lt;em&gt;GAME-CHANGING RUNTIMES&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bun&lt;/strong&gt; - The Swiss Army knife&lt;br&gt;
✅ Package manager + test runner + bundler in ONE tool&lt;br&gt;
✅ Written in Zig = insanely fast&lt;br&gt;
❌ Still maturing (some compatibility gaps)&lt;br&gt;
Best for: Early adopters who want everything&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deno&lt;/strong&gt; - The security-first rebel&lt;br&gt;
✅ Created by Node's original author to "fix" Node.js&lt;br&gt;
✅ Secure by default + built-in formatter/linter/tests&lt;br&gt;
❌ Smaller ecosystem (but growing)&lt;br&gt;
Best for: Security-conscious teams building modern apps&lt;/p&gt;

&lt;p&gt;🎯 &lt;strong&gt;MY HONEST TAKE:&lt;/strong&gt;&lt;br&gt;
→ Switching from npm? Try pnpm first (easiest migration)&lt;br&gt;
→ Starting fresh? Consider Bun for greenfield projects&lt;br&gt;
→ Enterprise team? Stick with npm/Yarn until Bun/Deno mature&lt;br&gt;
→ Security-critical app? Deno is worth the learning curve&lt;br&gt;
The real question isn't "which is best?" — it's "which solves YOUR biggest pain point?"&lt;/p&gt;

&lt;p&gt;What's your current setup? Drop your stack in the comments!&lt;br&gt;
I'm especially curious:&lt;/p&gt;

&lt;p&gt;Who's tried Bun in production?&lt;br&gt;
Any pnpm converts here?&lt;br&gt;
Deno success stories?&lt;/p&gt;

&lt;p&gt;Let's share war stories! 👇&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript #WebDevelopment #NodeJS #Bun #Deno #pnpm #Yarn #npm #DeveloperTools #Programming #TechStack #SoftwareDevelopment #WebDev #Frontend #Backend
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>npm</category>
      <category>bunjs</category>
    </item>
    <item>
      <title>HTML - 5 API's</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Tue, 18 Jun 2024 03:39:50 +0000</pubDate>
      <link>https://forem.com/kiransm/html5-apis-1dbb</link>
      <guid>https://forem.com/kiransm/html5-apis-1dbb</guid>
      <description>&lt;p&gt;HTML5 introduced several new APIs (Application Programming Interfaces) that extend the capabilities of web browsers, enabling developers to create richer and more interactive web applications without relying on third-party plugins like Flash or Java. Here are some key HTML5 APIs:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Canvas API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Provides a way to draw graphics, animations, and other visualizations on the fly using JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Creating games, data visualizations, image manipulation, and interactive animations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Web Audio API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Enables web applications to process and synthesize audio in real-time using JavaScript. It provides a powerful set of tools for audio processing and manipulation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Building audio players, creating music applications, implementing audio effects, and generating soundscapes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Web Storage API (localStorage and sessionStorage)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Allows web applications to store data locally on the user's device. &lt;code&gt;localStorage&lt;/code&gt; stores data persistently, while &lt;code&gt;sessionStorage&lt;/code&gt; stores data for the duration of a session.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Storing user preferences, caching data for offline use, implementing shopping carts, and saving form data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Web Workers API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Enables multi-threaded JavaScript execution in web applications by running scripts in the background without blocking the UI thread.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Performing CPU-intensive tasks, such as data processing, image manipulation, and calculations, without affecting the responsiveness of the user interface.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. WebSockets API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Provides a full-duplex communication channel over a single, long-lived connection between a client and a server, enabling real-time bidirectional communication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Building real-time chat applications, multiplayer games, collaborative editing tools, and live data streaming applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. Geolocation API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Allows web applications to access the device's geographical location information (latitude and longitude) using GPS, Wi-Fi, or cellular data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Implementing location-based services, mapping applications, weather forecasts, and local search functionality.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. Drag and Drop API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Provides support for dragging and dropping elements within a web page or between different applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Creating drag-and-drop interfaces, file upload widgets, and interactive user interfaces.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. WebRTC API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Enables real-time communication (voice, video, and data) directly between web browsers without the need for plugins or third-party software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Building video conferencing applications, peer-to-peer file sharing, screen sharing, and online gaming platforms.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. IndexedDB API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: A low-level API for client-side storage of large amounts of structured data, providing a way to store and retrieve data locally using JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Implementing offline web applications, managing large datasets, and caching frequently accessed data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  10. FileReader API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Description&lt;/strong&gt;: Allows web applications to read the contents of files (e.g., images, text files, audio files) selected by the user using file input elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;: Uploading files asynchronously, processing files locally before uploading, and building file management applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few examples of the many HTML5 APIs available to web developers. Each API provides unique functionality that can enhance the user experience and enable the creation of sophisticated web applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Implementing Role-Based Access Control (RBAC) In modern web applications</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Mon, 17 Jun 2024 09:14:14 +0000</pubDate>
      <link>https://forem.com/kiransm/implementing-role-based-access-control-rbacin-modern-web-applications-5525</link>
      <guid>https://forem.com/kiransm/implementing-role-based-access-control-rbacin-modern-web-applications-5525</guid>
      <description>&lt;p&gt;&lt;strong&gt;Enhancing Security in ReactJS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implementing Role-Based Access Control (RBAC)&lt;br&gt;
In modern web applications, ensuring that users have access only to the modules they are permitted to see is crucial for both security and user experience. Here's a simple way to implement RBAC in your ReactJS application:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-Step Guide:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Define Roles and Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a configuration file (roles.js).&lt;/li&gt;
&lt;li&gt;Define roles (e.g., admin, user) and their permissions (e.g., dashboard access, settings access).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2 . &lt;strong&gt;Create Authentication Context&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a context (e.g., AuthContext.js).&lt;/li&gt;
&lt;li&gt;Set up a context (AuthContext.js) to manage and provide user authentication state and role information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3 . &lt;strong&gt;Create a Higher-Order Component (HOC) for Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a HOC (e.g., withAuthorization.js).&lt;/li&gt;
&lt;li&gt;This HOC will check if the user has the required permission and render the component or show an error message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4 . &lt;strong&gt;Protect Components with HOC&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wrap protected components (e.g., Dashboard.js, Settings.js) with the HOC.&lt;/li&gt;
&lt;li&gt;Pass the required permission to the HOC for each component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5 . &lt;strong&gt;Wrap the Application with AuthProvider&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your main application file (e.g., App.js), wrap the application with the AuthProvider.&lt;/li&gt;
&lt;li&gt;This will ensure the authentication context is available throughout the app.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;code&gt;// roles.js&lt;br&gt;
export const Roles = { ADMIN: 'admin', USER: 'user' };&lt;br&gt;
export const Permissions = { DASHBOARD: 'dashboard', SETTINGS: 'settings' };&lt;br&gt;
export const RolePermissions = { [Roles.ADMIN]: [Permissions.DASHBOARD, Permissions.SETTINGS], [Roles.USER]: [Permissions.DASHBOARD] };&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// AuthContext.js&lt;br&gt;
import React, { createContext, useContext, useState } from 'react';&lt;br&gt;
const AuthContext = createContext();&lt;br&gt;
export const AuthProvider = ({ children }) =&amp;gt; { const [user, setUser] = useState({ role: 'user' }); return (&amp;lt;AuthContext.Provider value={{ user, setUser }}&amp;gt;{children}&amp;lt;/AuthContext.Provider&amp;gt;); };&lt;br&gt;
export const useAuth = () =&amp;gt; useContext(AuthContext);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// withAuthorization.js&lt;br&gt;
import React from 'react'; import { useAuth } from './AuthContext'; import { RolePermissions } from './roles';&lt;br&gt;
const withAuthorization = (WrappedComponent, requiredPermission) =&amp;gt; { return (props) =&amp;gt; { const { user } = useAuth(); const userPermissions = RolePermissions[user.role]; if (userPermissions.includes(requiredPermission)) { return &amp;lt;WrappedComponent {...props} /&amp;gt;; } else { return &amp;lt;div&amp;gt;You do not have permission to view this page.&amp;lt;/div&amp;gt;; } }; };&lt;br&gt;
export default withAuthorization;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// App.js&lt;br&gt;
import React from 'react'; import { AuthProvider } from './AuthContext'; import Dashboard from './Dashboard'; import Settings from './Settings';&lt;br&gt;
function App() { return (&amp;lt;AuthProvider&amp;gt;&amp;lt;div className="App"&amp;gt;&amp;lt;Dashboard /&amp;gt;&amp;lt;Settings /&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/AuthProvider&amp;gt;); }&lt;br&gt;
export default App;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can enhance your application's security by restricting module access based on user roles. By Steps🚀🔒&lt;/p&gt;

&lt;h1&gt;
  
  
  Authorization #RBAC  #reactjs  #nextjs  #softwaredevelopment  #javascript  #HOC  #security
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Types of Scopes in javascript</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Sat, 15 Jun 2024 14:36:32 +0000</pubDate>
      <link>https://forem.com/kiransm/types-of-scopes-in-javascript-4lm3</link>
      <guid>https://forem.com/kiransm/types-of-scopes-in-javascript-4lm3</guid>
      <description>&lt;p&gt;In JavaScript, scope determines the accessibility or visibility of variables and functions at various parts of the code during execution. Understanding the different types of scopes in JavaScript is crucial for writing efficient and error-free code. Here are the primary types of scopes in JavaScript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Global Scope&lt;/strong&gt;
Definition: Variables declared outside any function or block have global scope, meaning they are accessible from anywhere in the code.
Creation: Variables become global if they are declared with var outside any function or if they are not declared with let, const, or var inside a function (implicitly global).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`var globalVar = 'I am a global variable';&lt;/p&gt;

&lt;p&gt;function displayGlobalVar() {&lt;br&gt;
    console.log(globalVar); // Accessible here&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;displayGlobalVar();&lt;br&gt;
console.log(globalVar); // Accessible here too&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Local Scope (Function Scope)&lt;/strong&gt;
Definition: Variables declared within a function are in the local scope (or function scope). They are only accessible within that function.
Creation: Any variable declared inside a function using var, let, or const.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`function myFunction() {&lt;br&gt;
    var localVar = 'I am a local variable';&lt;br&gt;
    console.log(localVar); // Accessible here&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;myFunction();&lt;br&gt;
console.log(localVar); // Uncaught ReferenceError: localVar is not defined&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Block Scope&lt;/strong&gt;
Definition: Variables declared within a block (denoted by {}) are only accessible within that block. This type of scope was introduced with ES6 and applies to variables declared using let and const.
Creation: Any variable declared inside a block using let or const.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`{&lt;br&gt;
    let blockVar = 'I am a block-scoped variable';&lt;br&gt;
    const blockConst = 'I am also block-scoped';&lt;br&gt;
    console.log(blockVar); // Accessible here&lt;br&gt;
    console.log(blockConst); // Accessible here&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;console.log(blockVar); // Uncaught ReferenceError: blockVar is not defined&lt;br&gt;
console.log(blockConst); // Uncaught ReferenceError: blockConst is not defined&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Lexical Scope (Static Scope)&lt;/strong&gt;
Definition: Lexical scope means that the accessibility of variables is determined by their physical location in the code at the time of writing. Inner functions have access to variables defined in outer functions.
Creation: Automatically created based on where functions are declared.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`function outerFunction() {&lt;br&gt;
    var outerVar = 'I am an outer variable';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function innerFunction() {
    console.log(outerVar); // Accessible due to lexical scope
}

innerFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;outerFunction();&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Module Scope&lt;/strong&gt;
Definition: Variables declared within a module (using the ES6 module system) are scoped to that module. They are not accessible outside the module unless explicitly exported.
Creation: Using import and export statements in ES6 modules.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`// module1.js&lt;br&gt;
export const moduleVar = 'I am a module-scoped variable';&lt;/p&gt;

&lt;p&gt;// main.js&lt;br&gt;
import { moduleVar } from './module1.js';&lt;br&gt;
console.log(moduleVar); // Accessible here&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope Chain&lt;/strong&gt;&lt;br&gt;
The scope chain is a hierarchical structure that determines the order in which scopes are looked up to resolve variable names. When a variable is referenced, JavaScript starts looking in the current scope, then moves up to the outer scope, and continues this process until it reaches the global scope.&lt;/p&gt;

&lt;p&gt;`var globalVar = 'I am global';&lt;/p&gt;

&lt;p&gt;function outerFunction() {&lt;br&gt;
    var outerVar = 'I am outer';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function innerFunction() {
    var innerVar = 'I am inner';
    console.log(innerVar); // Found in inner scope
    console.log(outerVar); // Found in outer scope
    console.log(globalVar); // Found in global scope
}

innerFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;outerFunction();&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures&lt;/strong&gt;&lt;br&gt;
Closures are functions that remember their lexical scope even when they are executed outside of that scope. This allows inner functions to access variables from their outer function scope even after the outer function has returned.&lt;/p&gt;

&lt;p&gt;`function outerFunction() {&lt;br&gt;
    var outerVar = 'I am outer';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function innerFunction() {
    console.log(outerVar);
}

return innerFunction;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;const closureFunction = outerFunction();&lt;br&gt;
closureFunction(); // 'I am outer' - outerVar is still accessible&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
Understanding these different types of scopes and their behavior is essential for managing variable accessibility and preventing issues like variable shadowing and unintentional global variable creation. It also helps in writing clean, maintainable, and error-free JavaScript code.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: 𝟤/𝟔 - 𝐑𝐞𝐯𝐞𝐚𝐥𝐢𝐧𝐠 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Tue, 11 Jun 2024 04:28:08 +0000</pubDate>
      <link>https://forem.com/kiransm/--5bf0</link>
      <guid>https://forem.com/kiransm/--5bf0</guid>
      <description>&lt;p&gt;𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: 𝟤/𝟔 - 𝐑𝐞𝐯𝐞𝐚𝐥𝐢𝐧𝐠 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧&lt;/p&gt;

&lt;p&gt;𝖤𝗏𝖾𝗋 𝗐𝗈𝗇𝖽𝖾𝗋𝖾𝖽 𝗁𝗈𝗐 𝗍𝗈 𝖾𝗇𝖼𝖺𝗉𝗌𝗎𝗅𝖺𝗍𝖾 𝗒𝗈𝗎𝗋 𝖩𝖺𝗏𝖺𝖲𝖼𝗋𝗂𝗉𝗍 𝖼𝗈𝖽𝖾 𝖾𝖿𝖿𝗂𝖼𝗂𝖾𝗇𝗍𝗅𝗒 𝗐𝗁𝗂𝗅𝖾 𝗄𝖾𝖾𝗉𝗂𝗇𝗀 𝗂𝗍 𝖼𝗅𝖾𝖺𝗇 𝖺𝗇𝖽 𝗋𝖾𝖺𝖽𝖺𝖻𝗅𝖾? 𝖳𝗁𝖾 𝖱𝖾𝗏𝖾𝖺𝗅𝗂𝗇𝗀 𝖬𝗈𝖽𝗎𝗅𝖾 𝖯𝖺𝗍𝗍𝖾𝗋𝗇 𝗆𝗂𝗀𝗁𝗍 𝖻𝖾 𝗒𝗈𝗎𝗋 𝖺𝗇𝗌𝗐𝖾𝗋!&lt;/p&gt;

&lt;p&gt;𝖳𝗁𝗂𝗌 𝗏𝖺𝗋𝗂𝖺𝗍𝗂𝗈𝗇 𝗈𝖿 𝗍𝗁𝖾 𝗆𝗈𝖽𝗎𝗅𝖾 𝗉𝖺𝗍𝗍𝖾𝗋𝗇 𝗇𝗈𝗍 𝗈𝗇𝗅𝗒 𝖾𝗇𝖼𝖺𝗉𝗌𝗎𝗅𝖺𝗍𝖾𝗌 𝗒𝗈𝗎𝗋 𝖼𝗈𝖽𝖾 𝖻𝗎𝗍 𝖺𝗅𝗌𝗈 𝗆𝖺𝗄𝖾𝗌 𝗂𝗍 𝗆𝗈𝗋𝖾 𝗂𝗇𝗍𝗎𝗂𝗍𝗂𝗏𝖾 𝖻𝗒 𝖽𝖾𝖿𝗂𝗇𝗂𝗇𝗀 𝖺𝗅𝗅 𝗏𝖺𝗋𝗂𝖺𝖻𝗅𝖾𝗌 𝖺𝗇𝖽 𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇𝗌 𝗂𝗇 𝖺 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝗌𝖼𝗈𝗉𝖾 𝖺𝗇𝖽 𝗍𝗁𝖾𝗇 "𝗋𝖾𝗏𝖾𝖺𝗅𝗂𝗇𝗀" 𝖺𝗇 𝗈𝖻𝗃𝖾𝖼𝗍 𝗐𝗂𝗍𝗁 𝗉𝗈𝗂𝗇𝗍𝖾𝗋𝗌 𝗍𝗈 𝗍𝗁𝖾 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝗆𝖾𝗍𝗁𝗈𝖽𝗌. 𝖧𝖾𝗋𝖾'𝗌 𝖺 𝗊𝗎𝗂𝖼𝗄 𝗅𝗈𝗈𝗄 𝖺𝗍 𝗁𝗈𝗐 𝗂𝗍 𝗐𝗈𝗋𝗄𝗌:&lt;/p&gt;

&lt;p&gt;`𝖼𝗈𝗇𝗌𝗍 𝗋𝖾𝗏𝖾𝖺𝗅𝗂𝗇𝗀𝖬𝗈𝖽𝗎𝗅𝖾 = (𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇() {&lt;br&gt;
𝖼𝗈𝗇𝗌𝗍 𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖵𝖺𝗋 = '𝖨 𝖺𝗆 𝗉𝗋𝗂𝗏𝖺𝗍𝖾';&lt;br&gt;
𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇 𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇() {&lt;br&gt;
   𝖼𝗈𝗇𝗌𝗈𝗅𝖾.𝗅𝗈𝗀(𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖵𝖺𝗋);&lt;br&gt;
 }&lt;/p&gt;

&lt;p&gt;𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇 𝗉𝗎𝖻𝗅𝗂𝖼𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇() {&lt;br&gt;
  𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇();&lt;br&gt;
 }&lt;br&gt;
𝗋𝖾𝗍𝗎𝗋𝗇 {&lt;br&gt;
  𝗉𝗎𝖻𝗅𝗂𝖼𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇: 𝗉𝗎𝖻𝗅𝗂𝖼𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇&lt;br&gt;
 };&lt;br&gt;
})();&lt;br&gt;
𝗋𝖾𝗏𝖾𝖺𝗅𝗂𝗇𝗀𝖬𝗈𝖽𝗎𝗅𝖾.𝗉𝗎𝖻𝗅𝗂𝖼𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇(); // 𝖮𝗎𝗍𝗉𝗎𝗍: 𝖨 𝖺𝗆 𝗉𝗋𝗂𝗏𝖺𝗍𝖾`&lt;/p&gt;

&lt;p&gt;𝐖𝐡𝐲 𝐬𝐡𝐨𝐮𝐥𝐝 𝐲𝐨𝐮 𝐜𝐨𝐧𝐬𝐢𝐝𝐞𝐫 𝐮𝐬𝐢𝐧𝐠 𝐭𝐡𝐞 𝐑𝐞𝐯𝐞𝐚𝐥𝐢𝐧𝐠 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧?&lt;/p&gt;

&lt;p&gt;𝐈𝐦𝐩𝐫𝐨𝐯𝐞𝐝 𝐑𝐞𝐚𝐝𝐚𝐛𝐢𝐥𝐢𝐭𝐲: 𝖢𝗅𝖾𝖺𝗋𝗅𝗒 𝗌𝖾𝗉𝖺𝗋𝖺𝗍𝖾𝗌 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝖺𝗇𝖽 𝗉𝗎𝖻𝗅𝗂𝖼 𝗉𝖺𝗋𝗍𝗌 𝗈𝖿 𝗒𝗈𝗎𝗋 𝖼𝗈𝖽𝖾.&lt;br&gt;
𝐄𝐧𝐜𝐚𝐩𝐬𝐮𝐥𝐚𝐭𝐢𝐨𝐧: 𝖪𝖾𝖾𝗉𝗌 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝗏𝖺𝗋𝗂𝖺𝖻𝗅𝖾𝗌 𝗍𝗋𝗎𝗅𝗒 𝗉𝗋𝗂𝗏𝖺𝗍𝖾, 𝗉𝗋𝖾𝗏𝖾𝗇𝗍𝗂𝗇𝗀 𝖾𝗑𝗍𝖾𝗋𝗇𝖺𝗅 𝖺𝖼𝖼𝖾𝗌𝗌.&lt;br&gt;
𝐂𝐥𝐞𝐚𝐧𝐞𝐫 𝐂𝐨𝐝𝐞: 𝖱𝖾𝖽𝗎𝖼𝖾𝗌 𝖼𝗅𝗎𝗍𝗍𝖾𝗋 𝖻𝗒 𝖾𝗑𝗉𝗈𝗌𝗂𝗇𝗀 𝗈𝗇𝗅𝗒 𝗍𝗁𝖾 𝗇𝖾𝖼𝖾𝗌𝗌𝖺𝗋𝗒 𝗉𝖺𝗋𝗍𝗌 𝗈𝖿 𝗒𝗈𝗎𝗋 𝖼𝗈𝖽𝖾.&lt;/p&gt;

&lt;p&gt;𝖦𝗂𝗏𝖾 𝗂𝗍 𝖺 𝗍𝗋𝗒 𝗂𝗇 𝗒𝗈𝗎𝗋 𝗇𝖾𝗑𝗍 𝗉𝗋𝗈𝗃𝖾𝖼𝗍 𝖺𝗇𝖽 𝗌𝖾𝖾 𝗍𝗁𝖾 𝖽𝗂𝖿𝖿𝖾𝗋𝖾𝗇𝖼𝖾 𝗂𝗍 𝗆𝖺𝗄𝖾𝗌 𝗂𝗇 𝖼𝗈𝖽𝖾 𝗆𝖺𝗂𝗇𝗍𝖺𝗂𝗇𝖺𝖻𝗂𝗅𝗂𝗍𝗒 𝖺𝗇𝖽 𝖼𝗅𝖺𝗋𝗂𝗍𝗒!&lt;/p&gt;

&lt;p&gt;💬 𝖧𝗈𝗐 𝖽𝗈 𝗒𝗈𝗎 𝗆𝖺𝗇𝖺𝗀𝖾 𝖼𝗈𝖽𝖾 𝖾𝗇𝖼𝖺𝗉𝗌𝗎𝗅𝖺𝗍𝗂𝗈𝗇 𝗂𝗇 𝗒𝗈𝗎𝗋 𝖩𝖺𝗏𝖺𝖲𝖼𝗋𝗂𝗉𝗍 𝗉𝗋𝗈𝗃𝖾𝖼𝗍𝗌? 𝖲𝗁𝖺𝗋𝖾 𝗒𝗈𝗎𝗋 𝗍𝗁𝗈𝗎𝗀𝗁𝗍𝗌 𝖺𝗇𝖽 𝖾𝗑𝗉𝖾𝗋𝗂𝖾𝗇𝖼𝖾𝗌 𝖻𝖾𝗅𝗈𝗐!&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript #DesignPatterns #Encapsulation #CodingBestPractices #WebDevelopment
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>designpatterns</category>
      <category>interview</category>
      <category>react</category>
    </item>
    <item>
      <title>𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: 𝟏/𝟔 - 𝐓𝐡𝐞 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Mon, 10 Jun 2024 04:17:23 +0000</pubDate>
      <link>https://forem.com/kiransm/--3ga7</link>
      <guid>https://forem.com/kiransm/--3ga7</guid>
      <description>&lt;p&gt;🎯 𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 𝐃𝐞𝐬𝐢𝐠𝐧 𝐏𝐚𝐭𝐭𝐞𝐫𝐧𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭: 𝟏/𝟔 - 𝐓𝐡𝐞 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧&lt;/p&gt;

&lt;p&gt;𝖨𝗇 𝗈𝗎𝗋 𝖿𝖺𝗌𝗍-𝗉𝖺𝖼𝖾𝖽 𝗍𝖾𝖼𝗁 𝗐𝗈𝗋𝗅𝖽, 𝗐𝗋𝗂𝗍𝗂𝗇𝗀 𝖼𝗅𝖾𝖺𝗇 𝖺𝗇𝖽 𝗆𝖺𝗂𝗇𝗍𝖺𝗂𝗇𝖺𝖻𝗅𝖾 𝖼𝗈𝖽𝖾 𝗂𝗌 𝖾𝗌𝗌𝖾𝗇𝗍𝗂𝖺𝗅. 𝖳𝗁𝖾 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 𝗂𝗇 𝖩𝖺𝗏𝖺𝖲𝖼𝗋𝗂𝗉𝗍 𝗂𝗌 𝖺 𝗉𝗈𝗐𝖾𝗋𝖿𝗎𝗅 𝖽𝖾𝗌𝗂𝗀𝗇 𝗉𝖺𝗍𝗍𝖾𝗋𝗇 𝗍𝗁𝖺𝗍 𝗁𝖾𝗅𝗉𝗌 𝖺𝖼𝗁𝗂𝖾𝗏𝖾 𝗍𝗁𝗂𝗌 𝖻𝗒 𝖾𝗇𝖺𝖻𝗅𝗂𝗇𝗀 𝗉𝗎𝖻𝗅𝗂𝖼 𝖺𝗇𝖽 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝖾𝗇𝖼𝖺𝗉𝗌𝗎𝗅𝖺𝗍𝗂𝗈𝗇 𝗐𝗂𝗍𝗁𝗂𝗇 𝖺 𝗌𝗂𝗇𝗀𝗅𝖾 𝗈𝖻𝗃𝖾𝖼𝗍.&lt;/p&gt;

&lt;p&gt;🚀 𝐖𝐡𝐲 𝐔𝐬𝐞 𝐭𝐡𝐞 𝐌𝐨𝐝𝐮𝐥𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧?&lt;br&gt;
𝟣. 𝐄𝐧𝐜𝐚𝐩𝐬𝐮𝐥𝐚𝐭𝐢𝐨𝐧: 𝖪𝖾𝖾𝗉 𝗉𝖺𝗋𝗍𝗌 𝗈𝖿 𝗒𝗈𝗎𝗋 𝖼𝗈𝖽𝖾 𝗁𝗂𝖽𝖽𝖾𝗇 𝖺𝗇𝖽 𝗉𝗋𝗈𝗍𝖾𝖼𝗍𝖾𝖽.&lt;br&gt;
𝟤. 𝐌𝐚𝐢𝐧𝐭𝐚𝐢𝐧𝐚𝐛𝐢𝐥𝐢𝐭𝐲: 𝖲𝗂𝗆𝗉𝗅𝗂𝖿𝗒 𝖼𝗈𝖽𝖾 𝗆𝖺𝗂𝗇𝗍𝖾𝗇𝖺𝗇𝖼𝖾 𝖻𝗒 𝗈𝗋𝗀𝖺𝗇𝗂𝗓𝗂𝗇𝗀 𝗋𝖾𝗅𝖺𝗍𝖾𝖽 𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇𝗌 𝖺𝗇𝖽 𝗏𝖺𝗋𝗂𝖺𝖻𝗅𝖾𝗌.&lt;br&gt;
𝟥. 𝐍𝐚𝐦𝐞𝐬𝐩𝐚𝐜𝐞 𝐌𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭: 𝖯𝗋𝖾𝗏𝖾𝗇𝗍 𝗀𝗅𝗈𝖻𝖺𝗅 𝗇𝖺𝗆𝖾𝗌𝗉𝖺𝖼𝖾 𝗉𝗈𝗅𝗅𝗎𝗍𝗂𝗈𝗇.&lt;/p&gt;

&lt;p&gt;𝖧𝖾𝗋𝖾'𝗌 𝖺 𝗊𝗎𝗂𝖼𝗄 𝖾𝗑𝖺𝗆𝗉𝗅𝖾 𝗍𝗈 𝗂𝗅𝗅𝗎𝗌𝗍𝗋𝖺𝗍𝖾 𝗍𝗁𝖾 𝖬𝗈𝖽𝗎𝗅𝖾 𝖯𝖺𝗍𝗍𝖾𝗋𝗇 𝗂𝗇 𝖺𝖼𝗍𝗂𝗈𝗇:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;𝖼𝗈𝗇𝗌𝗍 𝗆𝗒𝖬𝗈𝖽𝗎𝗅𝖾 = (𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇() {
 𝖼𝗈𝗇𝗌𝗍 𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖵𝖺𝗋𝗂𝖺𝖻𝗅𝖾 = '𝖨 𝖺𝗆 𝗉𝗋𝗂𝗏𝖺𝗍𝖾';
 𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇 𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖬𝖾𝗍𝗁𝗈𝖽() {
 𝖼𝗈𝗇𝗌𝗈𝗅𝖾.𝗅𝗈𝗀(𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖵𝖺𝗋𝗂𝖺𝖻𝗅𝖾);
 }
𝗋𝖾𝗍𝗎𝗋𝗇 {
 𝗉𝗎𝖻𝗅𝗂𝖼𝖬𝖾𝗍𝗁𝗈𝖽: 𝖿𝗎𝗇𝖼𝗍𝗂𝗈𝗇() {
 𝗉𝗋𝗂𝗏𝖺𝗍𝖾𝖬𝖾𝗍𝗁𝗈𝖽();
 }
 };
})();
𝗆𝗒𝖬𝗈𝖽𝗎𝗅𝖾.𝗉𝗎𝖻𝗅𝗂𝖼𝖬𝖾𝗍𝗁𝗈𝖽(); // 𝖮𝗎𝗍𝗉𝗎𝗍: 𝖨 𝖺𝗆 𝗉𝗋𝗂𝗏𝖺𝗍𝖾
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔍 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲𝐬:&lt;/p&gt;

&lt;p&gt;𝟣. 𝐏𝐫𝐢𝐯𝐚𝐭𝐞 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 𝐚𝐧𝐝 𝐌𝐞𝐭𝐡𝐨𝐝𝐬: 𝖣𝖾𝖿𝗂𝗇𝖾𝖽 𝗂𝗇𝗌𝗂𝖽𝖾 𝗍𝗁𝖾 𝗆𝗈𝖽𝗎𝗅𝖾, 𝗍𝗁𝖾𝗒 𝖺𝗋𝖾 𝗂𝗇𝖺𝖼𝖼𝖾𝗌𝗌𝗂𝖻𝗅𝖾 𝖿𝗋𝗈𝗆 𝗈𝗎𝗍𝗌𝗂𝖽𝖾.&lt;br&gt;
𝟤. 𝐏𝐮𝐛𝐥𝐢𝐜 𝐌𝐞𝐭𝐡𝐨𝐝𝐬: 𝖱𝖾𝗍𝗎𝗋𝗇𝖾𝖽 𝖿𝗋𝗈𝗆 𝗍𝗁𝖾 𝗆𝗈𝖽𝗎𝗅𝖾, 𝖺𝗅𝗅𝗈𝗐𝗂𝗇𝗀 𝖼𝗈𝗇𝗍𝗋𝗈𝗅𝗅𝖾𝖽 𝖺𝖼𝖼𝖾𝗌𝗌 𝗍𝗈 𝗉𝗋𝗂𝗏𝖺𝗍𝖾 𝗆𝖾𝗆𝖻𝖾𝗋𝗌.&lt;/p&gt;

&lt;p&gt;𝖨𝗇𝖼𝗈𝗋𝗉𝗈𝗋𝖺𝗍𝗂𝗇𝗀 𝗍𝗁𝖾 𝖬𝗈𝖽𝗎𝗅𝖾 𝖯𝖺𝗍𝗍𝖾𝗋𝗇 𝗂𝗇𝗍𝗈 𝗒𝗈𝗎𝗋 𝖩𝖺𝗏𝖺𝖲𝖼𝗋𝗂𝗉𝗍 𝗉𝗋𝗈𝗃𝖾𝖼𝗍𝗌 𝖼𝖺𝗇 𝗌𝗂𝗀𝗇𝗂𝖿𝗂𝖼𝖺𝗇𝗍𝗅𝗒 𝖾𝗇𝗁𝖺𝗇𝖼𝖾 𝗒𝗈𝗎𝗋 𝖼𝗈𝖽𝖾'𝗌 𝗌𝗍𝗋𝗎𝖼𝗍𝗎𝗋𝖾 𝖺𝗇𝖽 𝖼𝗅𝖺𝗋𝗂𝗍𝗒.&lt;/p&gt;

&lt;p&gt;🔗 𝖶𝗁𝖺𝗍 𝖽𝖾𝗌𝗂𝗀𝗇 𝗉𝖺𝗍𝗍𝖾𝗋𝗇𝗌 𝗁𝖺𝗏𝖾 𝗒𝗈𝗎 𝖿𝗈𝗎𝗇𝖽 𝗆𝗈𝗌𝗍 𝗎𝗌𝖾𝖿𝗎𝗅 𝗂𝗇 𝗒𝗈𝗎𝗋 𝖩𝖺𝗏𝖺𝖲𝖼𝗋𝗂𝗉𝗍 𝗃𝗈𝗎𝗋𝗇𝖾𝗒? 𝖲𝗁𝖺𝗋𝖾 𝗒𝗈𝗎𝗋 𝖾𝗑𝗉𝖾𝗋𝗂𝖾𝗇𝖼𝖾𝗌 𝖺𝗇𝖽 𝗅𝖾𝗍'𝗌 𝖽𝗂𝗌𝖼𝗎𝗌𝗌! 💬&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Shallow Copy v/s Deep Copy</title>
      <dc:creator>Kiran </dc:creator>
      <pubDate>Mon, 03 Jun 2024 03:54:20 +0000</pubDate>
      <link>https://forem.com/kiransm/shallow-copy-vs-deep-copy-a8l</link>
      <guid>https://forem.com/kiransm/shallow-copy-vs-deep-copy-a8l</guid>
      <description>&lt;p&gt;The main difference between a shallow copy and a deep copy in JavaScript lies in how they handle the copying of nested objects. Here’s a detailed explanation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shallow Copy&lt;/strong&gt;&lt;br&gt;
A shallow copy of an object is a new object that has the same top-level properties as the original object. However, if any of these properties are themselves objects, the shallow copy does not create a new instance of those nested objects. Instead, it copies the references to the original nested objects.&lt;/p&gt;

&lt;p&gt;Characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Top-level properties&lt;/strong&gt;: A shallow copy duplicates the top-level properties of the original object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nested objects&lt;/strong&gt;: Any nested objects or arrays are not duplicated. Instead, their references are copied.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Methods to create a shallow copy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using Object.assign&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const original = { a: 1, b: { c: 2 } };&lt;br&gt;
const shallowCopy = Object.assign({}, original);&lt;br&gt;
shallowCopy.b.c = 3;&lt;br&gt;
console.log(original.b.c); // Output: 3 (reference is shared)&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using the spread operator (...)&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const original = { a: 1, b: { c: 2 } };&lt;br&gt;
const shallowCopy = { ...original };&lt;br&gt;
shallowCopy.b.c = 3;&lt;br&gt;
console.log(original.b.c); // Output: 3 (reference is shared)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deep Copy&lt;/strong&gt;&lt;br&gt;
A deep copy of an object is a new object that is a complete duplicate of the original object, including all nested objects. This means that any changes made to the deep copy do not affect the original object, and vice versa.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Top-level properties&lt;/strong&gt;: A deep copy duplicates the top-level properties of the original object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nested objects&lt;/strong&gt;: Any nested objects or arrays are also duplicated, creating new instances of these objects rather than copying references.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Methods to create a deep copy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using JSON.parse(JSON.stringify(obj)) (simple cases):&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const original = { a: 1, b: { c: 2 } };&lt;br&gt;
const deepCopy = JSON.parse(JSON.stringify(original));&lt;br&gt;
deepCopy.b.c = 3;&lt;br&gt;
console.log(original.b.c); // Output: 2 (reference is not shared)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt;: This method has limitations with functions, special objects like Date, and undefined properties.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using a recursive function&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;function deepCopy(obj) {&lt;br&gt;
    if (obj === null || typeof obj !== 'object') {&lt;br&gt;
        return obj;&lt;br&gt;
    }&lt;br&gt;
 &lt;br&gt;
    if (Array.isArray(obj)) {&lt;br&gt;
        const arrCopy = [];&lt;br&gt;
        obj.forEach((item, index) =&amp;gt; {&lt;br&gt;
            arrCopy[index] = deepCopy(item);&lt;br&gt;
        });&lt;br&gt;
        return arrCopy;&lt;br&gt;
    }&lt;br&gt;
 &lt;br&gt;
    const objCopy = {};&lt;br&gt;
    Object.keys(obj).forEach((key) =&amp;gt; {&lt;br&gt;
        objCopy[key] = deepCopy(obj[key]);&lt;br&gt;
    });&lt;br&gt;
    return objCopy;&lt;br&gt;
}&lt;br&gt;
 &lt;br&gt;
const original = { a: 1, b: { c: 2 } };&lt;br&gt;
const deepCopy = deepCopy(original);&lt;br&gt;
deepCopy.b.c = 3;&lt;br&gt;
console.log(original.b.c); // Output: 2 (reference is not shared)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Shallow Copy&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicates top-level properties.&lt;/li&gt;
&lt;li&gt;Copies references to nested objects.&lt;/li&gt;
&lt;li&gt;Changes to nested objects in the copy affect the original object.&lt;/li&gt;
&lt;li&gt;Methods: &lt;strong&gt;Object.assign&lt;/strong&gt;, &lt;strong&gt;spread operator&lt;/strong&gt; (...).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Deep Copy&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicates all properties, including nested objects.&lt;/li&gt;
&lt;li&gt;Creates new instances of nested objects.&lt;/li&gt;
&lt;li&gt;Changes to nested objects in the copy do not affect the original object.&lt;/li&gt;
&lt;li&gt;Methods: &lt;strong&gt;JSON.parse(JSON.stringify(obj))&lt;/strong&gt; (for simple cases), *&lt;em&gt;recursive functions *&lt;/em&gt;(for complex objects).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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