<?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>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>
    <item>
      <title>Day 1 Of Payilagam</title>
      <dc:creator>Hariharan S J</dc:creator>
      <pubDate>Tue, 06 Jan 2026 14:54:13 +0000</pubDate>
      <link>https://dev.to/hariharan_sj_584ad73ef2e/day-1-of-payilagam-37j6</link>
      <guid>https://dev.to/hariharan_sj_584ad73ef2e/day-1-of-payilagam-37j6</guid>
      <description>&lt;p&gt;1.Introduction of both HTML And CSS&lt;/p&gt;

&lt;p&gt;Basic concept of HTML&lt;/p&gt;

&lt;p&gt;HTML (HyperText Markup Language) is the standard language used to create web pages. It provides the structure of a webpage by using elements called tags.&lt;/p&gt;

&lt;p&gt;HTML is not a programming language; it is a markup language.&lt;/p&gt;

&lt;p&gt;Structure of an HTML Document&lt;/p&gt;

&lt;p&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;br&gt;
    My First Web Page&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
    &lt;h1&gt;Welcome&lt;/h1&gt;
&lt;br&gt;
    &lt;p&gt;This is my first HTML page.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;


&lt;p&gt;Common HTML Tags&lt;br&gt;
Tag&lt;br&gt;
Purpose&lt;/p&gt;

&lt;h1&gt; to &lt;h6&gt;
Headings
&lt;/h6&gt;
&lt;/h1&gt;
&lt;p&gt;
Paragraph
&lt;br&gt;
Line break
&lt;/p&gt;

Horizontal line
&lt;img&gt;
Image
&lt;a&gt;
Link

Container
&lt;span&gt;
Inline container



Attributes in HTML
Attributes provide additional information about elements.
Example:
&lt;a href="https://example.com" rel="noopener noreferrer"&gt;Visit Site&lt;/a&gt;
href is an attribute
Attributes are written inside the opening tag

HTML Headings
HTML has 6 levels of headings:
&lt;h1&gt;Main Heading&lt;/h1&gt;

&lt;h2&gt;Sub Heading&lt;/h2&gt;


&lt;h1&gt; is the most important and &lt;h6&gt; is the least.

&lt;/h6&gt;
&lt;/h1&gt;

&lt;p&gt;Paragraphs and Line Breaks&lt;br&gt;
Paragraph → &lt;/p&gt;

&lt;p&gt;&lt;br&gt;
Line break → &lt;br&gt;&lt;/p&gt;

&lt;p&gt;This is a paragraph.&lt;br&gt;This is next line.&lt;/p&gt;

&lt;p&gt;HTML Links&lt;br&gt;
Links are created using &lt;a&gt; tag:&lt;br&gt;
&lt;/a&gt;&lt;a href="https://google.com" rel="noopener noreferrer"&gt;Google&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basic concept of CSS&lt;/p&gt;

&lt;p&gt;CSS (Cascading Style Sheets) is used to style and design HTML web pages.&lt;br&gt;
It controls the layout, colors, fonts, spacing, and responsiveness of a website.&lt;br&gt;
HTML gives structure, CSS gives style.&lt;/p&gt;

&lt;p&gt;Inline CSS&lt;br&gt;
Applied directly inside an HTML tag.&lt;/p&gt;

&lt;p&gt;Hello World&lt;/p&gt;

&lt;p&gt;text-align: center aligns the text to the center of its container.&lt;/p&gt;

&lt;p&gt;HTML Box model&lt;/p&gt;

&lt;p&gt;The HTML Box Model is a basic concept in CSS that explains how every HTML element is treated as a rectangular box on a web page.&lt;br&gt;
This box controls spacing, size, and layout of elements.&lt;br&gt;
Components of the Box Model&lt;br&gt;
Every HTML element consists of four layers:&lt;/p&gt;

&lt;p&gt;+-------------------------+&lt;br&gt;
|        Margin           |&lt;br&gt;
|  +-------------------+  |&lt;br&gt;
|  |      Border       |  |&lt;br&gt;
|  |  +-------------+ |  |&lt;br&gt;
|  |  |   Padding   | |  |&lt;br&gt;
|  |  | +---------+ | |  |&lt;br&gt;
|  |  | | Content | | |  |&lt;br&gt;
|  |  | +---------+ | |  |&lt;br&gt;
|  |  +-------------+ |  |&lt;br&gt;
|  +-------------------+  |&lt;br&gt;
+-------------------------+&lt;/p&gt;

&lt;p&gt;Where margin is outside the box and padding is &lt;br&gt;
Inside the Box&lt;/p&gt;

&lt;/span&gt;&lt;/a&gt;

</description>
    </item>
  </channel>
</rss>
