<?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: Saravanan Lakshmanan</title>
    <description>The latest articles on DEV Community by Saravanan Lakshmanan (@dev_saravanan_journey).</description>
    <link>https://dev.to/dev_saravanan_journey</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3927221%2F86db017d-8633-4bd5-9ac1-97ee29f0d80e.png</url>
      <title>DEV Community: Saravanan Lakshmanan</title>
      <link>https://dev.to/dev_saravanan_journey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dev_saravanan_journey"/>
    <language>en</language>
    <item>
      <title>Stop Prop Drilling: Learn React useContext with Easy Examples</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Sun, 02 Aug 2026 06:37:20 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/stop-prop-drilling-learn-react-usecontext-with-easy-examples-ach</link>
      <guid>https://dev.to/dev_saravanan_journey/stop-prop-drilling-learn-react-usecontext-with-easy-examples-ach</guid>
      <description>&lt;h1&gt;
  
  
  React &lt;code&gt;useContext&lt;/code&gt; Hook Explained with Simple Examples
&lt;/h1&gt;

&lt;p&gt;If you've started learning React Hooks, you've probably heard about &lt;code&gt;useContext&lt;/code&gt;. At first, it may seem confusing, but once you understand the problem it solves, it becomes much easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;useContext&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; is a React Hook that allows multiple components to access the same data without passing it through every intermediate component as props.&lt;/p&gt;

&lt;p&gt;In simple words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; helps you share data between components directly.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why do we need &lt;code&gt;useContext&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Imagine the following component structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
 ├── Parent
      ├── Child
            ├── GrandChild
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose the &lt;code&gt;GrandChild&lt;/code&gt; component needs the user's name.&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;useContext&lt;/code&gt;, you would have to pass the data like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Saravanan"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   ↓
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   ↓
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
   ↓
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GrandChild&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though only &lt;code&gt;GrandChild&lt;/code&gt; needs the data, every component in between has to receive and pass it.&lt;/p&gt;

&lt;p&gt;This process is called &lt;strong&gt;prop drilling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; solves this problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-Time Example
&lt;/h2&gt;

&lt;p&gt;Think of a company.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The CEO announces a holiday.&lt;/li&gt;
&lt;li&gt;Every employee should know about it.&lt;/li&gt;
&lt;li&gt;The CEO doesn't tell each employee individually.&lt;/li&gt;
&lt;li&gt;Instead, the announcement is placed on the company notice board where everyone can read it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context = Notice board&lt;/li&gt;
&lt;li&gt;Provider = Person who posts the announcement&lt;/li&gt;
&lt;li&gt;Consumer (&lt;code&gt;useContext&lt;/code&gt;) = Employees reading the announcement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No need to pass the information through every manager.&lt;/p&gt;




&lt;h2&gt;
  
  
  Another Simple Example
&lt;/h2&gt;

&lt;p&gt;Imagine your house has Wi-Fi.&lt;/p&gt;

&lt;p&gt;Every family member connects to the same Wi-Fi.&lt;/p&gt;

&lt;p&gt;The password is not passed from one family member to another every time someone wants internet access.&lt;/p&gt;

&lt;p&gt;Instead, everyone accesses the same network directly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; works similarly.&lt;/p&gt;




&lt;h1&gt;
  
  
  Syntax
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Step 1: Create a Context
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Provide the Data
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Saravanan"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;UserContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;value&lt;/code&gt; prop contains the data that will be shared.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: Consume the Data
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UserContext&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the component can access the shared data directly.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Example
&lt;/h1&gt;

&lt;h3&gt;
  
  
  App.jsx
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Child&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Child&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Saravanan"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;UserContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  Child.jsx
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;GrandChild&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./GrandChild&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Child&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GrandChild&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Child&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  GrandChild.jsx
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;UserContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;GrandChild&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UserContext&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;GrandChild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, Saravanan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that &lt;code&gt;Child&lt;/code&gt; never receives any props.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GrandChild&lt;/code&gt; directly accesses the shared value.&lt;/p&gt;




&lt;h1&gt;
  
  
  How &lt;code&gt;useContext&lt;/code&gt; Works
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createContext()
        │
        ▼
Context Object
        │
        ▼
Provider shares data
        │
        ▼
Child Components
        │
        ▼
useContext() reads the data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>react</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python Is More Than Just print("Hello World"): Understanding the Fundamentals</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Sun, 26 Jul 2026 14:41:56 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/python-is-more-than-just-printhello-world-understanding-the-fundamentals-2mfg</link>
      <guid>https://dev.to/dev_saravanan_journey/python-is-more-than-just-printhello-world-understanding-the-fundamentals-2mfg</guid>
      <description>&lt;p&gt;I recently started learning Python, and in my first session, we explored some important fundamentals about Python, programming languages, Python versions, Python implementations, and the features that make Python popular.&lt;/p&gt;

&lt;p&gt;Before jumping directly into coding, understanding these basics gives us a better idea of what Python actually is and why it is widely used.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Python?
&lt;/h1&gt;

&lt;p&gt;Python is a high-level, general-purpose programming language known for its simple and readable syntax.&lt;/p&gt;

&lt;p&gt;It is used in many areas, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web Development&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;li&gt;Data Science&lt;/li&gt;
&lt;li&gt;Artificial Intelligence&lt;/li&gt;
&lt;li&gt;Machine Learning&lt;/li&gt;
&lt;li&gt;Scripting&lt;/li&gt;
&lt;li&gt;Backend Development&lt;/li&gt;
&lt;li&gt;Software Development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python is designed to be easy to read and write, which makes it popular among beginners as well as experienced developers.&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding Python Version Numbers
&lt;/h1&gt;

&lt;p&gt;You may have seen Python versions written like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python 3.14.6&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's understand what these numbers mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Major Version
&lt;/h2&gt;

&lt;p&gt;The first number represents the major version.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 2&lt;/li&gt;
&lt;li&gt;Python 3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python 2 and Python 3 are major versions with significant differences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Minor Version
&lt;/h2&gt;

&lt;p&gt;The second number represents the minor version.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.13&lt;/li&gt;
&lt;li&gt;Python 3.14&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new minor version can introduce new language features, improvements, and changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Maintenance or Patch Version
&lt;/h2&gt;

&lt;p&gt;The third number represents the maintenance or patch release.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Python 3.14.6&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This can be understood as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;3&lt;/strong&gt; → Major version&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;14&lt;/strong&gt; → Minor version&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;6&lt;/strong&gt; → Maintenance/Patch release&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Patch releases generally focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bug fixes&lt;/li&gt;
&lt;li&gt;Security fixes&lt;/li&gt;
&lt;li&gt;Stability improvements&lt;/li&gt;
&lt;li&gt;Other small improvements&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Understanding Alpha, Beta, RC, and Development Versions
&lt;/h1&gt;

&lt;p&gt;When looking at Python releases, we may see versions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;3.15.0a1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3.15.0b1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3.15.0rc1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3.15.0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3.15.0.dev1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These indicate different stages of development.&lt;/p&gt;




&lt;h2&gt;
  
  
  Alpha (a)
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.15.0a1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An Alpha version is an early development version.&lt;/p&gt;

&lt;p&gt;It may contain new features, but the features and behavior can still change.&lt;/p&gt;

&lt;p&gt;Alpha versions are mainly useful for developers and testers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Beta (b)
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.15.0b1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Beta version is more mature than an Alpha version, but it may still contain bugs and changes.&lt;/p&gt;

&lt;p&gt;It is released for further testing before the final version.&lt;/p&gt;




&lt;h2&gt;
  
  
  Release Candidate (rc)
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.15.0rc1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Release Candidate is almost ready for the final release.&lt;/p&gt;

&lt;p&gt;If no major problems are discovered, the Release Candidate may become the final version.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Release
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.15.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the official stable release.&lt;/p&gt;

&lt;p&gt;It is considered ready for general use.&lt;/p&gt;




&lt;h2&gt;
  
  
  Development Version (dev)
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.15.0.dev1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A development version represents an early stage of development before the Alpha stage.&lt;/p&gt;

&lt;p&gt;The general progression is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Development
     ↓
Alpha
     ↓
Beta
     ↓
Release Candidate
     ↓
Final Release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  What is CPython?
&lt;/h1&gt;

&lt;p&gt;CPython is the original and most widely used implementation of Python.&lt;/p&gt;

&lt;p&gt;It is written primarily in the C programming language.&lt;/p&gt;

&lt;p&gt;When most people download and install Python from the official Python website, they are generally using CPython.&lt;/p&gt;

&lt;p&gt;A simple representation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Code
     ↓
CPython
     ↓
Execution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CPython is the reference implementation of Python and is the implementation most commonly used by Python developers.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Jython?
&lt;/h1&gt;

&lt;p&gt;Jython is an implementation of Python designed to run on the Java platform.&lt;/p&gt;

&lt;p&gt;It allows Python code to interact with Java libraries and Java applications.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python + Java Platform = Jython
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Jython can be useful when Python code needs to work with Java-based applications and libraries.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is IronPython?
&lt;/h1&gt;

&lt;p&gt;IronPython is an implementation of Python designed for the .NET platform.&lt;/p&gt;

&lt;p&gt;It allows Python code to work with the .NET ecosystem and interact with .NET libraries.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python + .NET Platform = IronPython
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Important Features of Python
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Simple and Easy to Learn
&lt;/h2&gt;

&lt;p&gt;Python has a clean and readable syntax.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, Python!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is simple and easy to understand.&lt;/p&gt;

&lt;p&gt;Python syntax is designed to be close to natural language, which makes it beginner-friendly.&lt;/p&gt;

&lt;p&gt;Compared to many other programming languages, Python generally requires less code to perform the same task.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Open Source
&lt;/h2&gt;

&lt;p&gt;Python is open-source software.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Anyone can use Python.&lt;/li&gt;
&lt;li&gt;Anyone can download Python.&lt;/li&gt;
&lt;li&gt;Developers can study its source code.&lt;/li&gt;
&lt;li&gt;Developers can contribute to its development.&lt;/li&gt;
&lt;li&gt;Python can be used for personal and commercial projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python is freely available to developers around the world.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Object-Oriented Programming
&lt;/h2&gt;

&lt;p&gt;Python supports Object-Oriented Programming, commonly known as OOP.&lt;/p&gt;

