<?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: Hariharan S J</title>
    <description>The latest articles on DEV Community by Hariharan S J (@hariharan_sj_584ad73ef2e).</description>
    <link>https://dev.to/hariharan_sj_584ad73ef2e</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%2F3695479%2Ff5a31cc0-fa01-479f-8676-bc16b7d1d5ad.png</url>
      <title>DEV Community: Hariharan S J</title>
      <link>https://dev.to/hariharan_sj_584ad73ef2e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hariharan_sj_584ad73ef2e"/>
    <language>en</language>
    <item>
      <title>React Essentials: NPM, NPX, JSX Rules, Fragments &amp; More</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Fri, 17 Apr 2026 10:32:53 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/react-essentials-npm-npx-jsx-rules-fragments-more-1nm4</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/react-essentials-npm-npx-jsx-rules-fragments-more-1nm4</guid>
      <description>&lt;h2&gt;
  
  
  1. What is mean by npm?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;NPM- Node Package Manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;NPM is a package manager used to install and manage dependencies in a React project.&lt;/p&gt;

&lt;p&gt;In React (and JavaScript in general), npm is a tool used to install, manage, and share packages (libraries or tools).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of npm like an app store for developers&lt;br&gt;
Instead of downloading everything manually, you just run a command and install what you need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What NPM does in React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you build a React app, you don’t write everything from scratch. You use packages like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React itself&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Routing libraries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;UI libraries&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;npm helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install them → npm install&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update them → npm update&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove them → npm uninstall&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This file keeps track of all installed packages&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managed by npm automatically&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. What is mean by NPX?
&lt;/h2&gt;

&lt;p&gt;NPX stands for Node Package Execute&lt;/p&gt;

&lt;p&gt;NPX is a tool used to execute Node packages instantly without installing them globally.&lt;/p&gt;

&lt;p&gt;NPX is used to run packages without installing them permanently&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why we need NPX?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before NPX&lt;/p&gt;

&lt;p&gt;If you want to use a tool, you had to install it first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install create-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With NPX&lt;/p&gt;

&lt;p&gt;You can directly run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No need to install it globally!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens internally?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NPX will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Check if the package is already installed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If not → download it temporarily&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove it (or cache it)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real-life analogy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;NPM = Buying a software and installing it on your laptop&lt;/p&gt;

&lt;p&gt;NPX = Using an app online without installing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Difference between npm and npx&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What is dev in npm run dev?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;dev is a custom script name in package.json used to run the project in development mode.&lt;/p&gt;

&lt;p&gt;dev is just a script name&lt;/p&gt;

&lt;p&gt;It is not a keyword in npm&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does dev come from?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inside your project, there is a file:&lt;/p&gt;

&lt;p&gt;package.json&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 plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "dev": "vite",
    "start": "react-scripts start",
    "build": "vite build"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens when you run:&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;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NPM will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to package.json&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Look inside "scripts"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find "dev"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Execute the command assigned to it&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this case:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;So what does dev usually mean?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;dev = development mode&lt;/p&gt;

