<?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: Mohana Kumar</title>
    <description>The latest articles on DEV Community by Mohana Kumar (@mohana_kumar_m).</description>
    <link>https://dev.to/mohana_kumar_m</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3689421%2Fea6f8860-7406-461a-8aaf-18a546618075.png</url>
      <title>DEV Community: Mohana Kumar</title>
      <link>https://dev.to/mohana_kumar_m</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohana_kumar_m"/>
    <language>en</language>
    <item>
      <title>Stop Using Callbacks! Learn JavaScript Promises Today</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Mon, 30 Mar 2026 03:32:49 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/stop-using-callbacks-learn-javascript-promises-today-noj</link>
      <guid>https://dev.to/mohana_kumar_m/stop-using-callbacks-learn-javascript-promises-today-noj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Handling asynchronous operations is one of the most important parts of JavaScript. Before promises, developers relied heavily on callbacks, which often led to messy and hard-to-read code.&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;Promises&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;A Promise in JavaScript is an object that represents the &lt;strong&gt;eventual completion (or failure)&lt;/strong&gt; of an asynchronous operation.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Promise?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Promise&lt;/strong&gt; is like a guarantee that something will happen in the future.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-Life Analogy:
&lt;/h3&gt;

&lt;p&gt;Imagine you ordered food online &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pending&lt;/strong&gt; → Food is being prepared&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fulfilled&lt;/strong&gt; → Food delivered&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rejected&lt;/strong&gt; → Order canceled&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Promise States
&lt;/h2&gt;

&lt;p&gt;A Promise has three states:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pending&lt;/strong&gt;  → Initial state&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fulfilled&lt;/strong&gt;  → Operation successful&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rejected&lt;/strong&gt;  → Operation failed&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Creating a Promise
&lt;/h2&gt;