&lt;p&gt;Object-Oriented Programming allows us to organize programs using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;li&gt;Abstraction&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;Student&lt;/code&gt; is a class.&lt;/p&gt;

&lt;p&gt;A class can be used as a blueprint for creating objects.&lt;/p&gt;

&lt;p&gt;Python also supports other programming styles, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Procedural Programming&lt;/li&gt;
&lt;li&gt;Functional Programming&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, Python is a multi-paradigm programming language.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. High-Level Programming Language
&lt;/h2&gt;

&lt;p&gt;Python is a high-level programming language.&lt;/p&gt;

&lt;p&gt;High-level languages are designed to be easier for humans to read and understand.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, Python!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We do not need to directly manage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU registers&lt;/li&gt;
&lt;li&gt;Memory addresses&lt;/li&gt;
&lt;li&gt;Machine instructions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Python implementation handles many low-level details for us.&lt;/p&gt;

&lt;h3&gt;
  
  
  Low-Level Language
&lt;/h3&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Machine Language&lt;/li&gt;
&lt;li&gt;Assembly Language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These languages are closer to the hardware and are more difficult for humans to understand.&lt;/p&gt;

&lt;h3&gt;
  
  
  High-Level Language
&lt;/h3&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;C++&lt;/li&gt;
&lt;li&gt;C#&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These languages are easier for humans to read and write.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Dynamically Typed Language
&lt;/h2&gt;

&lt;p&gt;Python is a dynamically typed programming language.&lt;/p&gt;

&lt;p&gt;This means we do not need to explicitly declare the data type of a variable.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python automatically understands that &lt;code&gt;x&lt;/code&gt; contains an integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Saravanan&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python understands that &lt;code&gt;name&lt;/code&gt; contains a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;99.99&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python understands that &lt;code&gt;price&lt;/code&gt; contains a floating-point number.&lt;/p&gt;

&lt;p&gt;The data type is determined automatically during program execution.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Interpreted Language
&lt;/h2&gt;

&lt;p&gt;Python is commonly described as an interpreted programming language.&lt;/p&gt;

&lt;p&gt;Python code is executed by the Python interpreter.&lt;/p&gt;

&lt;p&gt;A simple representation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Source Code
        ↓
Python Interpreter
        ↓
Program Execution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interpreter reads and executes Python code.&lt;/p&gt;

&lt;p&gt;In CPython, Python source code is first compiled into an intermediate form called &lt;strong&gt;bytecode&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The bytecode is then executed by the Python Virtual Machine, commonly known as the PVM.&lt;/p&gt;

&lt;p&gt;A simplified representation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Source Code
        ↓
Bytecode
        ↓
Python Virtual Machine
        ↓
Execution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  7. Extensive Standard Library
&lt;/h2&gt;

&lt;p&gt;Python comes with a large collection of built-in modules and libraries.&lt;/p&gt;

&lt;p&gt;These libraries provide ready-made functionality for many tasks.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File handling&lt;/li&gt;
&lt;li&gt;Mathematics&lt;/li&gt;
&lt;li&gt;Date and time operations&lt;/li&gt;
&lt;li&gt;Regular expressions&lt;/li&gt;
&lt;li&gt;Internet communication&lt;/li&gt;
&lt;li&gt;Operating system interaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of writing the square root logic ourselves, we can use the built-in &lt;code&gt;math&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;Python is often called:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Batteries included"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means Python provides many useful tools and libraries out of the box.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Large Ecosystem of Third-Party Libraries
&lt;/h2&gt;

&lt;p&gt;In addition to the standard library, Python has a huge ecosystem of third-party libraries.&lt;/p&gt;

&lt;p&gt;Developers can install additional packages to add more functionality.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NumPy → Numerical computing&lt;/li&gt;
&lt;li&gt;Pandas → Data analysis&lt;/li&gt;
&lt;li&gt;Matplotlib → Data visualization&lt;/li&gt;
&lt;li&gt;Django → Web development&lt;/li&gt;
&lt;li&gt;Flask → Web development&lt;/li&gt;
&lt;li&gt;TensorFlow → Machine Learning&lt;/li&gt;
&lt;li&gt;PyTorch → Deep Learning&lt;/li&gt;
&lt;li&gt;Requests → HTTP requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This large ecosystem is one of the major reasons Python is so popular.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Platform Independent
&lt;/h2&gt;

&lt;p&gt;Python is a cross-platform programming language.&lt;/p&gt;

&lt;p&gt;Python programs can generally run on different operating systems, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows&lt;/li&gt;
&lt;li&gt;Linux&lt;/li&gt;
&lt;li&gt;macOS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a Python program written on Windows can usually be executed on Linux or macOS with little or no modification.&lt;/p&gt;

&lt;p&gt;A simple representation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Program
      ↓
Python Interpreter
      ↓
Windows / Linux / macOS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, certain operating-system-specific features may require modifications.&lt;/p&gt;




&lt;h2&gt;
  
  
  10. General-Purpose Programming Language
&lt;/h2&gt;

&lt;p&gt;Python is a general-purpose programming language.&lt;/p&gt;

&lt;p&gt;This means it is not limited to only one specific type of application.&lt;/p&gt;

&lt;p&gt;Python can be used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web Development&lt;/li&gt;
&lt;li&gt;Automation&lt;/li&gt;
&lt;li&gt;Data Analysis&lt;/li&gt;
&lt;li&gt;Data Science&lt;/li&gt;
&lt;li&gt;Artificial Intelligence&lt;/li&gt;
&lt;li&gt;Machine Learning&lt;/li&gt;
&lt;li&gt;Backend Development&lt;/li&gt;
&lt;li&gt;Scripting&lt;/li&gt;
&lt;li&gt;Game Development&lt;/li&gt;
&lt;li&gt;Desktop Applications&lt;/li&gt;
&lt;li&gt;Cybersecurity&lt;/li&gt;
&lt;li&gt;Scientific Computing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of this flexibility, Python is useful in many different industries.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. Portable
&lt;/h2&gt;

&lt;p&gt;Python programs can often be moved from one operating system to another.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Windows
    ↓
Python Program
    ↓
Linux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In many cases, the same Python code can work on both systems.&lt;/p&gt;

&lt;p&gt;This makes Python portable.&lt;/p&gt;

&lt;p&gt;However, external dependencies and operating-system-specific features may sometimes require additional configuration.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. Extensible
&lt;/h2&gt;

&lt;p&gt;Python can be extended using code written in other programming languages such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C&lt;/li&gt;
&lt;li&gt;C++&lt;/li&gt;
&lt;li&gt;Rust&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can be useful when high performance is required.&lt;/p&gt;

&lt;p&gt;For example, Python can use code written in C to perform certain operations more quickly.&lt;/p&gt;

&lt;p&gt;This allows developers to combine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python
   +
High-Performance Languages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  13. Embeddable
&lt;/h2&gt;

&lt;p&gt;Python can be embedded inside applications written in other programming languages.&lt;/p&gt;

&lt;p&gt;For example, Python can be integrated into applications written using languages such as C or C++.&lt;/p&gt;

&lt;p&gt;This allows developers to use Python's flexibility inside larger software applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  14. Automatic Memory Management
&lt;/h2&gt;

&lt;p&gt;Python provides automatic memory management.&lt;/p&gt;

&lt;p&gt;Developers generally do not need to manually allocate and release memory.&lt;/p&gt;

&lt;p&gt;Python uses a mechanism called &lt;strong&gt;Garbage Collection&lt;/strong&gt; to manage unused objects.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When an object is no longer needed, Python can automatically clean up the memory associated with it.&lt;/p&gt;

&lt;p&gt;This makes programming easier and reduces certain types of memory-management errors.&lt;/p&gt;




</description>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React useEffect Explained: Understanding Mounting, Updating, and Unmounting</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Fri, 24 Jul 2026 09:17:52 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/react-useeffect-explained-understanding-mounting-updating-and-unmounting-408k</link>
      <guid>https://dev.to/dev_saravanan_journey/react-useeffect-explained-understanding-mounting-updating-and-unmounting-408k</guid>
      <description>&lt;p&gt;When learning React, two important concepts are the component lifecycle and the &lt;code&gt;useEffect&lt;/code&gt; Hook.&lt;/p&gt;

&lt;p&gt;A React component is not just created once and forgotten. It goes through different stages during its existence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mounting&lt;/li&gt;
&lt;li&gt;Updating&lt;/li&gt;
&lt;li&gt;Unmounting&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; Hook helps us perform side effects during these stages. Examples of side effects include fetching data from an API, working with timers, adding event listeners, and interacting with external systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a React Component?
&lt;/h2&gt;

&lt;p&gt;A React component is an independent and reusable part of a user interface. In modern React, components are commonly created using JavaScript functions.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Welcome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome to React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When React uses this component, it renders the JSX returned by the function.&lt;/p&gt;

&lt;p&gt;A component can have its own state, receive props, and respond to changes during its lifetime.&lt;/p&gt;

&lt;p&gt;This is where the concept of the component lifecycle becomes important.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Three Stages of a React Component
&lt;/h1&gt;

&lt;p&gt;Every React component goes through three major stages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mounting → Updating → Unmounting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can understand these stages using a simple real-life example.&lt;/p&gt;

&lt;p&gt;Think of a component like a person:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Birth → Life and Changes → Departure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In React:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component Created → Component Updated → Component Removed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  1. Mounting
&lt;/h1&gt;

&lt;p&gt;Mounting is the first stage of a component's lifecycle.&lt;/p&gt;

&lt;p&gt;It happens when a component is created and added to the page for the first time.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When React displays this component for the first time, the component is mounted.&lt;/p&gt;

&lt;p&gt;The basic process is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component is created
        ↓
React renders the component
        ↓
The UI appears on the page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For function components, &lt;code&gt;useEffect&lt;/code&gt; with an empty dependency array is commonly used when an effect should run after the initial render.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Component mounted&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The empty dependency array is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells React that the effect should run after the initial render and should not run again because of later state or prop changes.&lt;/p&gt;

&lt;p&gt;A common use case is fetching initial data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The empty array is useful when the operation should happen only when the component initially appears.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. Updating
&lt;/h1&gt;

&lt;p&gt;After a component has been mounted, it may change.&lt;/p&gt;