&lt;p&gt;Used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Running your app locally&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Live reload (auto refresh)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fast development&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example (React with Vite)&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;"scripts": {
  "dev": "vite"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;/div&gt;



&lt;p&gt;Starts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local server (like &lt;a href="http://localhost:5173" rel="noopener noreferrer"&gt;http://localhost:5173&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-Life Analogy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;scripts = Remote control buttons&lt;/p&gt;

&lt;p&gt;dev = One button name&lt;/p&gt;

&lt;p&gt;npm run dev = Pressing that button&lt;/p&gt;

&lt;h2&gt;
  
  
  3. What is Fragment in React?
&lt;/h2&gt;

&lt;p&gt;A Fragment is used to group multiple elements without adding extra HTML tags to the DOM&lt;/p&gt;

&lt;p&gt;A Fragment in React lets you group multiple elements without adding extra nodes to the DOM.&lt;/p&gt;

&lt;p&gt;Why Fragment is needed?&lt;/p&gt;

&lt;p&gt;In React, you cannot return multiple elements directly&lt;/p&gt;

&lt;p&gt;This will give error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React needs one parent element&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution 1 (normal way)&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;return (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
  &amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adds extra  in DOM (not always needed)


&lt;p&gt;&lt;strong&gt;Solution 2 (Fragment)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;React.Fragment&amp;gt;
    &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
  &amp;lt;/React.Fragment&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;No extra DOM element created&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short Syntax (most used)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;&amp;gt;
    &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
  &amp;lt;/&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This is called Fragment shorthand&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Fragment is important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keeps DOM clean&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Avoids unnecessary &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves performance slightly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Useful in tables, lists, layouts&lt;/p&gt;&lt;/li&gt;


&lt;p&gt;&lt;strong&gt;Real-Life Analogy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fragment = Invisible box &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Holds items&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But you can’t see the box&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4.Rules of JSX
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Must return a single parent element&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/ul&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;



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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;World&amp;lt;/p&amp;gt;
  &amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Every tag must be properly closed&lt;/li&gt;
&lt;/ul&gt;

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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="image.png"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="image.png" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;JSX is strict (like XML)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use className instead of class&lt;/li&gt;
&lt;/ul&gt;

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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="box"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="box"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Because class is a JavaScript keyword&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inline styles must be objects&lt;/li&gt;
&lt;/ul&gt;

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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div style="color: red;"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



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

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div style={{ color: "red" }}&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Double {}:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Outer = JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inner = object&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5.Final Takeaway
&lt;/h2&gt;

&lt;p&gt;Understanding core concepts like NPM, NPX, JSX, Fragments, and React’s control flow builds a strong foundation for developing modern React applications efficiently.&lt;/p&gt;


&lt;/li&gt;

&lt;/ul&gt;
&lt;br&gt;
&lt;br&gt;


</description>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>From Basics to Brilliance: React, SPAs, MPAs &amp; More</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Thu, 16 Apr 2026 11:30:22 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/from-basics-to-brilliance-react-spas-mpas-more-46bg</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/from-basics-to-brilliance-react-spas-mpas-more-46bg</guid>
      <description>&lt;h2&gt;
  
  
  1. What is React?
&lt;/h2&gt;

&lt;p&gt;React is a JavaScript library for building fast, interactive, and reusable user interfaces using components.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Key Difference Between React and JavaScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A programming language used to build logic for web pages (and more)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A library built using JavaScript to create UI components&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handles logic, events, API calls, calculations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works everywhere (frontend + backend with Node.js)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specifically used for building user interfaces (UI)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Focuses on rendering and updating the view&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DOM Handling&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Direct DOM manipulation (can get complex)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Uses Virtual DOM (TBD) for efficient updates &lt;/p&gt;

&lt;p&gt;JavaScript is a programming language used to build web functionality, while React is a JavaScript library used specifically for building user interfaces in a more efficient and structured way.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Why We Use React
&lt;/h2&gt;

&lt;p&gt;React is mainly used to build fast, scalable, and maintainable user interfaces. Here’s the real reasoning behind it&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To Build Complex UIs Easily&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Plain Javascript&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;UI becomes messy as the app grows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Too many DOM manipulations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React solves this with components&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Break UI into small reusable parts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy to manage large applications&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reusability (Write Once, Use Many Times)&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Button component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Card component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navbar&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You create once and reuse everywhere&lt;/p&gt;

&lt;p&gt;Saves time&lt;/p&gt;

&lt;p&gt;Reduces duplicate code&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What is a Single Page Application (SPA) in React
&lt;/h2&gt;

&lt;p&gt;A Single Page Application (SPA) in React is a web application that loads a single HTML page and dynamically updates content without reloading the entire page, providing a fast and seamless user experience&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works in React&lt;/strong&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Only one main HTML file is loaded (index.html)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React controls everything inside it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you navigate:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;React updates components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No full page reload happens&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No full page reload happens&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example (Real Life)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Instagram&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gmail&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you click:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home → Profile → Messages&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Page doesn’t reload&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only content changes&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s an SPA behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of SPA&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Faster navigation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better user experience&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Less server load after first load&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Feels like a mobile app&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Initial load can be slow&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SEO can be tricky&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requires JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5.What is a Multi Page Application (MPA)?
&lt;/h2&gt;

&lt;p&gt;A Multi Page Application (MPA) is a type of web application where every action loads a new HTML page from the server.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Every time you click something, the whole page reloads.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;User clicks a link (e.g., Home → About)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Browser sends request to server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server sends a new HTML page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Browser reloads the entire page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example (Real Life)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Amazon (when switching pages)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Old-style websites&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each click = full page refresh&lt;/p&gt;

&lt;p&gt;You can actually see the page loading&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of MPA&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Better for SEO&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple architecture&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each page is independent&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Slower navigation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Full page reload every time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not as smooth as SPA&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Easy Analogy&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;MPA = Opening a new book page every time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SPA = Scrolling inside the same page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6.Libraries vs Frameworks (Key Difference)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Library&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A collection of pre-written functions that you call when needed&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Framework&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A complete structure that calls your code and controls the flow&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the core concept:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Library → You are in control&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Framework → It is in control&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Using React&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&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;You decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;when to create components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;how to structure your app&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You control the flow&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Framework Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using Angular&lt;/p&gt;

&lt;p&gt;Angular decides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;folder structure&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;architecture&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;how components interact&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Framework controls everything&lt;/p&gt;

&lt;p&gt;In Simple Words We Can Say That&lt;/p&gt;

&lt;p&gt;A library is a set of tools that developers call when needed, while a framework provides a complete structure and controls the flow of the application using inversion of control.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inversion Of Control (TBD)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So far you are thinking react is a javascript library and it is not a framework what if i tell you react can be used as a framework by using React Native&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Native(TBD)&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I Built a To Do App with JavaScript — Features, Challenges &amp; What's Next</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Tue, 07 Apr 2026 11:45:03 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/how-i-built-a-to-do-app-with-javascript-features-challenges-whats-next-18am</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/how-i-built-a-to-do-app-with-javascript-features-challenges-whats-next-18am</guid>
      <description>&lt;h2&gt;
  
  
  1.Introduction
&lt;/h2&gt;

&lt;p&gt;Every developer has that one project they keep coming back to — the classic Todo App. It sounds simple on the surface, but building one from scratch teaches you a surprising amount about DOM manipulation, state management, browser storage, and UI design. In this blog, I'll walk you through how I built my own Todo App using pure HTML, CSS, and JavaScript — no frameworks, no libraries (except a little confetti surprise). I'll talk about the features I built, the decisions I made along the way, and the improvements I plan to add in the future.&lt;/p&gt;

&lt;h1&gt;
  
  
  2.Why a Todo App?
&lt;/h1&gt;

&lt;p&gt;Before diving in, you might be wondering — why another Todo App? The honest answer is that it's one of the best exercises for a frontend developer. A Todo App forces you to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How to add, update, and remove items dynamically in the DOM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to persist data so it survives a page refresh&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to track state and reflect it visually in real time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to style a UI that actually feels good to use&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's the perfect project to solidify your core JavaScript skills before jumping into frameworks like React or Vue.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Tech Stack
&lt;/h2&gt;

&lt;p&gt;I intentionally kept this project framework-free to focus on the fundamentals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML5 — Semantic structure and layout&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS3 — Custom dark theme using CSS variables, flexbox, and smooth transitions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript — All the logic: DOM manipulation, event handling, and localStorage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;@hiseb/confetti — A lightweight CDN library for the celebration animation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No build tools, no npm install, no webpack. Just three files and a browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.Features I Built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Adding Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The core feature — a text input and a + button. When the user types a task and clicks the button (or submits the form), the task gets pushed into a tasks array as an object { text, completed: false }, and the list re-renders.&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;addTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;taskInput&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="s1"&gt;taskInput&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;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;taskInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;completed&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="nf"&gt;updateTasksList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;updateStats&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;saveTasks&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;taskInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used .trim() to avoid saving empty or whitespace-only tasks — a small but important detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Completing Tasks (Toggle)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each task has a checkbox. When checked, it toggles the completed boolean on the task object and re-renders the list. Completed tasks display with a teal strikethrough to visually distinguish them from pending ones.&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;toggleTastComplete&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;updateTasksList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;updateStats&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;saveTasks&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 CSS handles the visual:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.completed&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;line-through&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="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--teal&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;&lt;strong&gt;Editing Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clicking the edit icon on any task loads its text back into the input field and removes it from the list. This lets the user modify it and re-add it with the + button. It's a simple but effective pattern.&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;editTask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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;taskInput&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="s1"&gt;taskInput&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;taskInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;updateTasksList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;updateStats&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;saveTasks&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;&lt;strong&gt;Deleting Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A delete icon removes a task permanently from the array using splice(). The list and stats update immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress Bar &amp;amp; Stats Counter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was one of my favourite parts to build. There's a live progress bar that fills up as you complete tasks, and a circular stats counter showing completed / total.&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;updateStats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completeTasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&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;totalTasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;progress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;completeTasks&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;totalTasks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&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;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;progress&lt;/span&gt;&lt;span class="dl"&gt;'&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;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;%`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="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="s1"&gt;numbers&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;completeTasks&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; / &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;totalTasks&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The progress bar uses a CSS transition for a smooth animation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nf"&gt;#progress&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt; &lt;span class="n"&gt;ease&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;&lt;strong&gt;Confetti Celebration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My favourite Easter egg — when every single task is checked off, the app fires a confetti animation using the @hiseb/confetti CDN library. It's a small touch that makes the app feel rewarding to use.&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;completeTasks&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;totalTasks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;blaskConfetti&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;&lt;strong&gt;Persistent Storage with localStorage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tasks are saved to the browser's localStorage so they survive a page refresh. Every time the user adds, edits, deletes, or completes a task, the updated array is serialized and saved.&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;saveTasks&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="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tasks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tasks&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;On page load, tasks are retrieved and the UI is rebuilt:&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;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;storedTasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tasks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;storedTasks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;storedTasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;task&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;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="nf"&gt;updateTasksList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;updateStats&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;&lt;strong&gt;UI Design Decisions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I went with a deep navy dark theme that feels clean and modern. The colour palette is defined with CSS variables, making it easy to adjust globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#000430&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--secondaryBackground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#171c48&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--purple&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#828dff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--teal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#24feee&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 purple is used for borders, buttons, and the stats circle. The teal is reserved for active/completed states and the progress bar — creating a clear visual hierarchy. The rounded corners and consistent padding make everything feel polished without overcomplicating the CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.Challenges I Faced
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;DOM Re-rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every time a task is added, deleted, edited, or toggled, I clear the entire innerHTML of the task list and re-render everything from scratch. This is simple and effective for small lists, but not efficient for larger ones (more on this in future improvements).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inline Event Handlers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since task items are built with innerHTML, I used inline onclick attributes to attach event handlers. This works fine but isn't ideal — a better approach would be event delegation on the parent list element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope Issue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's a subtle bug in the original code — the stats calculation at the top of the file runs before any tasks exist, so it always computes 0 / 0. Moving all initial logic inside the DOMContentLoaded handler or inside updateStats() (which is already correctly placed) would fix this cleanly.&lt;/p&gt;

&lt;h2&gt;
  
  
  6.What I Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;localStorage is incredibly easy to use and a great first step into data persistence before touching databases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS variables make theming clean and maintainable — I'll use them in every project going forward.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;State management in JS is about maintaining a single source of truth (the tasks array) and always rendering from it, rather than trying to read state from the DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Small UX details — like transitions, strikethroughs, and confetti — make a huge difference in how a project feels to use.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7.Future Improvements
&lt;/h2&gt;

&lt;p&gt;There's a lot I'd love to add to make this app more production-ready:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Due dates — Add an optional date picker to each task&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Priority levels — Mark tasks as Low, Medium, or High priority with colour coding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Task categories / tags — Organise tasks into groups like Work, Personal, Shopping&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backend + user accounts — Move from localStorage to a real database so tasks sync across devices&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recurring tasks — Set tasks to repeat daily, weekly, or monthly&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You Can Check My To Do List By Clicking The Below Link&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://my-to-do-list-sable.vercel.app/" rel="noopener noreferrer"&gt;To Do List&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8.Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Building this Todo App was a great exercise in keeping things simple while still producing something genuinely useful.JavaScript gets a lot less credit than it deserves — you don't always need a framework to build something clean and functional&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Simple Calculator App using HTML, CSS &amp; JavaScript</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Mon, 06 Apr 2026 05:10:21 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/building-a-simple-calculator-app-using-html-css-javascript-41fh</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/building-a-simple-calculator-app-using-html-css-javascript-41fh</guid>
      <description>&lt;h2&gt;
  
  
  1.Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog, I will walk you through how I built a simple calculator web application using HTML, CSS, and JavaScript. This project is beginner-friendly and helped me understand core concepts like DOM manipulation, event handling, and basic JavaScript logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Technologies Used
&lt;/h2&gt;

&lt;p&gt;To build this calculator app, I used the following technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML – for structuring the calculator layout&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS – for styling and designing the user interface&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript – for implementing functionality and calculations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3.HTML Structure
&lt;/h2&gt;

&lt;p&gt;The HTML file defines the layout of the calculator.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A container to hold the calculator&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An input field (#finalinput) to display user input and results&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Buttons for numbers, operators, and actions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each button uses the onclick attribute to perform actions like adding numbers or operators to the display.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.CSS Design
&lt;/h2&gt;

&lt;p&gt;The CSS file is used to make the calculator visually appealing.&lt;/p&gt;

&lt;p&gt;Key styling features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Flexbox to center the calculator on the screen&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dark theme UI for a modern look&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Box shadows for a soft 3D effect&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rounded buttons for better user experience&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Operators are highlighted using a different color to make them stand out.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.JavaScript Logic
&lt;/h2&gt;

&lt;p&gt;The logic of the calculator is handled using JavaScript inside the HTML file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a button is clicked, its value is added to the display:&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;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;7&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;Clear Function (AC)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This clears the entire display:&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;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&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;Delete Function (DE)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This removes the last character from the display:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation (=)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The result is calculated using:&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;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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;What is eval() in JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The eval() function in JavaScript is used to evaluate a string as a JavaScript expression.&lt;/p&gt;

&lt;p&gt;In simple terms, it takes a string input and executes it like actual JavaScript code.&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 javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2 + 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the string "2 + 3" is converted into a real expression and evaluated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I Used eval() in My Calculator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my calculator project, I used eval() to calculate the final result when the user clicks the = button.&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;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;display&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;display.value contains a string like "5+3*2"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;eval() processes this string&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It returns the calculated result → 11&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The result is then shown on the display&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why eval() is Useful Here&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It simplifies calculation logic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No need to manually parse expressions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works for multiple operations (+, -, *, /)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quick solution for beginner projects&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6.Features of the Calculator
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Supports basic arithmetic operations (+, -, *, /)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clear (AC) button to reset input&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete (DE) button to remove last digit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decimal number support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple and clean user interface&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time display updates&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7.Challenges Faced
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Handling string-based input correctly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementing the delete functionality&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understanding how eval() works&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managing user input dynamically&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8.Future Improvements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keyboard input support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scientific functions (sin, cos, log, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculation history feature&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dark/Light mode toggle&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better error handling for invalid inputs&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9.What I Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DOM manipulation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Event handling in JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Working with strings and expressions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;UI design using CSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building logic step-by-step&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  10.Conclusion
&lt;/h2&gt;

&lt;p&gt;Building a calculator app may seem simple, but it involves important programming concepts. This project helped me strengthen my fundamentals in web development and gave me confidence to build more complex applications in the future.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why JavaScript Doesn’t Wait: Sync vs Async Explained</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Fri, 27 Mar 2026 11:43:13 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/why-javascript-doesnt-wait-sync-vs-async-explained-428m</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/why-javascript-doesnt-wait-sync-vs-async-explained-428m</guid>
      <description>&lt;h2&gt;
  
  
  1.Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript is a single-threaded language, which means it can do only one task at a time. But if that’s true, how does it handle things like API calls, timers, or file loading without freezing the entire application?&lt;/p&gt;

&lt;p&gt;That’s where Synchronous and Asynchronous programming comes in.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll break down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What synchronous and asynchronous code means&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why JavaScript “doesn’t wait”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How it actually works behind the scenes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before Going into the synchronous and asynchronous You are all having one question which is why Javascript is a single-threaded language?&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded because:&lt;/p&gt;

&lt;p&gt;It has one call stack, meaning it can execute only one task at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But WHY was it designed like this?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Simplicity (Main Reason)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When JavaScript was created (by Brendan Eich):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It was meant to run inside the browser&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mainly to handle:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Button clicks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Form validation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple UI interactions&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, making it single-threaded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keeps things simple&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoids complex issues like thread synchronization&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript is single-threaded because it uses a single call stack to execute code one task at a time. This design simplifies execution and avoids concurrency issues like race conditions, while asynchronous behavior is handled using the event loop and browser APIs&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Simple Program for Single Thread Behaviour&lt;/strong&gt;&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;Match Started&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;batting&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;Batsman started batting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&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;0&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;1&lt;/span&gt;&lt;span class="nx"&gt;e9&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="c1"&gt;// playing long innings&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;Batsman finished batting&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bowling&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;Bowler started bowling&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;batting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;bowling&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;Match Ended&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;Match Started
Batsman started batting
Batsman finished batting
Bowler started bowling
Match Ended
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, batsman plays completely&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only after that, bowler starts bowling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Both don’t happen at the same time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One after another execution&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just like in cricket where batting must finish before bowling begins in this example, JavaScript executes one task at a time. Even if multiple functions are called, the next task waits until the current one finishes, proving that JavaScript is single-threaded&lt;/p&gt;

&lt;p&gt;Here is Where Synchronus and Asynchronus Comes to play&lt;/p&gt;

&lt;h2&gt;
  
  
  2.What is Synchronous in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Before going into the technical part of synchronus we shall understand the synchronus non technically&lt;/p&gt;

&lt;p&gt;Imagine you are eating chocolates 🍫&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You eat one chocolate&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only after finishing it → you take the next chocolate&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t eat 2 chocolates at the same time&lt;/p&gt;

&lt;p&gt;Likewise in Javascript&lt;/p&gt;

&lt;p&gt;Computer also does the same:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It does one work&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Waits till it finishes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then does the next work&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you get a idea of what synchronus actually do if we deep dive into the technical part you can clearly understand about this topic&lt;/p&gt;

&lt;p&gt;JavaScript executes code line by line using a single call stack, where each operation must complete before the next one starts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single Thread + Call Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded, so it uses:&lt;/p&gt;

&lt;p&gt;One Call Stack (Execution Stack)&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;starter&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;Starter is served 🍲&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainCourse&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;Main course is served 🍛&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dessert&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;Dessert is served 🍰&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;starter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;mainCourse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;dessert&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;Starter is served 🍲
Main course is served 🍛
Dessert is served 🍰
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;First, you eat starter 🍲&lt;/p&gt;

&lt;p&gt;Then main course 🍛&lt;/p&gt;

&lt;p&gt;Finally dessert 🍰&lt;/p&gt;

&lt;p&gt;You don’t eat everything at the same time&lt;/p&gt;

&lt;p&gt;One after another → synchronous&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blocking Nature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Synchronous code is blocking&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;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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;heavyTask&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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;0&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;1&lt;/span&gt;&lt;span class="nx"&gt;e9&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="c1"&gt;// long work&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;Heavy Task Done&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;heavyTask&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;What happens?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JS starts execution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enters heavyTask()&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stays there until loop finishes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only then moves to next line&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything else is blocked&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Context&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whenever a function runs:&lt;/p&gt;

&lt;p&gt;JavaScript creates an Execution Context&lt;/p&gt;

&lt;p&gt;Each context has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Memory (variables)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code execution phase&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Global Execution Context created first&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then function contexts are created and pushed to stack&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-World Impact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problems with synchronous code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;UI freezing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slow performance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Poor user experience&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Loading large data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Heavy calculations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;File processing&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;The Problems in Synchronus is Solved in Asynchronus So lets deep dive into Asynchronus Concept *&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3.What is Asynchronous JavaScript
&lt;/h2&gt;

&lt;p&gt;Asynchronous execution means:&lt;/p&gt;

&lt;p&gt;JavaScript can delegate long-running tasks and continue executing other code, instead of blocking the main thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How JavaScript Actually Handles Async&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript runtime consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Call Stack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web APIs (Browser / Node APIs)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Callback Queue (Task Queue)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Event Loop&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;Match Started 🏏&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;Drinks break over 🍹, match resumes&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;First over is going on...&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;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Match Started 🏏
First over is going on...
Drinks break over 🍹, match resumes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Match starts&lt;/p&gt;

&lt;p&gt;First over continues immediately&lt;/p&gt;

&lt;p&gt;Meanwhile:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drinks break is scheduled ⏳ (setTimeout)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript does NOT wait &lt;/p&gt;

&lt;p&gt;It continues the match&lt;/p&gt;

&lt;p&gt;After 2 seconds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drinks break message comes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What This Shows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even though drinks break was set:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Match didn’t stop&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Other things continued&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is asynchronous behavior&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event Loop (Heart of Async)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The event loop continuously checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Is Call Stack empty?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If yes → take task from queue → execute&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why JS feels non-blocking&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Async Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Macro Tasks (Callback Queue)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;setTimeout&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;setInterval&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DOM events&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Micro Tasks (Priority Queue)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Promises&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;queueMicrotask&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Microtasks run before macrotasks&lt;/p&gt;

&lt;p&gt;Okay this will lead up to the methods of asynchronus in Javascript&lt;/p&gt;

&lt;h2&gt;
  
  
  4.Methods Used in Asynchronous JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, async behavior is achieved using different techniques (methods):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Promise in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Promise in JavaScript is an object that represents the eventual completion or failure of an asynchronous operation, allowing developers to handle results using methods like then, catch, and finally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Structure of a Promise&lt;/strong&gt;&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;promise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;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="nx"&gt;reject&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;// async work&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It has 2 important functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;resolve() → success&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;reject() → failure&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Promise States&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pending → Initial state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fulfilled  → Success (resolve called)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rejected → Failed (reject called)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;foodOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;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="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;foodReady&lt;/span&gt; &lt;span class="o"&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foodReady&lt;/span&gt;&lt;span class="p"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your food is ready &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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sorry, food is not available &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;foodOrder&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="nx"&gt;message&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="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;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output (if foodReady = true)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your food is ready 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output (if foodReady = false)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sorry, food is not available 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;You order food&lt;/p&gt;

&lt;p&gt;Kitchen checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If food is ready → serve it (resolve) &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If not → say unavailable (reject) &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Customer (your code):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;.then() → handles success&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;.catch() → handles failure&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Promise in JavaScript is like ordering food—either the food gets delivered successfully (resolve) or the order fails (reject), and we handle both outcomes using then and catch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise Chaining&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can chain multiple .then()&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;getData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;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="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="nf"&gt;resolve&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="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;span class="nf"&gt;getData&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="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&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="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&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="nx"&gt;result&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="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each .then() passes value to next&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;async / await(To Be Discussed)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;fetch() API(To Be Discussed)&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript DOM Basics: A Beginner’s Guide</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Wed, 25 Mar 2026 10:00:09 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/javascript-dom-basics-a-beginners-guide-205c</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/javascript-dom-basics-a-beginners-guide-205c</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript DOM (Document Object Model) is a programming interface that allows developers to interact with HTML elements. It helps in making web pages dynamic by allowing changes in content, structure, and style using JavaScript. In this blog, we will learn the basics of DOM in a simple way.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is DOM?
&lt;/h2&gt;

&lt;p&gt;The DOM represents a web page as a tree structure where each element is treated as an object. Using JavaScript, we can access and modify these elements easily.&lt;/p&gt;

&lt;p&gt;HTML page → tree structure → JavaScript control pannum&lt;/p&gt;

&lt;h2&gt;
  
  
  3. DOM Structure (Tree Concept)
&lt;/h2&gt;

&lt;p&gt;The Document Object Model (DOM) represents an HTML page as a tree structure.&lt;br&gt;
Each part of the HTML document is treated as a node (object) in this tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main Parts of the DOM Tree&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Document → The entire web page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTML → Root element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Head → Contains metadata (title, links, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Body → Contains visible content&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Elements → Tags like &lt;/p&gt;
&lt;h1&gt;, &lt;/h1&gt;
&lt;p&gt;, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example HTML&lt;/strong&gt;&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;html&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&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;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;💡 Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The document is the top-level object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside it, we have the html element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The body contains all visible content&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Elements like &lt;/p&gt;
&lt;h1&gt; and &lt;/h1&gt;
&lt;p&gt; are child nodes&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This tree structure helps JavaScript easily access, modify, and update elements on a web page.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Selecting Elements (DOM Methods)
&lt;/h2&gt;

&lt;p&gt;Most important basics&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&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="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;class&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="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;p&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="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;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;Short explanation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ID → single element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;class/tag → multiple elements&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Changing Content
&lt;/h2&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;innerHTML&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 JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;innerHTML&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;textContent&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5.Creating Elements in DOM
&lt;/h2&gt;

&lt;p&gt;JavaScript allows us to create new HTML elements dynamically using the DOM. This is useful when we want to add content to a web page without reloading it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Creating a New Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use document.createElement() to create a new element.&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;newElement&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 a new &lt;/p&gt;
&lt;p&gt; element, but it is not yet visible on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Adding Content to the Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can add text using textContent or innerHTML.&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;newElement&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;This is a new paragraph&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;3. Adding the Element to the Page&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To display the element, we must append it to an existing element.&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="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newElement&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 paragraph will appear on the webpage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full Example&lt;/strong&gt;&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;newElement&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;newElement&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, this is added using 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;newElement&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;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;createElement() → creates element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;textContent → adds text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;appendChild() → adds element to page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6.Changing Attributes
&lt;/h2&gt;

&lt;p&gt;We can modify HTML attributes like id, class, or src.&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;img&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;myImage&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image2.jpg&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;Common methods&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;setAttribute()&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;getAttribute()&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;removeAttribute()&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Event Listeners
&lt;/h2&gt;

&lt;p&gt;A modern way to handle events in JavaScript.&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;btn&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;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;btn&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;h2&gt;
  
  
  8.Conclusion.
&lt;/h2&gt;

&lt;p&gt;The Document Object Model (DOM) is a fundamental concept in JavaScript that allows developers to interact with and manipulate web pages dynamically. By understanding DOM basics such as selecting elements, creating and removing elements, handling events, and modifying content and styles, beginners can start building interactive and responsive websites. Mastering the DOM is an important first step toward becoming a skilled web developer.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding JavaScript Core Concepts: Spread Operator, Constructor Functions, and Built-in Objects</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Mon, 16 Mar 2026 12:36:13 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/understanding-javascript-core-concepts-spread-operator-constructor-functions-and-built-in-objects-5994</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/understanding-javascript-core-concepts-spread-operator-constructor-functions-and-built-in-objects-5994</guid>
      <description>&lt;h2&gt;
  
  
  Spread Operator in JavaScript
&lt;/h2&gt;

&lt;p&gt;Before technical part of spread operator we shall understand the spread operator by non technically&lt;/p&gt;

&lt;p&gt;Imagine you have a bag of candies 🍬.&lt;/p&gt;

&lt;p&gt;Inside the bag there are 3 candies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[🍬, 🍬, 🍬]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you want to pour all the candies out on the table.&lt;/p&gt;

&lt;p&gt;When you open the bag and spread the candies on the table, that is like the Spread Operator (...) in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have a box:&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;box1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you open the box and spread everything into another box&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;box1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;box2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;box1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now box2 also has the same toys.&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;box2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Simple Meaning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spread Operator (...) = Open a box and spread everything inside it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now lets deep dive into the technical part of spread operator
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is Spread Operator?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Spread Operator (...) is used to expand (spread) the elements of an iterable (like an array or string) or the properties of an object into individual elements.&lt;/p&gt;

&lt;p&gt;It was introduced in ES6 (ECMAScript 2015) and is commonly used for copying, merging, and passing values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Idea of Spread Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The spread operator takes a collection and spreads its values one by one&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&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;arr&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;10 20 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;arr is an array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;...arr spreads the values inside the array&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of:&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="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="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It Becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10,20,30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Spread Operator with Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Copying an Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Normally if you copy arrays like this&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both variables point to the same memory reference&lt;/p&gt;

&lt;p&gt;So if you change b, a will also change&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Spread&lt;/strong&gt;&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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;a&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;b&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;[1,2,3]
[1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;...a creates a new copy of the array&lt;/p&gt;

&lt;p&gt;This is called Shallow Copy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Merging Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spread operator is commonly used to combine multiple arrays&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;let&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&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;arr3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;arr2&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;arr3&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;[1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;...arr1 spreads 1,2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;...arr2 spreads 3,4&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Final array becomes [1,2,3,4]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Elements While Merging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also add new values.&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;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&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="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;arr2&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;[1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spread operator does not have to be at the start.&lt;br&gt;
It can be used anywhere in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spread Operator with Objects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spread operator can also copy or merge objects&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;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&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;details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;details&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;person&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;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;...user spreads object properties&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;...details spreads other properties&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Result is a merged object&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spread Operator with Nested Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spread Operator with Nested Arrays&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;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;a&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;[[100,2],[3,4]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;The inner arrays still share memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spread operator copies only the first level&lt;/p&gt;

&lt;h2&gt;
  
  
  Constructor Function In Javascript
&lt;/h2&gt;

&lt;p&gt;before going into the technical part of constructor function lets all first understand it non technically&lt;/p&gt;

&lt;p&gt;Imagine you have a toy machine 🏭.&lt;/p&gt;

&lt;p&gt;This machine can make many toy cars 🚗.&lt;/p&gt;

&lt;p&gt;You just press a button and tell the machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Color&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the machine creates a new toy car.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Toy Machine = Constructor Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, a constructor function is like that toy-making machine.&lt;/p&gt;

&lt;p&gt;It helps us create many similar objects.&lt;/p&gt;

&lt;p&gt;Now lets understand the constructor function concept technically&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is mean by constructor function in javascript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Constructor Function in JavaScript is a special type of function used to create and initialize objects. It acts as a blueprint (template) for creating multiple objects with similar properties and methods.&lt;/p&gt;

&lt;p&gt;Constructor functions were the main way of creating objects before ES6 classes were introduced.&lt;/p&gt;

&lt;p&gt;In Another words it can say as &lt;/p&gt;

&lt;p&gt;A constructor function is simply a regular function that is used with the new keyword to create objects.&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;Person&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="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&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;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Person → constructor function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;name, age → parameters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;this → refers to the new object being created&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Creating Objects Using Constructor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create an object we use the new keyword&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;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&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;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Surya&lt;/span&gt;&lt;span class="dl"&gt;"&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;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;user1&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;user2&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;{ name: "Hari", age: 21 }
{ name: "Surya", age: 25 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we created two objects using the same constructor function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Happens Internally When new is Used&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we write:&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript performs 4 important steps internally.&lt;/p&gt;

&lt;p&gt;Step 1 — Create a new empty object&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Step 2 — Set this to the new object&lt;/p&gt;

&lt;p&gt;Inside the function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this → {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3 — Add properties to the object&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Object becomes:&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="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4 — Return the object&lt;/p&gt;

&lt;p&gt;JavaScript automatically returns the new object.&lt;/p&gt;

&lt;p&gt;Final Result&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&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;Why this is Used in Constructor Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;this refers to the object that is being created.&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;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;brand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;brand&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;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Toyota&lt;/span&gt;&lt;span class="dl"&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;car2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BMW&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;Objects Created&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;car1 → { brand: "Toyota" }
car2 → { brand: "BMW" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here this.brand stores the value in each new object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem if new is Not Used&lt;/strong&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Person&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&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;user&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;undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because:&lt;/p&gt;

&lt;p&gt;this refers to the global object, not a new object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor Naming Convention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Constructor functions usually start with a capital letter.&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 plaintext"&gt;&lt;code&gt;Person
User
Car
Student
Employee
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not mandatory but is a common JavaScript convention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Prototype with Constructor Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To avoid copying methods for every object, we use prototype.&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;Person&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&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="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="k"&gt;this&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&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;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Surya&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;sayHello exists only once in memory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All objects share it&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This improves memory efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor Function Returning Values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Normally constructors return the object automatically.&lt;/p&gt;

&lt;p&gt;But if you return another object manually:&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;Test&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&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="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;21&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Test&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;obj&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;{ age: 21 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned object replaces the default object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Constructor Functions&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create multiple objects easily&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reusable object structure&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works with prototypes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Foundation for JavaScript’s object-oriented programming&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Build In Objects In Javascript
&lt;/h2&gt;

&lt;p&gt;before going into this topic we shall discuss this topic non technically&lt;/p&gt;

&lt;p&gt;Imagine you have a magic calculator box 🧮✨.&lt;/p&gt;

&lt;p&gt;This magic box can help you do many math things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;finding the biggest number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;finding the smallest number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;rounding numbers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;giving random numbers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;finding square roots&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In JavaScript, this magic box is called the Math Object.&lt;/p&gt;

&lt;p&gt;Think 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;Math = Magic Math Box
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever you need help with math, you ask the box.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example-Biggest Number&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You ask the box:&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&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;span class="mi"&gt;10&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Box Says&lt;br&gt;
&lt;/p&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;Because 10 is the biggest.&lt;/p&gt;

&lt;p&gt;Now lets deep dive in by technically&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Mean By Json Object In Javascript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON stands for JavaScript Object Notation.&lt;br&gt;
It is a lightweight data format used to store and exchange data between systems.&lt;/p&gt;

&lt;p&gt;Even though it comes from JavaScript, JSON is now language-independent, meaning it can be used with:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Why JSON Exists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before JSON, systems used formats like XML to transfer data.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;user&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;name&amp;gt;&lt;/span&gt;Hari&lt;span class="nt"&gt;&amp;lt;/name&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;age&amp;gt;&lt;/span&gt;21&lt;span class="nt"&gt;&amp;lt;/age&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/user&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This format is long and complex.&lt;/p&gt;

&lt;p&gt;JSON solved this by being shorter and easier to read.&lt;/p&gt;

&lt;p&gt;JSON Version:&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;"Hari"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;21&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;&lt;strong&gt;JSON.stringify()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON.stringify() converts a JavaScript object into a JSON string.&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;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hari&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;21&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;jsonData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="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;jsonData&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 json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Hari"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&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;Conversion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript Object → JSON String

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JSON.parse()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON.parse() converts a JSON string into a JavaScript object.&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;let&lt;/span&gt; &lt;span class="nx"&gt;jsonData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"name":"Hari","age":21}&lt;/span&gt;&lt;span class="dl"&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jsonData&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;user&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;/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;Hari
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JSON String → JavaScript Object
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Math Object In Javascript.
&lt;/h2&gt;

&lt;p&gt;The Math object in JavaScript is a built-in global object that provides mathematical constants and functions for performing calculations.&lt;/p&gt;

&lt;p&gt;Important point:&lt;/p&gt;

&lt;p&gt;The Math object is not a constructor, so we do not use new Math().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why the Math Object Exists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Programming often requires mathematical operations like:&lt;/p&gt;

&lt;p&gt;1.rounding numbers&lt;/p&gt;

&lt;p&gt;2.finding maximum or minimum values&lt;/p&gt;

&lt;p&gt;3.generating random numbers&lt;/p&gt;

&lt;p&gt;4.trigonometric calculations&lt;/p&gt;

&lt;p&gt;5.powers and square roots&lt;/p&gt;

&lt;p&gt;Instead of writing these algorithms manually, JavaScript provides the Math object with built-in methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Math Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Math.max()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the largest value&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&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="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&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;50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally it compares numbers and returns the maximum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Math.round()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rounds a number to the nearest integer.&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.6&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.5 or greater → round up
less than 0.5 → round down
&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 plaintext"&gt;&lt;code&gt;Math.round(4.4) → 4
Math.round(4.5) → 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Math.floor()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rounds down to the nearest integer.&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.9&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;4
&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 plaintext"&gt;&lt;code&gt;Math.floor(8.99) → 8
Math.floor(3.1) → 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Math.trunc()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes the decimal part.&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;5.9&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Math.sqrt()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Calculates square root.&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;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;625&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;25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Math.crbt()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Calculates Cube root.&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;27&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;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript String Methods Explained with Examples</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Tue, 10 Mar 2026 15:21:56 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/javascript-string-methods-explained-with-examples-2hb0</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/javascript-string-methods-explained-with-examples-2hb0</guid>
      <description>&lt;h2&gt;
  
  
  1.String in Javascript
&lt;/h2&gt;

&lt;p&gt;A string in JavaScript is a data type used to store text.&lt;br&gt;
It is a sequence of characters such as letters, numbers, symbols, or spaces enclosed within quotes.&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 javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let name = "Hariharan";
let city = 'Chennai';
let message = "Hai";`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above examples&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"Hariharan" is a string&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Chennai" is a string&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Hai" is a string&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Strings can be created using single quotes (' '), double quotes (" "), or backticks ( ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strings are used to store text values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A string can contain letters, numbers, symbols, and spaces.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2.Why We Use Strings in JavaScript
&lt;/h2&gt;

&lt;p&gt;We use strings in JavaScript to store and work with text data. Most applications need to handle text such as names, messages, addresses, or descriptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.String Methods in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, a string is a sequence of characters used to represent text. JavaScript provides many built-in string methods that allow developers to manipulate, analyze, and transform text data easily.&lt;/p&gt;

&lt;p&gt;These methods help perform operations such as finding characters, extracting parts of a string, changing case, removing spaces, and replacing text.&lt;/p&gt;

&lt;p&gt;One important thing to remember is that strings in JavaScript are immutable. This means string methods do not change the original string. Instead, they return a new string with the result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Length&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the length of a string.&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="s2"&gt;`let text = "Hari";
console.log(text.length);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.charAt()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the character at a specific index.&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="s2"&gt;`let text = "Hariharan";
console.log(text.charAt(4));`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
h`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.charCodeAt()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the Unicode value of a character.&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="s2"&gt;`let text = "A";
console.log(text.charCodeAt(0));`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
65`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What is Unicode&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unicode is a universal character encoding standard used to represent characters from almost all languages in the world.&lt;/p&gt;

&lt;p&gt;It assigns a unique numeric code (number) to every character.&lt;/p&gt;

&lt;p&gt;This allows computers to store and display text consistently across different systems and languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.String Concat&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The concat() method in JavaScript is used to join two or more strings together and return a new combined string.&lt;/p&gt;

&lt;p&gt;It does not modify the original strings.&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="s2"&gt;`let text1 = "Bumrah";
let text2 = "Bowls a Yorker";

let result = text1.concat(" ", text2);

console.log(result);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
Bumrah Bowls a Yorker`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.toLowerCase()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Converts all characters to lowercase.&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="s2"&gt;`let text = "HARIHARAN";
console.log(text.toLowerCase());`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
hariharan`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.toUppercase()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Converts all characters to uppercase&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="s2"&gt;`let text = "hariharan";
console.log(text.toLowerCase());`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
HARIHARAN`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.Slice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Extracts a portion of a string&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="s2"&gt;`let text = "JavaScript";
console.log(text.slice(0,4));`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
Java`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7.trim()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes extra spaces from the beginning and end of a string&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="s2"&gt;`let text = "   Hello   ";
console.log(text.trim());`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;/div&gt;



&lt;h2&gt;
  
  
  String Search
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JavaScript indexOf() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The indexOf() method in JavaScript is used to find the position (index) of the first occurrence of a specified value in a string.&lt;/p&gt;

&lt;p&gt;If the specified value is not found, the method returns -1.&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="s2"&gt;`let text = "Hello World";

console.log(text.indexOf("World"));`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Output
6`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;indexOf() returns the first occurrence of a value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the value is not found, it returns -1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is case-sensitive.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript Array Basics: Methods &amp; Iteration Explained</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Mon, 02 Mar 2026 12:18:41 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/javascript-array-basics-methods-iteration-explained-3e20</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/javascript-array-basics-methods-iteration-explained-3e20</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqed3l9y60bzk3nnl8cgj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqed3l9y60bzk3nnl8cgj.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Definition of Method in JavaScript
&lt;/h2&gt;

&lt;p&gt;A method in JavaScript is a function that is associated with an object. It is used to perform a specific task or operation on that object.&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;let name = "Hari";

console.log(name.toUpperCase());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, toUpperCase() is a method of the String object.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Function → standalone&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Method → function inside an object&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2.Array Method in JavaScript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, array methods are built-in functions that allow us to perform different operations on arrays like adding, removing, updating, searching, and iterating elements.&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;let fruits = ["apple", "banana", "orange"];

fruits.push("mango");  // add element

console.log(fruits);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, push() is an array method used to add a new element to the array.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Array methods make array operations easy, fast, and clean.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3.Why should we use array methods in JavaScript
&lt;/h2&gt;

&lt;p&gt;We should use array methods because they make our code simple, clean, readable, and efficient while working with arrays&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Without array method (using loop)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nums = [1, 2, 3, 4];
let squares = [];

for(let i = 0; i &amp;lt; nums.length; i++) {
  squares.push(nums[i] * nums[i]);
}

console.log(squares);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With array method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nums = [1, 2, 3, 4];
let squares = nums.map(n =&amp;gt; n * n);

console.log(squares);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4.Basic Array Methods in JavaScript
&lt;/h2&gt;

&lt;p&gt;JavaScript basic array methods help developers efficiently add, remove, search, modify, and manage array elements. These methods improve code readability, reduce complexity, and enhance performance in real-world applications&lt;/p&gt;

&lt;p&gt;Basic array methods mainly help us perform CRUD operations (Create, Read, Update, Delete) on array data&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.push() – Add Elements at the End&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adds one or more elements to the end of an array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Can add multiple values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modifies the original array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns the new length of the array&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [10, 20, 30];
let newLength = arr.push(40, 50);

console.log(arr);        // [10, 20, 30, 40, 50]
console.log(newLength); // 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Real-world use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adding a new product to a shopping cart&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.pop() – Remove Last Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes the last element from an array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Removes the last value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns the removed value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modifies the original array&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1, 2, 3, 4];
let removed = arr.pop();

console.log(arr);     // [1, 2, 3]
console.log(removed); // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Undo operations, stack implementation (LIFO concept).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.unshift() – Add Elements at the Beginning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adds one or more elements to the start of an array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Existing elements shift to the right&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slightly slower than push() for large arrays&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [20, 30];
arr.unshift(10);

console.log(arr); // [10, 20, 30]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Displaying latest notifications or messages at the top&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.shift() – Remove First Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes the first element from an array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All remaining elements shift to the left&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used in queue operations (FIFO)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [10, 20, 30];
let removed = arr.shift();

console.log(arr);     // [20, 30]
console.log(removed); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.shift() – Remove First Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes the first element from an array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All remaining elements shift to the left&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used in queue operations (FIFO)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [10, 20, 30];
let removed = arr.shift();

console.log(arr);     // [20, 30]
console.log(removed); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.length – Size of the Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the number of elements in an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1, 2, 3, 4];
console.log(arr.length); // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advanced Concept&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can manually modify the length property to truncate an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1, 2, 3, 4, 5];
arr.length = 3;

console.log(arr); // [1, 2, 3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5.JavaScript Array Iteration Methods
&lt;/h2&gt;

&lt;p&gt;In JavaScript, array iteration methods are built-in functions that loop through array elements and apply a callback function to each element to perform specific operations such as transformation, filtering, aggregation, and searching&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. forEach() – Execute Function for Each Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Executes a function once for each array element&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Does not return a new array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used mainly for side effects (logging, updating UI, etc.)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1, 2, 3, 4];

arr.forEach((value, index) =&amp;gt; {
  console.log(`Index ${index} → Value ${value}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Displaying items in UI, logging data, API response handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. map() – Transform Each Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creates a new array by transforming each element&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Returns a new array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does not change original array&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3, 4];

let squares = numbers.map(n =&amp;gt; n * n);

console.log(squares); // [1, 4, 9, 16]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data transformation, UI rendering, calculations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. filter() – Select Elements Based on Condition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns a new array containing only elements that pass a condition&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [10, 15, 20, 25, 30];

let even = numbers.filter(n =&amp;gt; n % 2 === 0);

console.log(even); // [10, 20, 30]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Search results, category filtering, validations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. reduce() – Reduce Array to Single Value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reduces the array into a single output value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3, 4];

let sum = numbers.reduce((total, value) =&amp;gt; total + value, 0);

console.log(sum); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use cases&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sum, average, max/min value, grouping data&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. find() – Find First Matching Element&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the first element that matches a condition&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let users = [
  { id: 1, name: "Hari" },
  { id: 2, name: "Karthi" },
  { id: 3, name: "Arun" }
];

let result = users.find(user =&amp;gt; user.id === 2);

console.log(result); // { id: 2, name: "Karthi" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. findIndex() – Find Index of First Match&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Returns the index of first matching element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nums = [5, 12, 8, 130, 44];

let index = nums.findIndex(n =&amp;gt; n &amp;gt; 10);

console.log(index); // 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6.What is Method Chaining in JavaScript
&lt;/h2&gt;

&lt;p&gt;Method chaining in JavaScript is a programming technique in which multiple methods are invoked sequentially on the same object, where each method returns the object itself or another object, enabling continuous chained calls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use Method Chaining?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Makes code short and clean&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves readability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoids unnecessary temporary variables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Encourages functional programming style&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes logic more expressive&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Simple 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;let result = [1, 2, 3, 4, 5]
  .filter(n =&amp;gt; n % 2 === 0)
  .map(n =&amp;gt; n * 10)
  .reduce((sum, n) =&amp;gt; sum + n, 0);

console.log(result); // 60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;filter() → selects even numbers → [2, 4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;map() → multiplies by 10 → [20, 40]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;reduce() → sums → 60&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Functions in JavaScript – Learn Once, Use Everywhere</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Tue, 24 Feb 2026 05:54:31 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/functions-in-javascript-learn-once-use-everywhere-fnf</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/functions-in-javascript-learn-once-use-everywhere-fnf</guid>
      <description>&lt;h2&gt;
  
  
  1.Function Definition
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A function is a set of instructions that performs a particular job when we call it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;(Or)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A function in JavaScript is a block of reusable code that is designed to perform a specific task. It runs only when it is called (invoked), and it helps to reduce code repetition, improve readability, and make programs easier to manage.&lt;/strong&gt;&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;function makeParotta() {
    console.log("Kothu Parotta is Ready");
}

makeParotta();  // calling the function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2.Rules for Declaring a Function
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Starts with lower case&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No Space Allowed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No Special Characters are allowed except Underscore(_) and Dollar($)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunction() { }
function _test() { }
function $demo() { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript keywords cannot be used as function names&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reserved words like if, else, for, while, etc. cannot be used.&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;function if() { }   // ❌
function for() { }  // ❌
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Parameters in Function
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Parameters are the variables listed in the function definition. They act as placeholders to receive values when the function is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {   // a and b are parameters
  return a + b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, a and b are parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arguments in Function
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arguments are the actual values passed to the function when calling it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add(5, 3);   // 5 and 3 are arguments
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, 5 and 3 are arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple One-Line Definition:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Parameter: Variable in function definition.&lt;/p&gt;

&lt;p&gt;Argument: Value passed to the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy to Remember Trick:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;P → Parameter → Placeholders&lt;br&gt;
A → Argument → Actual values&lt;/p&gt;
&lt;h2&gt;
  
  
  Difference between Parameters and Arguments
&lt;/h2&gt;

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

&lt;p&gt;&lt;strong&gt;A return statement gives the output of a function back to the caller.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;(Or)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The return statement is used to send a value back from a function to the place where the function was called and stop the execution of the function.&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;function add(a, b) {
  return a + b;
}

let result = add(5, 3);
console.log(result);   // Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;return a + b; → sends the value 8 back&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;result receives 8&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important Points&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A function can return only one value at a time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any code after the return statement will not execute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If no return statement is used, the function returns undefined.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Understanding JavaScript the Easy Way</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Fri, 13 Feb 2026 14:49:39 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/understanding-javascript-the-easy-way-1op</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/understanding-javascript-the-easy-way-1op</guid>
      <description>&lt;h2&gt;
  
  
  History of JavaSript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. The Birth of JavaScript (1995)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript was created by Brendan Eich in 1995 while he was working at Netscape.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initially named Mocha&lt;/li&gt;
&lt;li&gt;    Later renamed to LiveScript&lt;/li&gt;
&lt;li&gt;    Finally renamed JavaScript (because Java was very popular at that time, and the name helped in marketing) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interestingly, the first version of JavaScript was developed in just 10 days.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Standardization (1997)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In 1997, JavaScript was standardized by ECMA International under the name ECMAScript (ES).&lt;/p&gt;

&lt;p&gt;This ensured that different browsers followed the same core rules and reduced compatibility issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables in javascript
&lt;/h2&gt;

&lt;p&gt;Variables in JavaScript are used to store data values.&lt;br&gt;
You can think of a variable as a container that holds information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Declare Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, there are three ways to declare variables:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Var(Old Method)&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;`var name = "Hari";
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Function-scoped&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can be re-declared&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not recommended in modern JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.let(Modern &amp;amp; Recommended)&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;`let age = 22;
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Block-scoped&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can be updated&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cannot be re-declared in the same scope&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.const(Constant Value)&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 country = "India";
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Block-scoped&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cannot be updated&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cannot be re-declared&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rules for Naming Variables&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Must start with a letter, _, or $&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cannot start with a number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Case-sensitive (name and Name are different)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid reserved keywords (like if, for, while)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Datatypes in javascript
&lt;/h2&gt;

&lt;p&gt;In JavaScript, data types define the type of value a variable can hold&lt;br&gt;
JavaScript has two main categories of data types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Primitive Datatype&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. Non Primitive Datatype&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Primitive Datatype&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primitive data types are basic data types that store a single value directly in memory&lt;br&gt;
They are immutable, meaning their value cannot be changed once created (a new value is created instead).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Number&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Represents both integers and decimal values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let age = 21;
let price = 105.234;
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.String&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Represents text (written inside quotes).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let name = "Hari";
let message = 'Hello World';
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Boolean&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Represents true or false values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let isLoggedIn = true;
let isAdmin = false;
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.Undefined&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A variable that is declared but not assigned a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let x;
console.log(x); // undefined
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.Null&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Represents an intentional empty value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let data = null;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.BigInt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used for very large numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let bigNumber = 123456789012345678901234567890n;
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7.Symbol&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used to create unique identifiers (mostly used in advanced concepts).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let id = Symbol("unique");
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Non Primitive Datatype&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Non-primitive data types (also called reference data types) store collections of values or complex data&lt;br&gt;
They are stored as references (memory addresses) instead of storing the actual value directly&lt;/p&gt;

&lt;p&gt;They are mutable, meaning their contents can be changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stores data in key–value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let person = {
  name: "Hari",
  age: 21
};
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used to store multiple values in a single variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let numbers = [1, 2, 3, 4];
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Functions are also treated as objects in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function greet() {
  console.log("Hello!");
}
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Semantic Tags in HTML</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Wed, 21 Jan 2026 14:25:32 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/semantic-tags-in-html-276h</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/semantic-tags-in-html-276h</guid>
      <description>&lt;p&gt;1.What is mean by semantic tags in html?&lt;/p&gt;

&lt;p&gt;Semantic tags are HTML tags that tell both the browser and the developer what type of content they contain.&lt;/p&gt;

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

&lt;p&gt;❌ Non-semantic:&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;div&amp;gt;This is a header&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;✅ Semantic:&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;header&amp;gt;This is a header&amp;lt;/header&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;2.Why semantic tags is used in html&lt;/p&gt;

&lt;p&gt;Semantic tags are used in HTML to define the meaning and structure of web content, improving readability, SEO, and accessibility.&lt;/p&gt;

&lt;p&gt;i)Better understanding of content&lt;/p&gt;

&lt;p&gt;Example:  tells it is a header,  tells it is footer&lt;/p&gt;

&lt;p&gt;ii)Improves SEO (Search Engine Optimization)&lt;/p&gt;

&lt;p&gt;iii)Better accessibility&lt;/p&gt;

&lt;p&gt;iv)Clean and readable code&lt;/p&gt;

&lt;p&gt;v)Standard and professional layout&lt;/p&gt;

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

&lt;p&gt;❌ Without semantic tags:&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;div id="header"&amp;gt;Header&amp;lt;/div&amp;gt;
&amp;lt;div id="nav"&amp;gt;Menu&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;✅ With semantic tags:&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;header&amp;gt;Header&amp;lt;/header&amp;gt;
&amp;lt;nav&amp;gt;Menu&amp;lt;/nav&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;3.Various semantic tags in html&lt;/p&gt;

&lt;p&gt;🔹 Page Structure Semantic Tags&lt;/p&gt;

&lt;p&gt;i) &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Represents top/intro content&lt;/p&gt;

&lt;p&gt;Logo, heading, navigation&lt;/p&gt;

&lt;p&gt;ii) &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Navigation links&lt;/p&gt;

&lt;p&gt;iii) &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Main content of the webpage (only one per page)&lt;/p&gt;

&lt;p&gt;iv) &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Groups related content&lt;/p&gt;

&lt;p&gt;v) &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Independent, self-contained content (blogs, news)&lt;/p&gt;

&lt;p&gt;vi) &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Side or related content&lt;/p&gt;

&lt;p&gt;vii) &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Bottom section (copyright, contact info)&lt;/p&gt;

&lt;p&gt;🔹 Content Semantic Tags&lt;/p&gt;

&lt;p&gt;i)&lt;code&gt;&amp;lt;figure&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Image, diagram, illustration&lt;/p&gt;

&lt;p&gt;ii) &lt;code&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Caption for figure&lt;/p&gt;

&lt;p&gt;iii) &lt;code&gt;&amp;lt;time&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Represents date or time&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;time datetime="2026-01-21"&amp;gt;Jan 21, 2026&amp;lt;/time&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;🔹 Text-Level Semantic Tags&lt;/p&gt;

&lt;p&gt;i) &lt;code&gt;&amp;lt;mark&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Highlights text&lt;/p&gt;

&lt;p&gt;ii) &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Important text (strong importance)&lt;/p&gt;

&lt;p&gt;iii) &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Emphasized text&lt;/p&gt;

&lt;p&gt;iv) &lt;code&gt;&amp;lt;address&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Contact information&lt;/p&gt;

&lt;p&gt;🔹 Media &amp;amp; Data Semantic Tags&lt;/p&gt;

&lt;p&gt;i) &lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Expandable content&lt;/p&gt;

&lt;p&gt;ii) &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Heading for details&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;details&amp;gt;
  &amp;lt;summary&amp;gt;More Info&amp;lt;/summary&amp;gt;
  Content here
&amp;lt;/details&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;4.Advantages of semantic tag&lt;/p&gt;

&lt;p&gt;i)Better code readability&lt;/p&gt;

&lt;p&gt;ii)Improves SEO&lt;/p&gt;

&lt;p&gt;iii)Better accessibility&lt;/p&gt;

&lt;p&gt;iv)Clear page structure&lt;/p&gt;

&lt;p&gt;v)Easy maintenance&lt;/p&gt;

&lt;p&gt;5.Disadvantages of semantic tags&lt;/p&gt;

&lt;p&gt;i)Limited styling by default&lt;/p&gt;

&lt;p&gt;ii)Learning curve for beginners&lt;/p&gt;

&lt;p&gt;iii)Overuse or misuse&lt;/p&gt;

&lt;p&gt;iv)Browser support issues (older browsers)&lt;/p&gt;

&lt;p&gt;v)Not suitable for every situation&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>beginners</category>
      <category>html</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