&lt;p&gt;You can create a Promise using the &lt;code&gt;Promise&lt;/code&gt; constructor.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```javascript id="y9m9y5"&lt;br&gt;
const myPromise = new Promise((resolve, reject) =&amp;gt; {&lt;br&gt;
  let success = true;&lt;/p&gt;

&lt;p&gt;if (success) {&lt;br&gt;
    resolve("Operation successful!");&lt;br&gt;
  } else {&lt;br&gt;
    reject("Operation failed!");&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

##  Consuming a Promise

You handle promises using `.then()` and `.catch()`.



```javascript id="b7y6cf"
myPromise
  .then((result) =&amp;gt; {
    console.log(result);
  })
  .catch((error) =&amp;gt; {
    console.log(error);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Promise Chaining
&lt;/h2&gt;

&lt;p&gt;Promises allow chaining multiple async operations cleanly.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```javascript id="u5q7w2"&lt;br&gt;
new Promise((resolve) =&amp;gt; {&lt;br&gt;
  resolve(2);&lt;br&gt;
})&lt;br&gt;
  .then((num) =&amp;gt; {&lt;br&gt;
    return num * 2;&lt;br&gt;
  })&lt;br&gt;
  .then((num) =&amp;gt; {&lt;br&gt;
    return num * 3;&lt;br&gt;
  })&lt;br&gt;
  .then((num) =&amp;gt; {&lt;br&gt;
    console.log(num); // 12&lt;br&gt;
  });&lt;/p&gt;

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


---

##  Handling Errors

Errors can be handled using `.catch()`.



```javascript id="8j9k2x"
new Promise((resolve, reject) =&amp;gt; {
  reject("Something went wrong!");
})
  .then((res) =&amp;gt; console.log(res))
  .catch((err) =&amp;gt; console.log(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Promise vs Callback
&lt;/h2&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;Callback&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;Readability&lt;/td&gt;
&lt;td&gt;Hard (callback hell)&lt;/td&gt;
&lt;td&gt;Clean &amp;amp; structured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error Handling&lt;/td&gt;
&lt;td&gt;Difficult&lt;/td&gt;
&lt;td&gt;Easy with &lt;code&gt;.catch()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chaining&lt;/td&gt;
&lt;td&gt;Not easy&lt;/td&gt;
&lt;td&gt;Easy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Why Use Promises?
&lt;/h2&gt;

&lt;p&gt;✔ Avoid callback hell&lt;br&gt;
✔ Better readability&lt;br&gt;
✔ Easier error handling&lt;br&gt;
✔ Cleaner async code&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use Promises
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;API calls &lt;/li&gt;
&lt;li&gt;Database operations &lt;/li&gt;
&lt;li&gt;File handling &lt;/li&gt;
&lt;li&gt;Timers &lt;/li&gt;
&lt;/ul&gt;




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

&lt;ul&gt;
&lt;li&gt;Promises simplify asynchronous programming in JavaScript&lt;/li&gt;
&lt;li&gt;They replace messy callbacks with clean, readable code&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Confused About Sync vs Async JavaScript? Read This!</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Fri, 27 Mar 2026 17:16:03 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/confused-about-sync-vs-async-javascript-read-this-289c</link>
      <guid>https://dev.to/mohana_kumar_m/confused-about-sync-vs-async-javascript-read-this-289c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript is one of the most popular programming languages used for building web applications. One of the most important concepts every developer must understand is &lt;strong&gt;how JavaScript executes code&lt;/strong&gt; — specifically, the difference between &lt;strong&gt;synchronous&lt;/strong&gt; and &lt;strong&gt;asynchronous&lt;/strong&gt; behavior.&lt;/p&gt;

&lt;p&gt;Understanding this will help you write faster, more efficient, and non-blocking applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Synchronous JavaScript?
&lt;/h2&gt;

&lt;p&gt;Synchronous JavaScript means that code is executed &lt;strong&gt;line by line, in order&lt;/strong&gt;. Each task must complete before the next one begins.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Idea:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;One task at a time — blocking execution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example:
&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Second&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Third&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;
  
  
  Output:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First
Second
Third
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Simple and easy to understand&lt;/li&gt;
&lt;li&gt;Predictable execution order&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Blocks execution&lt;/li&gt;
&lt;li&gt;Can make applications slow if tasks take time&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What is Asynchronous JavaScript?
&lt;/h2&gt;

&lt;p&gt;Asynchronous JavaScript allows tasks to run &lt;strong&gt;in the background&lt;/strong&gt;, without blocking the main thread. This means other code can continue executing while waiting for a task to complete.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Idea:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Non-blocking execution — multiple tasks handled efficiently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example:
&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&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;Second&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;Third&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;
  
  
  Output:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First
Third
Second
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Faster and more efficient&lt;/li&gt;
&lt;li&gt;Improves user experience&lt;/li&gt;
&lt;li&gt;Prevents UI freezing&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Slightly harder to understand&lt;/li&gt;
&lt;li&gt;Requires handling callbacks or promises&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Synchronous vs Asynchronous — Key Differences
&lt;/h2&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;Synchronous&lt;/th&gt;
&lt;th&gt;Asynchronous&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Execution&lt;/td&gt;
&lt;td&gt;One after another&lt;/td&gt;
&lt;td&gt;Runs in background&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Blocking&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Slower for heavy tasks&lt;/td&gt;
&lt;td&gt;Faster &amp;amp; efficient&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complexity&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;Slightly complex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use Cases&lt;/td&gt;
&lt;td&gt;Simple logic&lt;/td&gt;
&lt;td&gt;APIs, timers, I/O tasks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




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

&lt;h3&gt;
  
  
  Synchronous:
&lt;/h3&gt;

&lt;p&gt;Cooking one dish at a time — you wait until it’s done before starting the next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asynchronous:
&lt;/h3&gt;

&lt;p&gt;Ordering food and doing other work while waiting for delivery.&lt;/p&gt;







&lt;h2&gt;
  
  
  When to Use What?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use Synchronous:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simple calculations&lt;/li&gt;
&lt;li&gt;Sequential operations&lt;/li&gt;
&lt;li&gt;Small scripts&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use Asynchronous:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;API calls&lt;/li&gt;
&lt;li&gt;File handling&lt;/li&gt;
&lt;li&gt;Database operations&lt;/li&gt;
&lt;li&gt;Timers and delays&lt;/li&gt;
&lt;li&gt;Network requests&lt;/li&gt;
&lt;/ul&gt;







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

&lt;ul&gt;
&lt;li&gt;JavaScript is &lt;strong&gt;synchronous by default&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Asynchronous programming makes it &lt;strong&gt;powerful and efficient&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Mastering async concepts is essential for modern web development&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript Closures Made Easy: Understand in 10 Minutes</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Fri, 27 Mar 2026 03:55:53 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/javascript-closures-made-easy-understand-in-10-minutes-29g6</link>
      <guid>https://dev.to/mohana_kumar_m/javascript-closures-made-easy-understand-in-10-minutes-29g6</guid>
      <description>&lt;p&gt;Closures are one of the most powerful (and sometimes confusing) concepts in JavaScript. Once you understand them, a lot of advanced JavaScript patterns start to make sense.&lt;/p&gt;

&lt;p&gt;Let’s break it down in a simple way.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Closure?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;closure&lt;/strong&gt; is created when a function remembers the variables from its outer (parent) scope even after that outer function has finished executing.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
A closure lets a function &lt;strong&gt;access variables from outside its scope&lt;/strong&gt;, even later.&lt;/p&gt;




&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&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;outerFunction&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, Bonda!&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;innerFunction&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;innerFunction&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;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Bonda!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What’s happening here?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;outerFunction&lt;/code&gt; runs and creates a variable &lt;code&gt;message&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It returns &lt;code&gt;innerFunction&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Even after &lt;code&gt;outerFunction&lt;/code&gt; finishes, &lt;code&gt;innerFunction&lt;/code&gt; still remembers &lt;code&gt;message&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That memory is called a &lt;strong&gt;closure&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Closures Work
&lt;/h2&gt;

&lt;p&gt;Closures work because of &lt;strong&gt;lexical scope&lt;/strong&gt; in JavaScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions remember where they were created&lt;/li&gt;
&lt;li&gt;Not where they are executed&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Example: Counter
&lt;/h2&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;createCounter&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="k"&gt;return&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 2&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; is private (can’t access it directly)&lt;/li&gt;
&lt;li&gt;The inner function still remembers and updates it&lt;/li&gt;
&lt;li&gt;This is commonly used for &lt;strong&gt;data privacy&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Closures for Data Privacy
&lt;/h2&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;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="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;amount&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;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;getBalance&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;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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;account&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="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;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBalance&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1000&lt;/span&gt;
&lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&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;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBalance&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1500&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;balance&lt;/code&gt; is protected and can only be accessed via methods.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistake with Closures
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;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;i&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;/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;4
4
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; is function-scoped&lt;/li&gt;
&lt;li&gt;All functions share the same &lt;code&gt;i&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fix using &lt;code&gt;let&lt;/code&gt;:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;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;i&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;/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;
  
  
  Why Closures Are Useful
&lt;/h2&gt;

&lt;p&gt;Closures are used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data hiding / encapsulation&lt;/li&gt;
&lt;li&gt;Creating private variables&lt;/li&gt;
&lt;li&gt;Function factories&lt;/li&gt;
&lt;li&gt;Event handlers&lt;/li&gt;
&lt;li&gt;Callbacks and async code&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A closure is a function that &lt;strong&gt;remembers its outer variables&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It allows &lt;strong&gt;data persistence&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It helps in writing &lt;strong&gt;clean and modular code&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It enables &lt;strong&gt;private variables&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Closures might feel tricky at first, but once you get them, they unlock a lot of JavaScript power.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🔴🔵 Color Toggle Using Button in HTML, CSS, and JavaScript</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Wed, 25 Mar 2026 14:46:41 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/color-toggle-using-button-in-html-css-and-javascript-5c3j</link>
      <guid>https://dev.to/mohana_kumar_m/color-toggle-using-button-in-html-css-and-javascript-5c3j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This program shows how to change the color of a heading (&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;) between &lt;strong&gt;red&lt;/strong&gt; and &lt;strong&gt;blue&lt;/strong&gt; when a button is clicked using JavaScript.&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;.red&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.blue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;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="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"red"&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;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"toggleColor()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Change Color&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toggleColor&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;el&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;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&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="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. HTML
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; displays the text &lt;strong&gt;Hello&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It starts with class &lt;strong&gt;red&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A button is used to trigger the color change&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. CSS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.red&lt;/code&gt; → sets text color to red&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.blue&lt;/code&gt; → sets text color to blue&lt;/li&gt;
&lt;/ul&gt;




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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;getElementById("title")&lt;/code&gt; selects the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;classList.toggle()&lt;/code&gt; switches classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;removes current color&lt;/li&gt;
&lt;li&gt;adds the other color&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




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

&lt;ul&gt;
&lt;li&gt;Initially → 🔴 Red&lt;/li&gt;
&lt;li&gt;Click button → 🔵 Blue&lt;/li&gt;
&lt;li&gt;Click again → 🔴 Red&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;This is a simple example of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOM manipulation&lt;/li&gt;
&lt;li&gt;Event handling&lt;/li&gt;
&lt;li&gt;Using CSS classes with JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It helps beginners understand how web pages become interactive.&lt;/p&gt;




</description>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding the DOM: The Backbone of Interactive Web Development</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Wed, 25 Mar 2026 14:40:56 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/understanding-the-dom-the-backbone-of-interactive-web-development-4f00</link>
      <guid>https://dev.to/mohana_kumar_m/understanding-the-dom-the-backbone-of-interactive-web-development-4f00</guid>
      <description>&lt;h2&gt;
  
  
  What is DOM?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Document Object Model (DOM)&lt;/strong&gt; is a programming interface used in web development that represents a web page as a structured tree of objects. When a browser loads an HTML or XML document, it automatically converts it into the DOM.&lt;/p&gt;

&lt;p&gt;In simple terms, the DOM allows programming languages like JavaScript to &lt;strong&gt;access, modify, and manipulate&lt;/strong&gt; the content, structure, and styles of a webpage dynamically.&lt;/p&gt;

&lt;p&gt;Instead of treating a webpage as static text, the DOM turns it into a &lt;strong&gt;live, interactive model&lt;/strong&gt; where each element (like headings, paragraphs, images, and buttons) becomes an object that can be controlled.&lt;/p&gt;




&lt;h2&gt;
  
  
  How the DOM Works
&lt;/h2&gt;

&lt;p&gt;When a webpage is loaded:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser reads the HTML file&lt;/li&gt;
&lt;li&gt;It creates a tree-like structure (DOM tree)&lt;/li&gt;
&lt;li&gt;Each HTML element becomes a “node” (object)&lt;/li&gt;
&lt;li&gt;JavaScript can then interact with these nodes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, a simple HTML structure:&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;Becomes a DOM tree where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;body&lt;/code&gt; is the parent node&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;h1&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; are child nodes&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Purpose of the DOM
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Dynamic Content Updates
&lt;/h3&gt;

&lt;p&gt;The DOM allows developers to change webpage content without reloading the page.&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="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;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!&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 makes websites interactive and responsive.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Handling User Interactions
&lt;/h3&gt;

&lt;p&gt;The DOM enables programs to respond to user actions like clicks, typing, and scrolling.&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="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;alert&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 clicked!&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;h3&gt;
  
  
  3. Modifying Styles in Real-Time
&lt;/h3&gt;

&lt;p&gt;Developers can change CSS styles dynamically using the DOM.&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="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="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lightblue&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;
  
  
  4. Navigating the Document Structure
&lt;/h3&gt;

&lt;p&gt;The DOM allows traversal between elements such as parent, child, and sibling nodes.&lt;/p&gt;

&lt;p&gt;This helps in locating and modifying specific parts of a webpage efficiently.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Creating and Deleting Elements
&lt;/h3&gt;

&lt;p&gt;The DOM allows adding or removing elements dynamically.&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;const&lt;/span&gt; &lt;span class="nx"&gt;newPara&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;newPara&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New paragraph added!&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;newPara&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  6. Foundation for Modern Web Development
&lt;/h3&gt;

&lt;p&gt;The DOM is essential for building modern, interactive web applications. Many frameworks and libraries rely heavily on DOM manipulation to update user interfaces efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  Advantages of Using DOM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Makes web pages interactive&lt;/li&gt;
&lt;li&gt;Enables real-time updates&lt;/li&gt;
&lt;li&gt;Improves user experience&lt;/li&gt;
&lt;li&gt;Allows structured access to webpage elements&lt;/li&gt;
&lt;li&gt;Supports event-driven programming&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;The Document Object Model (DOM) is a core concept in web development that transforms static web pages into dynamic, interactive applications. It acts as a bridge between HTML and programming languages, enabling developers to control and manipulate web content efficiently.&lt;/p&gt;

&lt;p&gt;Understanding the DOM is essential for anyone learning web development, as it forms the foundation for creating modern, responsive, and user-friendly websites.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding var, let, and const in JavaScript: A Complete Beginner-Friendly Guide</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Fri, 13 Feb 2026 17:45:30 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/understanding-var-let-and-const-in-javascript-a-complete-beginner-friendly-guide-2pb1</link>
      <guid>https://dev.to/mohana_kumar_m/understanding-var-let-and-const-in-javascript-a-complete-beginner-friendly-guide-2pb1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to var in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, var is used to declare variables. It was the original way to create variables before let and const were introduced in ES6 (2015).&lt;br&gt;
Although still supported, var behaves differently from let and const. Understanding how it works is important, especially when reading older JavaScript code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historical Background of var&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before ES6, var was the only keyword available for declaring variables in JavaScript. Developers relied entirely on it to store and manage data in their programs. With the release of ES6, let and const were introduced to fix several limitations of var.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Scope Behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most important characteristics of var is that it is function-scoped, not block-scoped. This means a variable declared with var inside a block (such as an if statement or loop) is still accessible outside that block, as long as it is within the same function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;if (true) {
    var message = "Hello";
}

console.log(message); // "Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hoisting in var&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables declared with var are hoisted. This means their declarations are moved to the top of their scope before code execution. However, only the declaration is hoisted — not the value. The variable is initialized with undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;console.log(name); // undefined
var name = "John";

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Redeclaration and Reassignment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another difference is that var allows both redeclaration and reassignment within the same scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var count = 5;
var count = 10; // Allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
This flexibility can sometimes create unexpected bugs in larger applications.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to let in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, let is used to declare variables. It was introduced in ES6 (2015) as an improved alternative to var.&lt;/p&gt;

&lt;p&gt;Unlike var, let follows block scope rules and helps prevent common mistakes in variable handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historical Background of let&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before ES6, developers only had var for declaring variables. However, var had issues such as lack of block scope and unexpected hoisting behavior. To solve these problems, ES6 introduced let and const to provide safer and more predictable variable declarations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Scope Behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most important characteristics of let is that it is block-scoped. This means a variable declared with let inside a block (such as an if statement or loop) is only accessible within that block.&lt;br&gt;
&lt;strong&gt;Example:&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;if (true) {
    let message = "Hello";
}

console.log(message); // Error

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
Here, message cannot be accessed outside the if block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hoisting in let&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables declared with let are hoisted, but they are not initialized. They exist in something called the Temporal Dead Zone (TDZ) from the start of the block until the declaration line.&lt;br&gt;
&lt;strong&gt;Example:&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;console.log(name); // Error
let name = "John";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
Unlike var, let does not initialize the variable with undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redeclaration and Reassignment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;let allows reassignment but does not allow redeclaration within the same scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let count = 5;
count = 10; // Allowed

let count = 20; // Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
This prevents accidental overwriting of variables.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to const in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, const is used to declare variables whose values should not be reassigned. It was also introduced in ES6 (2015).&lt;/p&gt;

&lt;p&gt;const provides a way to create constant references, making code more predictable and secure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historical Background of const&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before ES6, JavaScript did not have a proper way to declare constant variables. Developers often relied on naming conventions (such as uppercase variable names). ES6 introduced const to officially support constant declarations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Scope Behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like let, const is block-scoped. A variable declared with const is only accessible within the block where it is defined.&lt;br&gt;
&lt;strong&gt;Example:&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;if (true) {
    const message = "Hello";
}

console.log(message); // Error

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hoisting in const&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables declared with const are hoisted but not initialized. They also follow the Temporal Dead Zone rule.&lt;br&gt;
&lt;strong&gt;Example:&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;console.log(pi); // Error
const pi = 3.14;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Redeclaration and Reassignment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;const does not allow redeclaration or reassignment.&lt;br&gt;
&lt;strong&gt;Example:&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;const count = 5;
count = 10; // Error

const count = 20; // Error

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Importance of Understanding var,let,const
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;var&lt;/strong&gt;&lt;br&gt;
Even though modern JavaScript development mainly uses let and const, understanding var is essential. Many existing projects and older codebases still use it. Knowing how it behaves helps developers read, debug, and maintain legacy code effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;let&lt;/strong&gt;&lt;br&gt;
let is widely used in modern JavaScript development. It is preferred when the value of a variable needs to change during program execution. Understanding let helps developers write cleaner and more maintainable code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;const&lt;/strong&gt;&lt;br&gt;
In modern JavaScript development, const is often used by default. Developers use const whenever the variable reference should not change. This helps make programs safer and easier to understand.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>learning</category>
      <category>basic</category>
      <category>programming</category>
    </item>
    <item>
      <title>what is HTML tags and usage and basic HTML tags</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Mon, 05 Jan 2026 17:53:30 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/what-is-html-tags-and-usage-and-basic-html-tags-33ng</link>
      <guid>https://dev.to/mohana_kumar_m/what-is-html-tags-and-usage-and-basic-html-tags-33ng</guid>
      <description>&lt;p&gt;WHAT IS HTML TAGS?&lt;/p&gt;

&lt;p&gt;An HTML tag tells the browser how to display or handle content.&lt;/p&gt;

&lt;p&gt;Basic tag structure&lt;/p&gt;

&lt;p&gt;&amp;lt;tagname&amp;gt; opening tag&lt;br&gt;
&amp;lt;/tagname&amp;gt; closing tag&lt;/p&gt;

&lt;p&gt;USAGE OF TAGS?&lt;/p&gt;

&lt;p&gt;HTML tags are used to create, structure, and format content on a web page. Each tag has a specific purpose.&lt;/p&gt;

&lt;p&gt;Basic html tags&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&amp;lt;HTML&amp;gt;&lt;br&gt;
Usage: Defines the beginning and end of an HTML document.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&amp;lt;head&amp;gt;&lt;br&gt;
Usage: Contains meta information like title, styles, and scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&amp;lt;title&amp;gt;&lt;br&gt;
Usage: Sets the title of the webpage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&amp;lt;body&amp;gt;&lt;br&gt;
Usage: Holds all visible content of the webpage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&amp;lt;h1&amp;gt;&lt;br&gt;
Usage: Used for headings.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>WHAT IS HTML?WHAT IS MARKUP LANGUAGE?</title>
      <dc:creator>Mohana Kumar</dc:creator>
      <pubDate>Fri, 02 Jan 2026 16:16:35 +0000</pubDate>
      <link>https://dev.to/mohana_kumar_m/what-is-htmlwhat-is-mark-language-56e4</link>
      <guid>https://dev.to/mohana_kumar_m/what-is-htmlwhat-is-mark-language-56e4</guid>
      <description>&lt;p&gt;FOUNDER OF HTML&lt;br&gt;
The founder of HTML is Tim Berners-Lee.&lt;br&gt;
YEAR:1991&lt;/p&gt;

&lt;p&gt;WHAT IS HTML?&lt;/p&gt;

&lt;p&gt;HTML stands for Hype Text Markup Language.&lt;br&gt;
It is the standard language used to create web pages. &lt;br&gt;
HTML tells a web browser what content to show and how it is structured, like headings, paragraphs, images, links, and buttons.&lt;/p&gt;

&lt;p&gt;What HTML does?&lt;/p&gt;

&lt;p&gt;Creates headings and text&lt;br&gt;
Adds images and videos&lt;br&gt;
Makes links to other pages&lt;br&gt;
Builds forms and buttons&lt;/p&gt;

&lt;p&gt;WHAT IS MARKUP LANGUAGE?&lt;/p&gt;

&lt;p&gt;A markup language is a system of tags used to structure, format, and describe content in a document.&lt;/p&gt;

&lt;p&gt;Common markup languages:&lt;br&gt;
HTML &lt;br&gt;
XML &lt;br&gt;
Markdown.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