&lt;p&gt;A component can update when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Its state changes&lt;/li&gt;
&lt;li&gt;Its props change&lt;/li&gt;
&lt;li&gt;Its parent component causes it to render again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                Increase
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initially:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the button is clicked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count: 0 → 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the state changed, React renders the component again with the updated value.&lt;/p&gt;

&lt;p&gt;The process is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;State or props change
        ↓
React renders the component again
        ↓
The UI is updated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is called the updating stage.&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding useEffect
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; Hook is used to perform side effects in a component.&lt;/p&gt;

&lt;p&gt;The basic syntax is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Side effect code&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second argument is called the dependency array.&lt;/p&gt;

&lt;p&gt;The dependency array controls when the effect should run.&lt;/p&gt;

&lt;p&gt;There are three important patterns.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pattern 1: useEffect Without a Dependency Array
&lt;/h1&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Effect executed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When no dependency array is provided, the effect runs after every render.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Effect executed&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="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sequence is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Initial render
      ↓
useEffect runs

Click button
      ↓
State changes
      ↓
Component renders again
      ↓
useEffect runs again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Every render → useEffect runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can sometimes cause unwanted repeated operations.&lt;/p&gt;

&lt;p&gt;For example, if an effect changes state and the effect runs after every render, it can potentially create repeated renders.&lt;/p&gt;

&lt;p&gt;Therefore, the dependency array is important for controlling when an effect should execute.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pattern 2: useEffect With an Empty Dependency Array
&lt;/h1&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Effect executed&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The empty dependency array means that the effect does not depend on any state or prop value.&lt;/p&gt;

&lt;p&gt;The effect runs after the initial render.&lt;/p&gt;

&lt;p&gt;The sequence is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component mounts
      ↓
Initial render
      ↓
useEffect runs
      ↓
Later re-renders occur
      ↓
Effect does not run again because of those changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This runs after the initial render&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the button is clicked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count changes
      ↓
Component re-renders
      ↓
useEffect does not run again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A common example is fetching initial data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.com/api/data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The effect is intended to run when the component initially appears.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pattern 3: useEffect With Dependencies
&lt;/h1&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Count changed&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="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;count&lt;/code&gt; is the dependency.&lt;/p&gt;

&lt;p&gt;The effect runs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;After the initial render&lt;/li&gt;
&lt;li&gt;Whenever &lt;code&gt;count&lt;/code&gt; changes&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Count changed&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="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                +
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setCount2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                +2
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Counter: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Counter 2: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now consider what happens when each button is clicked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clicking the first button
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count changes
      ↓
Component re-renders
      ↓
[count] has changed
      ↓
useEffect runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Clicking the second button
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count2 changes
      ↓
Component re-renders
      ↓
[count] has not changed
      ↓
useEffect does not run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very important point:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The entire component can re-render even though a particular useEffect does not run.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The dependency array controls the execution of the effect, not whether the entire component renders.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Example to Understand the Difference
&lt;/h1&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Effect executed&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="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;count&lt;/code&gt; changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count: 0 → 1

Component re-renders
        ↓
React checks [count]
        ↓
count changed
        ↓
useEffect runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;count2&lt;/code&gt; changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count2: 10 → 11

Component re-renders
        ↓
React checks [count]
        ↓
count did not change
        ↓
useEffect does not run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The component re-render and the effect execution are two different things.&lt;/p&gt;

&lt;p&gt;This distinction is essential for understanding React.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Unmounting
&lt;/h1&gt;

&lt;p&gt;Unmounting is the final stage of a component's lifecycle.&lt;/p&gt;

&lt;p&gt;It happens when a component is removed from the page.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;show&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setShow&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;show&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setShow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                Remove Component
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initially:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show = true
      ↓
Child component is displayed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After clicking the button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show = false
      ↓
Child component is removed
      ↓
Child component is unmounted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lifecycle becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mount
  ↓
Update
  ↓
Unmount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  useEffect Cleanup Function
&lt;/h1&gt;

&lt;p&gt;Some effects create resources that should be stopped or removed when they are no longer needed.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timers&lt;/li&gt;
&lt;li&gt;Intervals&lt;/li&gt;
&lt;li&gt;Event listeners&lt;/li&gt;
&lt;li&gt;Subscriptions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cleanup function is created by returning a function from &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Timer completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cleanup function is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&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;When the component is removed, the cleanup code runs.&lt;/p&gt;

&lt;p&gt;The process is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component mounts
      ↓
Timer starts
      ↓
Component is removed
      ↓
Cleanup function runs
      ↓
Timer is cleared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents unnecessary operations from continuing after the component is gone.&lt;/p&gt;




&lt;h1&gt;
  
  
  Cleanup During Updates
&lt;/h1&gt;

&lt;p&gt;Cleanup is not only used when a component is unmounted.&lt;/p&gt;

&lt;p&gt;Suppose an effect depends on a value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Effect started&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cleanup executed&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;count&lt;/code&gt; changes, React performs the following general sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Previous effect cleanup
        ↓
Component updates
        ↓
New effect runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the lifecycle of an effect can look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Effect starts
      ↓
Dependency changes
      ↓
Previous effect cleanup
      ↓
New effect starts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is particularly useful for subscriptions, timers, and event listeners.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Component Lifecycle
&lt;/h1&gt;

&lt;p&gt;The complete lifecycle can be represented like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 MOUNTING
                    ↓
          Component is created
                    ↓
             Initial render
                    ↓
              useEffect runs
                    ↓
                 UPDATING
                    ↓
       State or props change
                    ↓
             Component renders
                    ↓
     Dependency value changed?
             ↙              ↘
           Yes               No
            ↓                 ↓
    Effect runs again     Effect does not run
                    ↓
                UNMOUNTING
                    ↓
       Component removed
                    ↓
            Cleanup runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Ever wondered why React applications feel so fast? The answer lies in one of React's smartest concepts: the Virtual DOM.</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Thu, 16 Jul 2026 14:53:10 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/ever-wondered-why-react-applications-feel-so-fast-the-answer-lies-in-one-of-reacts-smartest-57p9</link>
      <guid>https://dev.to/dev_saravanan_journey/ever-wondered-why-react-applications-feel-so-fast-the-answer-lies-in-one-of-reacts-smartest-57p9</guid>
      <description>&lt;h1&gt;
  
  
  Real DOM vs Virtual DOM in React
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is the DOM?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;DOM (Document Object Model)&lt;/strong&gt; is a programming interface for HTML and XML documents. It represents the structure of a webpage as a tree of objects, allowing JavaScript to access, modify, add, or remove elements dynamically.&lt;/p&gt;

&lt;p&gt;When a browser loads an HTML document, it creates the DOM in memory.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DOM Tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document
   │
  html
   │
  body
  ├── h1
  │     └── Hello
  └── p
        └── Welcome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript can manipulate these elements using methods like:&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  What is Real DOM?
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Real DOM&lt;/strong&gt; is the actual DOM created and maintained by the browser. Every HTML element becomes an object in memory.&lt;/p&gt;

&lt;p&gt;Whenever JavaScript changes an element, the browser updates the Real DOM and may need to recalculate layout, repaint, and render the page again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome&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;The browser immediately updates the actual &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; element on the webpage.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem with Real DOM
&lt;/h2&gt;

&lt;p&gt;Imagine a webpage with &lt;strong&gt;5,000 elements&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If only &lt;strong&gt;one button's text changes&lt;/strong&gt;, the browser still needs to determine what changed, update the DOM, and potentially recalculate layout and repaint affected parts of the page.&lt;/p&gt;

&lt;p&gt;Frequent DOM updates can become expensive because DOM operations are generally slower than working with plain JavaScript objects.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Virtual DOM?
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Virtual DOM&lt;/strong&gt; is a lightweight JavaScript representation (copy) of the Real DOM.&lt;/p&gt;

&lt;p&gt;It is &lt;strong&gt;not displayed on the screen&lt;/strong&gt;. Instead, React uses it internally to determine what has changed before updating the browser's Real DOM.&lt;/p&gt;

&lt;p&gt;When data changes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;React creates a new Virtual DOM.&lt;/li&gt;
&lt;li&gt;React compares it with the previous Virtual DOM.&lt;/li&gt;
&lt;li&gt;It identifies only the changed elements.&lt;/li&gt;
&lt;li&gt;It updates only those elements in the Real DOM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This comparison process is called &lt;strong&gt;Diffing&lt;/strong&gt;, and the update strategy is known as &lt;strong&gt;Reconciliation&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example
&lt;/h1&gt;

&lt;p&gt;Initial UI&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;React&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Click&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Virtual DOM Copy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
├── h1 → Hello
├── p → React
└── button → Click
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After clicking a button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;React&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Click&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React compares the old and new Virtual DOM.&lt;/p&gt;

&lt;p&gt;It finds that only the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; text changed.&lt;/p&gt;

&lt;p&gt;Instead of rebuilding the whole page, React updates only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; remain untouched.&lt;/p&gt;




&lt;h1&gt;
  
  
  How React Updates the UI
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;State Changes
      │
      ▼
Create New Virtual DOM
      │
      ▼
Compare with Old Virtual DOM
      │
      ▼
Find Differences (Diffing)
      │
      ▼
Update Only Changed Elements
      │
      ▼
Real DOM Updated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Real DOM vs Virtual DOM
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Real DOM&lt;/th&gt;
&lt;th&gt;Virtual DOM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Meaning&lt;/td&gt;
&lt;td&gt;Actual DOM maintained by the browser&lt;/td&gt;
&lt;td&gt;Lightweight JavaScript copy of the Real DOM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Location&lt;/td&gt;
&lt;td&gt;Browser memory&lt;/td&gt;
&lt;td&gt;JavaScript memory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update Speed&lt;/td&gt;
&lt;td&gt;Comparatively slower for frequent updates&lt;/td&gt;
&lt;td&gt;Faster because React computes changes in memory first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update Method&lt;/td&gt;
&lt;td&gt;Updates the actual DOM directly&lt;/td&gt;
&lt;td&gt;Compares two virtual trees, then updates only necessary parts of the Real DOM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rendering&lt;/td&gt;
&lt;td&gt;Browser handles rendering directly&lt;/td&gt;
&lt;td&gt;React optimizes updates before the browser renders&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Can become slower with many repeated updates&lt;/td&gt;
&lt;td&gt;Improves efficiency by minimizing direct DOM operations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Used By&lt;/td&gt;
&lt;td&gt;Vanilla JavaScript&lt;/td&gt;
&lt;td&gt;React&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  Real-Life Analogy
&lt;/h1&gt;

&lt;p&gt;Imagine you are editing a 500-page book.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real DOM
&lt;/h3&gt;

&lt;p&gt;You erase and rewrite directly in the original printed book every time you find a mistake.&lt;/p&gt;

&lt;p&gt;Even a small correction means working on the actual book.&lt;/p&gt;

&lt;h3&gt;
  
  
  Virtual DOM
&lt;/h3&gt;

&lt;p&gt;You first make corrections on a photocopy.&lt;/p&gt;

&lt;p&gt;Then you compare the photocopy with the original.&lt;/p&gt;

&lt;p&gt;Finally, you update only the pages that actually changed.&lt;/p&gt;

&lt;p&gt;This saves time and avoids unnecessary work.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why React Uses Virtual DOM
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Reduces unnecessary DOM updates.&lt;/li&gt;
&lt;li&gt;Improves application performance for frequent UI changes.&lt;/li&gt;
&lt;li&gt;Makes user interfaces more responsive.&lt;/li&gt;
&lt;li&gt;Updates only the required elements instead of the entire page.&lt;/li&gt;
&lt;li&gt;Provides a declarative way to build interactive interfaces.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>React Made Simple: Components, Hooks (useState), and the Virtual DOM Explained</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Wed, 15 Jul 2026 15:19:58 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/react-made-simple-components-hooks-usestate-and-the-virtual-dom-explained-47ab</link>
      <guid>https://dev.to/dev_saravanan_journey/react-made-simple-components-hooks-usestate-and-the-virtual-dom-explained-47ab</guid>
      <description>&lt;p&gt;If you're starting your React journey, understanding Components, Hooks (useState), and the Virtual DOM will make learning every advanced topic much easier.&lt;/p&gt;

&lt;p&gt;In this blog, we'll explore these fundamental concepts with examples.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. What is a Component?
&lt;/h1&gt;

&lt;p&gt;A component is the fundamental building block of a React application. It is an independent, reusable piece of UI that contains its own structure, logic, and behavior.&lt;/p&gt;

&lt;p&gt;Instead of writing the same HTML repeatedly, React allows developers to create components once and reuse them wherever needed.&lt;/p&gt;

&lt;p&gt;For example, a website may contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header&lt;/li&gt;
&lt;li&gt;Navigation Bar&lt;/li&gt;
&lt;li&gt;Sidebar&lt;/li&gt;
&lt;li&gt;Product Card&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these can be created as separate components and reused throughout the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functional Component Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Header&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome to React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Header&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The component can then be rendered using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React treats the component as a custom HTML element and renders the UI returned by the function.&lt;/p&gt;




&lt;h1&gt;
  
  
  Advantages of Components
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Improves code reusability.&lt;/li&gt;
&lt;li&gt;Makes applications easier to maintain.&lt;/li&gt;
&lt;li&gt;Separates different parts of the UI into manageable units.&lt;/li&gt;
&lt;li&gt;Encourages modular development.&lt;/li&gt;
&lt;li&gt;Simplifies debugging and testing.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2. Types of Components
&lt;/h1&gt;

&lt;p&gt;React mainly provides two types of components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class Component
&lt;/h2&gt;

&lt;p&gt;Before React 16.8, class components were commonly used because they could manage state and lifecycle methods.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Uses JavaScript classes.&lt;/li&gt;
&lt;li&gt;Supports state.&lt;/li&gt;
&lt;li&gt;Supports lifecycle methods.&lt;/li&gt;
&lt;li&gt;More verbose and complex.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Functional Component
&lt;/h2&gt;

&lt;p&gt;Functional components are regular JavaScript functions that return JSX.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Welcome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Easy to understand.&lt;/li&gt;
&lt;li&gt;Less code.&lt;/li&gt;
&lt;li&gt;Better readability.&lt;/li&gt;
&lt;li&gt;Supports Hooks.&lt;/li&gt;
&lt;li&gt;Preferred in modern React applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, most React applications are built using functional components because they are simpler and more maintainable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Difference Between Class and Functional Components
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class Component&lt;/th&gt;
&lt;th&gt;Functional Component&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Uses JavaScript classes&lt;/td&gt;
&lt;td&gt;Uses JavaScript functions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;More code&lt;/td&gt;
&lt;td&gt;Less code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Uses &lt;code&gt;this&lt;/code&gt; keyword&lt;/td&gt;
&lt;td&gt;Does not use &lt;code&gt;this&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State managed using &lt;code&gt;this.state&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;State managed using Hooks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Uses lifecycle methods&lt;/td&gt;
&lt;td&gt;Uses Hooks such as &lt;code&gt;useEffect&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less common in new projects&lt;/td&gt;
&lt;td&gt;Preferred in modern React&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  3. What are Hooks?
&lt;/h1&gt;

&lt;p&gt;Hooks are special built-in React functions that allow functional components to use React features such as state, side effects, context, and references.&lt;/p&gt;

&lt;p&gt;They were introduced in React 16.8.&lt;/p&gt;

&lt;p&gt;Before Hooks, developers often used class components whenever they needed state or lifecycle methods. Hooks removed this limitation by enabling functional components to access these features.&lt;/p&gt;

&lt;p&gt;Examples of Hooks include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;useState&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useEffect&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useContext&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useRef&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useReducer&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  4. What is &lt;code&gt;useState&lt;/code&gt;?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; is a built-in React Hook used to create and manage state inside a functional component.&lt;/p&gt;

&lt;p&gt;State represents data that can change over time. Whenever state changes, React automatically re-renders the component and updates the user interface.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; stores the current state value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setCount&lt;/code&gt; updates the state.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useState&lt;/code&gt; is the Hook.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; is the initial value.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Counter Example
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initially, &lt;code&gt;count&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Clicking the button calls &lt;code&gt;increment()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setCount(count + 1)&lt;/code&gt; updates the state.&lt;/li&gt;
&lt;li&gt;React re-renders the component.&lt;/li&gt;
&lt;li&gt;The updated value is displayed automatically.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Why use &lt;code&gt;useState&lt;/code&gt;?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; is commonly used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Counter applications&lt;/li&gt;
&lt;li&gt;Like buttons&lt;/li&gt;
&lt;li&gt;Show/Hide password functionality&lt;/li&gt;
&lt;li&gt;Theme toggles&lt;/li&gt;
&lt;li&gt;Form inputs&lt;/li&gt;
&lt;li&gt;Shopping cart counters&lt;/li&gt;
&lt;li&gt;Dynamic UI updates&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  5. What is the Virtual DOM?
&lt;/h1&gt;

&lt;p&gt;The Virtual DOM is a lightweight JavaScript representation of the Real DOM.&lt;/p&gt;

&lt;p&gt;Instead of updating the browser's DOM directly after every change, React first updates the Virtual DOM.&lt;/p&gt;

&lt;p&gt;React then compares the updated Virtual DOM with the previous version using a process called &lt;strong&gt;Diffing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After identifying the changes, React updates only the necessary parts of the Real DOM.&lt;/p&gt;

&lt;p&gt;This process improves rendering performance because manipulating the Real DOM is comparatively expensive.&lt;/p&gt;




&lt;h1&gt;
  
  
  How the Virtual DOM Works
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;The component renders for the first time.&lt;/li&gt;
&lt;li&gt;React creates a Virtual DOM tree.&lt;/li&gt;
&lt;li&gt;When state changes, React creates a new Virtual DOM.&lt;/li&gt;
&lt;li&gt;React compares the old and new Virtual DOM trees.&lt;/li&gt;
&lt;li&gt;Only the changed elements are updated in the Real DOM.&lt;/li&gt;
&lt;li&gt;The browser reflects the changes efficiently.&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Example
&lt;/h1&gt;

&lt;p&gt;Suppose a page contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header&lt;/li&gt;
&lt;li&gt;Sidebar&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;li&gt;Counter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If only the counter value changes from 5 to 6, React updates only the counter element instead of rebuilding the entire page.&lt;/p&gt;

&lt;p&gt;This selective update improves application performance.&lt;/p&gt;




&lt;h1&gt;
  
  
  Advantages of the Virtual DOM
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Faster UI updates.&lt;/li&gt;
&lt;li&gt;Efficient DOM manipulation.&lt;/li&gt;
&lt;li&gt;Better application performance.&lt;/li&gt;
&lt;li&gt;Reduces unnecessary rendering.&lt;/li&gt;
&lt;li&gt;Improves user experience.&lt;/li&gt;
&lt;li&gt;Simplifies UI updates for developers.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Components, Hooks, and the Virtual DOM are among the most important concepts in React.&lt;/p&gt;

&lt;p&gt;Components encourage reusable and modular UI development. Functional components combined with Hooks such as &lt;code&gt;useState&lt;/code&gt; make React applications simpler and easier to maintain. The Virtual DOM optimizes rendering by updating only the parts of the interface that have changed, resulting in better performance and a smoother user experience.&lt;/p&gt;

&lt;p&gt;Understanding these concepts forms a strong foundation for learning more advanced React topics such as Props, &lt;code&gt;useEffect&lt;/code&gt;, Routing, Context API, and state management libraries.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Three React Terms That Confuse Every Beginner (Explained Clearly)</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Tue, 14 Jul 2026 14:32:16 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/the-three-react-terms-that-confuse-every-beginner-explained-clearly-28d6</link>
      <guid>https://dev.to/dev_saravanan_journey/the-three-react-terms-that-confuse-every-beginner-explained-clearly-28d6</guid>
      <description>&lt;h1&gt;
  
  
  Understanding Vite, Components, and Node Package Manager (NPM)
&lt;/h1&gt;

&lt;p&gt;When developers begin learning React, they frequently encounter three terms: &lt;strong&gt;Vite&lt;/strong&gt;, &lt;strong&gt;Component&lt;/strong&gt;, and &lt;strong&gt;Node Package Manager (NPM)&lt;/strong&gt;. Although these concepts are closely related, each serves a different purpose in the development workflow. Understanding them individually helps build a strong foundation before creating React applications.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Vite?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Vite&lt;/strong&gt; (pronounced &lt;em&gt;"veet"&lt;/em&gt;, derived from the French word for "fast") is a modern frontend build tool that helps developers create, run, and build web applications efficiently. It was created to solve the slow startup and rebuild times experienced with older frontend tooling.&lt;/p&gt;

&lt;p&gt;Vite is not a JavaScript library or a framework. Instead, it is a development tool that prepares your project, starts a development server, bundles your code for production, and provides a smooth development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why was Vite introduced?
&lt;/h2&gt;

&lt;p&gt;As frontend applications became larger, traditional bundlers had to process the entire application before starting the development server. This resulted in longer startup times and slower updates whenever developers modified their code.&lt;/p&gt;

&lt;p&gt;Vite improves this process by leveraging modern browser support for native ES Modules. Instead of bundling the entire application during development, Vite serves source files directly to the browser and only processes the files that are requested.&lt;/p&gt;

&lt;p&gt;This approach provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster project startup&lt;/li&gt;
&lt;li&gt;Instant page refreshes&lt;/li&gt;
&lt;li&gt;Faster Hot Module Replacement (HMR)&lt;/li&gt;
&lt;li&gt;Optimized production builds&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Creating a React Project with Vite
&lt;/h2&gt;

&lt;p&gt;To create a new React application using Vite:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to choose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project name&lt;/li&gt;
&lt;li&gt;Framework (React)&lt;/li&gt;
&lt;li&gt;Language (JavaScript or TypeScript)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the project is created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-project
npm &lt;span class="nb"&gt;install
&lt;/span&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The development server starts, and your React application becomes available in the browser.&lt;/p&gt;




&lt;h2&gt;
  
  
  Typical Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-project/
│
├── node_modules/
├── public/
├── src/
│   ├── App.jsx
│   ├── main.jsx
│
├── package.json
├── package-lock.json
├── vite.config.js
└── index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each folder has a specific responsibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;src/&lt;/strong&gt; – Contains the application's source code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;public/&lt;/strong&gt; – Stores static assets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;node_modules/&lt;/strong&gt; – Contains installed packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;package.json&lt;/strong&gt; – Stores project information and dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;vite.config.js&lt;/strong&gt; – Configuration file for Vite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;index.html&lt;/strong&gt; – Entry point of the application.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Features of Vite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Extremely fast development server&lt;/li&gt;
&lt;li&gt;Native ES Module support&lt;/li&gt;
&lt;li&gt;Hot Module Replacement (HMR)&lt;/li&gt;
&lt;li&gt;Optimized production builds&lt;/li&gt;
&lt;li&gt;Minimal configuration&lt;/li&gt;
&lt;li&gt;Supports React, Vue, Svelte, Solid, and other frameworks&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  What is a Component?
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;Component&lt;/strong&gt; is one of the core concepts of React.&lt;/p&gt;

&lt;p&gt;A component is an independent, reusable piece of the user interface. Instead of writing an entire webpage inside one large file, React encourages developers to divide the interface into smaller pieces called components.&lt;/p&gt;

&lt;p&gt;Each component is responsible for rendering a specific part of the application.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header&lt;/li&gt;
&lt;li&gt;Navigation Bar&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;li&gt;Product Card&lt;/li&gt;
&lt;li&gt;Login Form&lt;/li&gt;
&lt;li&gt;Search Box&lt;/li&gt;
&lt;li&gt;Sidebar&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every webpage is essentially a collection of multiple components working together.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Components?
&lt;/h2&gt;

&lt;p&gt;Imagine developing an e-commerce website.&lt;/p&gt;

&lt;p&gt;Without components, every product card would need to be written repeatedly.&lt;/p&gt;

&lt;p&gt;With components, the product card is written once and reused wherever needed.&lt;/p&gt;

&lt;p&gt;This approach provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code reusability&lt;/li&gt;
&lt;li&gt;Better readability&lt;/li&gt;
&lt;li&gt;Easier maintenance&lt;/li&gt;
&lt;li&gt;Independent development&lt;/li&gt;
&lt;li&gt;Improved scalability&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example Component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Header&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome to My Website&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a React component because it returns JSX, which React converts into user interface elements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using a Component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When React encounters &lt;code&gt;&amp;lt;Header /&amp;gt;&lt;/code&gt;, it executes the &lt;code&gt;Header&lt;/code&gt; function and displays the returned UI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Do Component Names Start with a Capital Letter?
&lt;/h2&gt;

&lt;p&gt;React follows a naming convention where custom components begin with an uppercase letter.&lt;/p&gt;

&lt;p&gt;Correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Header&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;Incorrect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This distinction exists because React interprets lowercase tags as standard HTML elements.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React recognizes this as an HTML &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;However:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React recognizes this as a custom React component.&lt;/p&gt;

&lt;p&gt;Using PascalCase allows React to differentiate custom components from built-in HTML tags.&lt;/p&gt;




&lt;h2&gt;
  
  
  Components Are JavaScript Functions
&lt;/h2&gt;

&lt;p&gt;Most React components are simply JavaScript functions.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although a component is technically a JavaScript function, React refers to it as a &lt;strong&gt;Component&lt;/strong&gt; because its purpose is to produce a portion of the user interface.&lt;/p&gt;




&lt;h2&gt;
  
  
  Types of Components
&lt;/h2&gt;

&lt;p&gt;Modern React primarily uses &lt;strong&gt;Function Components&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Welcome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Earlier versions of React also supported Class Components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Today, function components are the recommended approach because they are simpler and support Hooks.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Node Package Manager (NPM)?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;NPM (Node Package Manager)&lt;/strong&gt; is the default package manager for Node.js.&lt;/p&gt;

&lt;p&gt;It enables developers to install, update, remove, and manage reusable JavaScript packages.&lt;/p&gt;

&lt;p&gt;A package is a collection of reusable code created by developers to solve common programming problems.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;Axios&lt;/li&gt;
&lt;li&gt;Express&lt;/li&gt;
&lt;li&gt;Lodash&lt;/li&gt;
&lt;li&gt;Bootstrap&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of writing every feature from scratch, developers install packages maintained by the community.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Do We Need NPM?
&lt;/h2&gt;

&lt;p&gt;Modern web development depends heavily on third-party libraries.&lt;/p&gt;

&lt;p&gt;Without NPM, developers would need to manually download libraries, manage versions, and copy files into every project.&lt;/p&gt;

&lt;p&gt;NPM automates this entire process.&lt;/p&gt;

&lt;p&gt;It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install packages&lt;/li&gt;
&lt;li&gt;Update packages&lt;/li&gt;
&lt;li&gt;Remove packages&lt;/li&gt;
&lt;li&gt;Manage project dependencies&lt;/li&gt;
&lt;li&gt;Execute project scripts&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Installing a Package
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;NPM downloads Axios and stores it inside the &lt;strong&gt;node_modules&lt;/strong&gt; directory.&lt;/p&gt;




&lt;h2&gt;
  
  
  Installing React
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;This downloads React and its required packages into your project.&lt;/p&gt;




&lt;h2&gt;
  
  
  package.json
&lt;/h2&gt;

&lt;p&gt;Every NPM project contains a &lt;strong&gt;package.json&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;It stores important information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project name&lt;/li&gt;
&lt;li&gt;Version&lt;/li&gt;
&lt;li&gt;Dependencies&lt;/li&gt;
&lt;li&gt;Scripts&lt;/li&gt;
&lt;li&gt;Project metadata&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my-project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^19.0.0"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever a package is installed, NPM automatically updates this file.&lt;/p&gt;




&lt;h2&gt;
  
  
  node_modules
&lt;/h2&gt;

&lt;p&gt;After running:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;NPM creates a directory named:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This folder contains every installed package along with its required dependencies.&lt;/p&gt;

&lt;p&gt;Because this directory can become very large, developers typically exclude it from version control using &lt;code&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common NPM Commands
&lt;/h2&gt;

&lt;p&gt;Create a Vite project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install dependencies:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Install a package:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Remove a package:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Start the development server:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Build the project:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;






&lt;h1&gt;
  
  
  Relationship Between Vite, Components, and NPM
&lt;/h1&gt;

&lt;p&gt;Although these technologies work together, they have distinct responsibilities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vite&lt;/strong&gt; creates and serves the project during development and builds it for production.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NPM&lt;/strong&gt; installs and manages the packages required by the project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Components&lt;/strong&gt; are the reusable building blocks used to construct the application's user interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A typical React development workflow is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a project using Vite.&lt;/li&gt;
&lt;li&gt;Install project dependencies with NPM.&lt;/li&gt;
&lt;li&gt;Build the application's interface using React components.&lt;/li&gt;
&lt;li&gt;Run the project using the Vite development server.&lt;/li&gt;
&lt;li&gt;Build the optimized production version when development is complete.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding the role of each tool provides a strong foundation for modern React development and makes it easier to learn advanced concepts such as Hooks, Routing, State Management, and API integration.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Explained: JSX, Components, Virtual DOM &amp; Diffing Algorithm</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Mon, 13 Jul 2026 11:40:38 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/react-explained-jsx-components-virtual-dom-diffing-algorithm-3fc7</link>
      <guid>https://dev.to/dev_saravanan_journey/react-explained-jsx-components-virtual-dom-diffing-algorithm-3fc7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;React is an open-source JavaScript library used to build fast, interactive, and reusable user interfaces (UI). It is primarily used for developing Single Page Applications (SPAs), where only the necessary parts of a webpage are updated instead of reloading the entire page.&lt;/p&gt;

&lt;p&gt;React follows a component-based architecture, making applications easier to build, maintain, and scale.&lt;/p&gt;




&lt;h2&gt;
  
  
  History of React
&lt;/h2&gt;

&lt;p&gt;React was created by Facebook (now Meta) in 2011 to solve the challenges of building complex and dynamic user interfaces for its own applications. After successfully using it internally, Facebook released React as an open-source JavaScript library in 2013, allowing developers worldwide to use and contribute to its development.&lt;/p&gt;




&lt;h2&gt;
  
  
  Open Source
&lt;/h2&gt;

&lt;p&gt;React is completely open source, meaning its source code is publicly available for anyone to use, study, modify, and improve.&lt;/p&gt;

&lt;p&gt;Making React open source helped:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increase adoption across the industry.&lt;/li&gt;
&lt;li&gt;Build a large developer community.&lt;/li&gt;
&lt;li&gt;Receive contributions from developers worldwide.&lt;/li&gt;
&lt;li&gt;Improve the library continuously through community support.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, React is one of the most popular frontend libraries in the world.&lt;/p&gt;




&lt;h2&gt;
  
  
  Companies Using React
&lt;/h2&gt;

&lt;p&gt;React is widely adopted by many leading technology companies, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Meta (Facebook and Instagram)&lt;/li&gt;
&lt;li&gt;Netflix&lt;/li&gt;
&lt;li&gt;Airbnb&lt;/li&gt;
&lt;li&gt;Uber&lt;/li&gt;
&lt;li&gt;Dropbox&lt;/li&gt;
&lt;li&gt;WhatsApp Web&lt;/li&gt;
&lt;li&gt;Discord&lt;/li&gt;
&lt;li&gt;Shopify&lt;/li&gt;
&lt;li&gt;Reddit&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why React?
&lt;/h2&gt;

&lt;p&gt;React simplifies frontend development by providing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reusable components&lt;/li&gt;
&lt;li&gt;Faster UI updates&lt;/li&gt;
&lt;li&gt;Better code organization&lt;/li&gt;
&lt;li&gt;Easier maintenance&lt;/li&gt;
&lt;li&gt;Improved performance&lt;/li&gt;
&lt;li&gt;Strong community support&lt;/li&gt;
&lt;li&gt;Rich ecosystem of libraries and tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These advantages make React suitable for both small and large-scale applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  Component-Based Architecture
&lt;/h2&gt;

&lt;p&gt;React applications are built using components.&lt;/p&gt;

&lt;p&gt;A component is an independent, reusable piece of the user interface that performs a specific task.&lt;/p&gt;

&lt;p&gt;For example, an e-commerce website can be divided into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navbar&lt;/li&gt;
&lt;li&gt;Search Bar&lt;/li&gt;
&lt;li&gt;Banner&lt;/li&gt;
&lt;li&gt;Product Card&lt;/li&gt;
&lt;li&gt;Cart&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each component can be developed, tested, and reused independently, making applications more modular and easier to maintain.&lt;/p&gt;




&lt;h2&gt;
  
  
  JSX
&lt;/h2&gt;

&lt;p&gt;JSX (JavaScript XML) is a syntax extension that allows developers to write HTML-like code inside JavaScript.&lt;/p&gt;

&lt;p&gt;Although JSX looks like HTML, it is converted into JavaScript before being executed by the browser.&lt;/p&gt;

&lt;p&gt;JSX makes React code easier to read and write while allowing JavaScript and UI elements to work together naturally.&lt;/p&gt;




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

&lt;p&gt;React is commonly used to build Single Page Applications.&lt;/p&gt;

&lt;p&gt;In a traditional website, navigating between pages reloads the entire webpage.&lt;/p&gt;

&lt;p&gt;In a React application, only the required content is updated while the rest of the page remains unchanged.&lt;/p&gt;

&lt;p&gt;This provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster navigation&lt;/li&gt;
&lt;li&gt;Better user experience&lt;/li&gt;
&lt;li&gt;Reduced page reloads&lt;/li&gt;
&lt;li&gt;Improved application performance&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real DOM
&lt;/h2&gt;

&lt;p&gt;The Real DOM is the actual Document Object Model created by the browser from the HTML document.&lt;/p&gt;

&lt;p&gt;Whenever JavaScript directly modifies the DOM, the browser updates the webpage accordingly.&lt;/p&gt;

&lt;p&gt;For large applications with frequent UI updates, repeatedly modifying the Real DOM can become less efficient.&lt;/p&gt;




&lt;h2&gt;
  
  
  Virtual DOM
&lt;/h2&gt;

&lt;p&gt;The Virtual DOM is a lightweight copy of the Real DOM maintained by React in memory.&lt;/p&gt;

&lt;p&gt;Whenever application data changes, React creates a new Virtual DOM and compares it with the previous Virtual DOM.&lt;/p&gt;

&lt;p&gt;Instead of updating the entire webpage, React identifies only the parts that have changed and updates those specific elements in the Real DOM.&lt;/p&gt;

&lt;p&gt;This approach improves efficiency and provides a smoother user experience.&lt;/p&gt;




&lt;h2&gt;
  
  
  Diffing Algorithm
&lt;/h2&gt;

&lt;p&gt;The Diffing Algorithm is React's comparison process.&lt;/p&gt;

&lt;p&gt;It compares the previous Virtual DOM with the newly created Virtual DOM to identify differences between them.&lt;/p&gt;

&lt;p&gt;After finding the changes, React updates only the affected elements in the Real DOM rather than rebuilding the entire page.&lt;/p&gt;

&lt;p&gt;This selective updating helps improve rendering performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  React UI Updating Process
&lt;/h2&gt;

&lt;p&gt;The UI update process in React follows these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A user performs an action.&lt;/li&gt;
&lt;li&gt;The application state changes.&lt;/li&gt;
&lt;li&gt;React creates a new Virtual DOM.&lt;/li&gt;
&lt;li&gt;The Diffing Algorithm compares the old and new Virtual DOM.&lt;/li&gt;
&lt;li&gt;React identifies the changed elements.&lt;/li&gt;
&lt;li&gt;Only those elements are updated in the Real DOM.&lt;/li&gt;
&lt;li&gt;The browser displays the updated user interface.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Advantages of React
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Simple and reusable components&lt;/li&gt;
&lt;li&gt;Efficient UI rendering&lt;/li&gt;
&lt;li&gt;Better application performance&lt;/li&gt;
&lt;li&gt;Cleaner and maintainable code&lt;/li&gt;
&lt;li&gt;Easy integration with APIs&lt;/li&gt;
&lt;li&gt;Large open-source community&lt;/li&gt;
&lt;li&gt;Excellent ecosystem and tooling&lt;/li&gt;
&lt;li&gt;Suitable for modern web applications&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;React has become one of the most widely used JavaScript libraries for frontend development due to its simplicity, component-based architecture, Virtual DOM, and efficient rendering process.&lt;/p&gt;

&lt;p&gt;Understanding concepts such as Components, JSX, Virtual DOM, Diffing Algorithm, and Single Page Applications provides a strong foundation for building modern and scalable web applications.&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/reactjs/reactjs-introduction/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/reactjs/reactjs-introduction/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/react/react_intro.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/react/react_intro.asp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My Experience at Code on JVM Chennai: From DSA in Production to Building AI Products</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Sun, 12 Jul 2026 15:05:42 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/my-experience-at-code-on-jvm-chennai-from-dsa-in-production-to-building-ai-products-4b8a</link>
      <guid>https://dev.to/dev_saravanan_journey/my-experience-at-code-on-jvm-chennai-from-dsa-in-production-to-building-ai-products-4b8a</guid>
      <description>&lt;p&gt;Recently, I attended the &lt;strong&gt;Code on JVM Chennai&lt;/strong&gt; meetup, and it was an incredible learning experience. As someone transitioning into software development and currently learning Full Stack Java, events like these help bridge the gap between classroom learning and real-world software engineering.&lt;/p&gt;

&lt;p&gt;The meetup featured three insightful sessions, each offering a unique perspective on modern software development.&lt;/p&gt;




&lt;h1&gt;
  
  
  Session 1: DSA in Production
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Speaker:&lt;/strong&gt; Hareesh Rajendran (Founder &amp;amp; CEO, Hayan Tech)&lt;/p&gt;

&lt;p&gt;This session completely changed the way I think about Data Structures and Algorithms (DSA).&lt;/p&gt;

&lt;p&gt;As beginners, we often associate DSA with coding interviews and competitive programming. But this session demonstrated how many advanced data structures quietly power the applications we use every day.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Bloom Filter
&lt;/h3&gt;

&lt;p&gt;A Bloom Filter is a memory-efficient probabilistic data structure used to quickly determine whether an element &lt;em&gt;might&lt;/em&gt; exist in a dataset.&lt;/p&gt;

&lt;p&gt;Instead of storing every value, it stores compact information, making lookups extremely fast while consuming very little RAM.&lt;/p&gt;

&lt;p&gt;Some real-world applications include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instagram username availability checks&lt;/li&gt;
&lt;li&gt;Apache Cassandra&lt;/li&gt;
&lt;li&gt;Google Chrome&lt;/li&gt;
&lt;li&gt;Feed readers&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. HNSW Graph (Hierarchical Navigable Small World)
&lt;/h3&gt;

&lt;p&gt;One of the most important data structures behind modern AI applications.&lt;/p&gt;

&lt;p&gt;It enables extremely fast similarity searches across millions of vectors, making AI-powered search practical.&lt;/p&gt;

&lt;p&gt;Common applications include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vector Databases&lt;/li&gt;
&lt;li&gt;AI Search&lt;/li&gt;
&lt;li&gt;Recommendation Systems&lt;/li&gt;
&lt;li&gt;Retrieval-Augmented Generation (RAG)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One interesting takeaway was seeing how AI products rely on efficient data structures—not just machine learning models.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Skip List
&lt;/h3&gt;

&lt;p&gt;A Skip List is an alternative to balanced trees that allows fast searching, insertion, and deletion.&lt;/p&gt;

&lt;p&gt;Real-world usage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redis Sorted Sets&lt;/li&gt;
&lt;li&gt;Rate Limiting&lt;/li&gt;
&lt;li&gt;RocksDB Storage Engine&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. LSM Tree (Log-Structured Merge Tree)
&lt;/h3&gt;

&lt;p&gt;An LSM Tree is designed for systems that perform a huge number of write operations.&lt;/p&gt;

&lt;p&gt;It is widely used in databases and storage systems because it optimizes write performance.&lt;/p&gt;

&lt;p&gt;Applications include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storage Engines&lt;/li&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;Live Streaming Systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. Consistent Hashing
&lt;/h3&gt;

&lt;p&gt;Consistent Hashing distributes requests across multiple servers while minimizing data movement whenever servers are added or removed.&lt;/p&gt;

&lt;p&gt;It is heavily used in distributed systems such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Akamai CDN&lt;/li&gt;
&lt;li&gt;Netflix&lt;/li&gt;
&lt;li&gt;Amazon DynamoDB&lt;/li&gt;
&lt;li&gt;Discord Routing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The speaker also recommended exploring the &lt;strong&gt;Netflix Engineering Blog&lt;/strong&gt; to understand how these concepts are used in production.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. Hexagonal Grid (H3)
&lt;/h3&gt;

&lt;p&gt;A geospatial indexing system that divides maps into hexagonal cells for efficient location-based processing.&lt;/p&gt;

&lt;p&gt;Applications include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ola&lt;/li&gt;
&lt;li&gt;Uber&lt;/li&gt;
&lt;li&gt;Swiggy&lt;/li&gt;
&lt;li&gt;Zomato&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The recommendation to read the &lt;strong&gt;H3 Engineering Blogs&lt;/strong&gt; was another valuable takeaway.&lt;/p&gt;




&lt;h3&gt;
  
  
  7. HyperLogLog
&lt;/h3&gt;

&lt;p&gt;HyperLogLog is a probabilistic algorithm used to estimate the number of unique elements while using very little memory.&lt;/p&gt;

&lt;p&gt;Instead of counting every item exactly, it provides an approximate count with impressive accuracy.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reddit&lt;/li&gt;
&lt;li&gt;Analytics Dashboards&lt;/li&gt;
&lt;li&gt;Google BigQuery&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  My Biggest Takeaway
&lt;/h2&gt;

&lt;p&gt;This session completely changed my perspective on DSA.&lt;/p&gt;

&lt;p&gt;It's not just about solving interview problems—it's about building systems capable of serving millions of users efficiently.&lt;/p&gt;




&lt;h1&gt;
  
  
  Session 2: Uncovering Ideas Worth Building in the AI Era
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Speaker:&lt;/strong&gt; Agnel John (Founder &amp;amp; CEO, Error Makes Clever)&lt;/p&gt;

&lt;p&gt;This session shifted the focus from technology to entrepreneurship.&lt;/p&gt;

&lt;p&gt;One of the strongest messages was that &lt;strong&gt;building a product alone is never enough&lt;/strong&gt;. The real challenge is creating something that solves a genuine problem and that people are willing to pay for.&lt;/p&gt;

&lt;p&gt;Some important takeaways were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build your idea instead of waiting for the "perfect time."&lt;/li&gt;
&lt;li&gt;Learn how your product can generate revenue.&lt;/li&gt;
&lt;li&gt;A product by itself is never your competitive advantage—execution, customer understanding, and continuous improvement matter much more.&lt;/li&gt;
&lt;li&gt;Before building something big, find someone within your own circle who is willing to pay for your solution.&lt;/li&gt;
&lt;li&gt;Once you've validated your idea, commit fully and keep improving it.&lt;/li&gt;
&lt;li&gt;Getting your &lt;strong&gt;first paying customer&lt;/strong&gt; is a significant milestone because it proves that you're solving a real problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As someone still learning development, this session reminded me that writing code is only one part of building successful software. Understanding users and solving meaningful problems are equally important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Session 3: Streaming Large File Downloads in Java
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Speaker:&lt;/strong&gt; Kalaivani Mohan (Software Engineer, IBM)&lt;/p&gt;

&lt;p&gt;The final session focused on an important backend engineering concept—streaming large file downloads.&lt;/p&gt;

&lt;p&gt;A common mistake is trying to load an entire large file into memory before sending it to the user. This can consume excessive RAM and affect application performance.&lt;/p&gt;

&lt;p&gt;Instead, Java applications use &lt;strong&gt;streaming&lt;/strong&gt;, where files are sent in smaller chunks.&lt;/p&gt;

&lt;p&gt;This approach offers several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lower memory consumption&lt;/li&gt;
&lt;li&gt;Better application performance&lt;/li&gt;
&lt;li&gt;Faster response times&lt;/li&gt;
&lt;li&gt;Improved scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Streaming is commonly used while serving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Videos&lt;/li&gt;
&lt;li&gt;PDF documents&lt;/li&gt;
&lt;li&gt;Reports&lt;/li&gt;
&lt;li&gt;Cloud storage downloads&lt;/li&gt;
&lt;li&gt;Enterprise applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although the concept sounds simple, it's an excellent example of how small implementation decisions can make applications significantly more efficient.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Each session taught me something different.&lt;/p&gt;

&lt;p&gt;The first session showed how advanced data structures power large-scale systems used by millions of users.&lt;/p&gt;

&lt;p&gt;The second session reminded me that successful products are built around real customer problems—not just great technology.&lt;/p&gt;

&lt;p&gt;The third session demonstrated how backend engineering techniques improve performance and scalability.&lt;/p&gt;

&lt;p&gt;As someone currently learning Full Stack Development, attending this meetup broadened my understanding of software engineering beyond coding tutorials and classroom lessons.&lt;/p&gt;

&lt;p&gt;A heartfelt thank you to the organizers, speakers, and everyone involved in making &lt;strong&gt;Code on JVM Chennai&lt;/strong&gt; such an informative and inspiring event.&lt;/p&gt;

&lt;p&gt;I'm looking forward to attending more tech meetups, learning from experienced professionals, and continuing my journey as a software developer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every meetup is another step forward in the learning journey.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>java</category>
      <category>dsa</category>
      <category>hackathon</category>
    </item>
    <item>
      <title>Callback, Callback Hell &amp; Promise in JavaScript</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Thu, 09 Jul 2026 17:31:57 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/callback-callback-hell-promise-in-javascript-2dn8</link>
      <guid>https://dev.to/dev_saravanan_journey/callback-callback-hell-promise-in-javascript-2dn8</guid>
      <description>&lt;h1&gt;
  
  
  What is a Callback?
&lt;/h1&gt;

&lt;p&gt;A callback is simply &lt;strong&gt;a function passed as an argument to another function&lt;/strong&gt; so that it can be executed later.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&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;processUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Saravanan&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;processUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Saravanan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;greet&lt;/code&gt; is the callback function.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why do we need callbacks?
&lt;/h1&gt;

&lt;p&gt;Some tasks take time to complete.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Downloading data from a server&lt;/li&gt;
&lt;li&gt;Reading a file&lt;/li&gt;
&lt;li&gt;Waiting for a timer&lt;/li&gt;
&lt;li&gt;Fetching API data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript doesn't stop the entire program while waiting.&lt;/p&gt;

&lt;p&gt;Instead, it says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Continue doing other work. When this task finishes, I'll call the callback."&lt;/p&gt;
&lt;/blockquote&gt;

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

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

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Task Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;End&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;/div&gt;



&lt;p&gt;Notice that JavaScript didn't wait for 2 seconds before printing &lt;code&gt;End&lt;/code&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem: Callback Hell
&lt;/h1&gt;

&lt;p&gt;Imagine we're building software using the SDLC process.&lt;/p&gt;

&lt;p&gt;The order should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Planning
↓
Design
↓
Development
↓
Testing
↓
Deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using callbacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;planning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Planning Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;design&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Design Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;development&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Development Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;testing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Testing Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Deployment Completed&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;planning&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;design&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;development&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;testing&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although the program works, there's a problem.&lt;/p&gt;

&lt;p&gt;The code keeps moving further to the right.&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="nf"&gt;planning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;design&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;development&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nf"&gt;testing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This deeply nested structure is called &lt;strong&gt;Callback Hell&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Problems with Callback Hell:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Difficult to read&lt;/li&gt;
&lt;li&gt;Difficult to debug&lt;/li&gt;
&lt;li&gt;Difficult to maintain&lt;/li&gt;
&lt;li&gt;Becomes messy as the project grows&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Solution: Promise
&lt;/h1&gt;

&lt;p&gt;A Promise represents the result of an asynchronous operation.&lt;/p&gt;

&lt;p&gt;It can be in one of three states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pending&lt;/li&gt;
&lt;li&gt;Fulfilled (Resolved)&lt;/li&gt;
&lt;li&gt;Rejected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creating a Promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;planning&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Planning Completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Promise either calls:&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="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when successful,&lt;/p&gt;

&lt;p&gt;or&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="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when something goes wrong.&lt;/p&gt;




&lt;h1&gt;
  
  
  Promise Chaining
&lt;/h1&gt;

&lt;p&gt;Now we can execute tasks one after another without nesting.&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="nf"&gt;planning&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;design&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;development&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;testing&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Something went wrong.&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;This code is much easier to read.&lt;/p&gt;

&lt;p&gt;It clearly says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Planning
→ Design
→ Development
→ Testing
→ Deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Even Cleaner: async/await
&lt;/h1&gt;

&lt;p&gt;JavaScript introduced &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; to make Promise-based code look more like normal synchronous code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;SDLC&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;planning&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;design&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;development&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;testing&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="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;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;SDLC&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is usually easier to understand because the steps appear in the same order they execute.&lt;/p&gt;




&lt;h1&gt;
  
  
  Callback Hell vs Promise
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Callback Hell&lt;/th&gt;
&lt;th&gt;Promise&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Deeply nested code&lt;/td&gt;
&lt;td&gt;Flat and readable code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hard to maintain&lt;/td&gt;
&lt;td&gt;Easy to maintain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Difficult error handling&lt;/td&gt;
&lt;td&gt;Centralized error handling using &lt;code&gt;.catch()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less readable as the project grows&lt;/td&gt;
&lt;td&gt;Easier to understand and extend&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_promise.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/js/js_promise.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/javascript/javascript-promise/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/javascript/javascript-promise/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>callback</category>
    </item>
    <item>
      <title>JavaScript Closures</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Wed, 08 Jul 2026 09:54:26 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/javascript-closures-59cn</link>
      <guid>https://dev.to/dev_saravanan_journey/javascript-closures-59cn</guid>
      <description>&lt;h2&gt;
  
  
  Closure
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;closure&lt;/strong&gt; is created when an &lt;strong&gt;inner function remembers and can access the variables of its outer function even after the outer function has finished executing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simple words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A closure allows a function to "remember" the environment in which it was created.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is one of JavaScript's most powerful features and is commonly used for data privacy, maintaining state, callbacks, and event handling.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Do We Need Closures?
&lt;/h1&gt;

&lt;p&gt;Normally, local variables exist only while a function is running.&lt;/p&gt;

&lt;p&gt;Once the function finishes execution, its local variables are destroyed.&lt;/p&gt;

&lt;p&gt;But sometimes we need those variables even after the function has finished.&lt;/p&gt;

&lt;p&gt;Closures solve this problem by allowing the inner function to remember those variables.&lt;/p&gt;




&lt;h1&gt;
  
  
  Basic Example
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&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;inner&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;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step-by-Step Execution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;outer()&lt;/code&gt; is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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;A local variable is created.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;Inside &lt;code&gt;outer()&lt;/code&gt;, another function is created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;inner()&lt;/code&gt; function can access &lt;code&gt;message&lt;/code&gt; because it is inside &lt;code&gt;outer()&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Instead of calling &lt;code&gt;inner()&lt;/code&gt;, we return it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;The returned function is stored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although &lt;code&gt;outer()&lt;/code&gt; has finished execution, JavaScript does &lt;strong&gt;not&lt;/strong&gt; destroy the variable &lt;code&gt;message&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because the returned function still needs it.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Now we call:&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="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inner function still remembers the variable.&lt;/p&gt;

&lt;p&gt;This memory is called a &lt;strong&gt;closure&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Visual Representation
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;outer()
│
├── message = "Hello"
│
└── return inner()
         │
         ▼
    greet()
         │
         ▼
console.log(message)
         │
         ▼
      "Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though &lt;code&gt;outer()&lt;/code&gt; has finished, &lt;code&gt;message&lt;/code&gt; is still available because &lt;code&gt;inner()&lt;/code&gt; remembers it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example 2: Counter
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="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="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;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;count&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;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;When &lt;code&gt;counter()&lt;/code&gt; runs,&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;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned function remembers &lt;code&gt;count&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Each time the function is called,&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;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value increases instead of resetting.&lt;/p&gt;

&lt;p&gt;Without a closure, &lt;code&gt;count&lt;/code&gt; would become &lt;code&gt;0&lt;/code&gt; every time.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example 3: Private Variable
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bankAccount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5000&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="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;balance&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;checkBalance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bankAccount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;checkBalance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;balance&lt;/code&gt; cannot be accessed directly.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReferenceError
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the returned function can access it.&lt;/p&gt;

&lt;p&gt;This provides &lt;strong&gt;data privacy&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Closure with Parameters
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&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;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;y&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;double&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;multiply&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is remembered by the returned function.&lt;/p&gt;

&lt;p&gt;Later,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2 × 5 = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/javascript/closure-in-javascript/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/javascript/closure-in-javascript/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_function_closures.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/js/js_function_closures.asp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>JavaScript DOM Basics: Selecting, Accessing, Adding &amp; Deleting Elements</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Fri, 03 Jul 2026 10:26:50 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/javascript-dom-basics-selecting-accessing-adding-deleting-elements-5127</link>
      <guid>https://dev.to/dev_saravanan_journey/javascript-dom-basics-selecting-accessing-adding-deleting-elements-5127</guid>
      <description>&lt;h1&gt;
  
  
  1️⃣ Selecting an Element
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Selecting&lt;/strong&gt; means &lt;strong&gt;finding an HTML element&lt;/strong&gt; so JavaScript can work with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Click Me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&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;Now JavaScript knows which element you want to work with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Selection Methods
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// By ID&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// By Class&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// By Tag&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// First matching element&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// All matching elements&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;Real-life analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine a library with thousands of books.&lt;/p&gt;

&lt;p&gt;If someone asks you to bring the JavaScript book, the first thing you do is &lt;strong&gt;find it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That process is called &lt;strong&gt;Selecting&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  2️⃣ Accessing an Element
&lt;/h1&gt;

&lt;p&gt;Once you've selected an element, you can &lt;strong&gt;access its information&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also access other properties:&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;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tagName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Think of it this way
&lt;/h3&gt;

&lt;p&gt;Selecting ➜ Finds the element&lt;/p&gt;

&lt;p&gt;Accessing ➜ Reads information from the element&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Real-life analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You search for your friend's contact (Selecting).&lt;/p&gt;

&lt;p&gt;Then you check their phone number or email (Accessing).&lt;/p&gt;




&lt;h1&gt;
  
  
  3️⃣ Adding an Element
&lt;/h1&gt;

&lt;p&gt;Adding means &lt;strong&gt;creating a new HTML element and inserting it into the webpage&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create an element
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;para&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&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;This creates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it's &lt;strong&gt;not visible yet&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Add content
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;para&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello Everyone&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;Now it becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello Everyone&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still not visible.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: Add it to the webpage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;para&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your page becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;My Website&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello Everyone&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The paragraph now appears on the webpage.&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Real-life analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Buying a new chair doesn't automatically place it in your room.&lt;/p&gt;

&lt;p&gt;You first buy it (create), then bring it into your room (append).&lt;/p&gt;




&lt;h1&gt;
  
  
  4️⃣ Deleting an Element
&lt;/h1&gt;

&lt;p&gt;Deleting means &lt;strong&gt;removing an element from the webpage&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"msg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;para&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;msg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The paragraph disappears from the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Another Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"banana"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Banana&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Mango&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Apple&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Mango&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;Real-life analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your room has a chair, table, and fan.&lt;/p&gt;

&lt;p&gt;If you remove the chair, the room still exists—but the chair is gone.&lt;/p&gt;

&lt;p&gt;That's exactly what &lt;code&gt;.remove()&lt;/code&gt; does.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Flow
&lt;/h1&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1 — Select
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2 — Access
&lt;/h3&gt;



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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 3 — Add
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Learning DOM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the page becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Learning DOM&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 4 — Delete
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Quick Summary
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Selecting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Find an HTML element&lt;/td&gt;
&lt;td&gt;&lt;code&gt;document.getElementById("title")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Accessing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Read information from the selected element&lt;/td&gt;
&lt;td&gt;&lt;code&gt;heading.innerText&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Adding&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Create and insert a new element&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;createElement()&lt;/code&gt; + &lt;code&gt;appendChild()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Deleting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Remove an element from the webpage&lt;/td&gt;
&lt;td&gt;&lt;code&gt;element.remove()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://www.w3schools.com/jsreF/met_element_remove.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/jsreF/met_element_remove.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/remove" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Element/remove&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/javascript/how-to-remove-an-html-element-using-javascript/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/javascript/how-to-remove-an-html-element-using-javascript/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>JavaScript DOM Mini Projects</title>
      <dc:creator>Saravanan Lakshmanan</dc:creator>
      <pubDate>Wed, 01 Jul 2026 17:24:52 +0000</pubDate>
      <link>https://dev.to/dev_saravanan_journey/javascript-dom-mini-projects-2bc6</link>
      <guid>https://dev.to/dev_saravanan_journey/javascript-dom-mini-projects-2bc6</guid>
      <description>&lt;p&gt;&lt;strong&gt;DOM Mini Project #1 – Bulb ON/OFF Toggle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Project Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This beginner-friendly DOM project simulates a simple Bulb ON/OFF Toggle using JavaScript. Clicking the button switches the bulb image between ON and OFF states while updating the button text accordingly. This project helped me understand DOM manipulation, event handling, conditional statements, and dynamically updating HTML elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;img id = "bulb" src = "https://www.w3schools.com/js/pic_bulboff.gif"&amp;gt;
    &amp;lt;button id = "btn" onclick="bulbToggle()"&amp;gt;ON&amp;lt;/button&amp;gt;

    &amp;lt;script&amp;gt;
        function bulbToggle(){
            if(document.getElementById("btn").innerText ==="ON"){
            document.getElementById("bulb").src = "https://www.w3schools.com/js/pic_bulbon.gif";
            document.getElementById("btn").innerText = "OFF";

            }else{
            document.getElementById("bulb").src = "https://www.w3schools.com/js/pic_bulboff.gif";
            document.getElementById("btn").innerText = "ON";
            }
        }
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3bxgg2cb9g1ja72fcmdh.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3bxgg2cb9g1ja72fcmdh.png" alt=" " width="195" height="217"&gt;&lt;/a&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8cucbnlx85fkml1eejdu.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8cucbnlx85fkml1eejdu.png" alt=" " width="167" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitLab Pages:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://front-end-3d9f55.gitlab.io/javascript/js-mini_projects.html" rel="noopener noreferrer"&gt;https://front-end-3d9f55.gitlab.io/javascript/js-mini_projects.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM Mini Project #2 – Counter App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Project Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This Counter App is a beginner-friendly JavaScript project that allows users to increment, decrement, and reset a counter. It helped me practice variables, functions, DOM manipulation, conditional statements, and keeping the UI synchronized with application state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;h2&amp;gt;Count : &amp;lt;span id="count"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h2&amp;gt;
    &amp;lt;button id="incrementBtn" onclick="increment()"&amp;gt;+&amp;lt;/button&amp;gt;
    &amp;lt;button id="decrementBtn" onclick="decrement()"&amp;gt;-&amp;lt;/button&amp;gt;
    &amp;lt;button id="resetBtn" onclick="reset()"&amp;gt;reset&amp;lt;/button&amp;gt;
    &amp;lt;h1&amp;gt;Counter App&amp;lt;/h1&amp;gt;

    &amp;lt;script&amp;gt;
        let count = 0;
        let countElement = document.getElementById("count");
        countElement.innerText = count;

        function updateCount() {
            countElement.innerText = count;
        }

        function increment() {
            count++;
            updateCount();
        }

        function decrement() {
            if (count &amp;gt; 0) {
                count--;
                updateCount();
            }
        }

        function reset() {
            count = 0;
            updateCount();
        }
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnkc7oiuai7seb220nvd2.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnkc7oiuai7seb220nvd2.png" alt=" " width="236" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitLab Pages:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://front-end-3d9f55.gitlab.io/javascript/counterapp.html" rel="noopener noreferrer"&gt;https://front-end-3d9f55.gitlab.io/javascript/counterapp.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM Mini Project #3 – Live Character Counter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Project Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This Live Character Counter updates the character count instantly as the user types into a textarea. It helped me understand real-time event handling, DOM updates, and working with string properties in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Live Character Counter&amp;lt;/h1&amp;gt;

    &amp;lt;textarea id="text" oninput="textArea()"&amp;gt;&amp;lt;/textarea&amp;gt;

    &amp;lt;p&amp;gt;Characters : &amp;lt;span id="counter"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;

    &amp;lt;script&amp;gt;
        let counterElement = document.getElementById("counter");
        let textElement = document.getElementById("text");

        counterElement.innerText = textElement.value.length;

        function textArea() {
            counterElement.innerText = textElement.value.length;
        }
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl124lwnuxaxqbb4zukc8.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl124lwnuxaxqbb4zukc8.png" alt=" " width="399" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitLab Pages:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://front-end-3d9f55.gitlab.io/javascript/liveCharCount.html" rel="noopener noreferrer"&gt;https://front-end-3d9f55.gitlab.io/javascript/liveCharCount.html&lt;/a&gt;&lt;/p&gt;

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