<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HTML, CSS, Javascript Blog]]></title><description><![CDATA[HTML, CSS, Javascript Blog]]></description><link>https://arjun-js-blog.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 14:12:54 GMT</lastBuildDate><atom:link href="https://arjun-js-blog.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Prototype & Inheritance in JavaScript (Explained with Easy Analogies)]]></title><description><![CDATA[JavaScript looks confusing when you hear words like prototype, proto, and inheritance.But trust me — once you understand the idea, everything becomes simple.
In this blog, we’ll cover:

What prototype means (with real-life analogy)

prototype vs __pr...]]></description><link>https://arjun-js-blog.hashnode.dev/prototype-and-inheritance-in-javascript-explained-with-easy-analogies</link><guid isPermaLink="true">https://arjun-js-blog.hashnode.dev/prototype-and-inheritance-in-javascript-explained-with-easy-analogies</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[prototype]]></category><category><![CDATA[inheritance]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Arjun Saxena]]></dc:creator><pubDate>Mon, 08 Dec 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766396866931/4bd1f243-2bfc-4bcd-9491-cb481aadea47.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>JavaScript looks confusing when you hear words like <strong>prototype</strong>, <strong>proto</strong>, and <strong>inheritance</strong>.<br />But trust me — once you understand the <strong>idea</strong>, everything becomes simple.</p>
<p>In this blog, we’ll cover:</p>
<ul>
<li><p>What prototype means (with real-life analogy)</p>
</li>
<li><p><code>prototype</code> vs <code>__proto__</code></p>
</li>
<li><p>What <code>new</code> does behind the scenes</p>
</li>
<li><p>Inheritance <strong>without using</strong> <code>extends</code></p>
</li>
<li><p>JavaScript events explained using real-world examples</p>
</li>
<li><p>Simple diagrams to visualize everything</p>
</li>
</ul>
<h2 id="heading-first-a-simple-analogy-blueprint-amp-genetics">First, a Simple Analogy 🏗️ (Blueprint &amp; Genetics)</h2>
<p>Imagine this:</p>
<ul>
<li><p>A <strong>blueprint</strong> is used to create many houses</p>
</li>
<li><p>All houses share common features</p>
</li>
<li><p>Each house can have its own custom changes</p>
</li>
</ul>
<p>👉 In JavaScript:</p>
<ul>
<li><p><strong>Prototype = blueprint</strong></p>
</li>
<li><p><strong>Objects = houses</strong></p>
</li>
<li><p><strong>Inheritance = sharing features</strong></p>
</li>
</ul>
<h2 id="heading-what-is-a-prototype-in-javascript">What Is a Prototype in JavaScript?</h2>
<p>In JavaScript, <strong>every object has a hidden link to another object</strong>.<br />This link is called a <strong>prototype</strong>.</p>
<p>When you try to access a property:</p>
<ol>
<li><p>JavaScript checks the object itself</p>
</li>
<li><p>If not found, it looks in its prototype</p>
</li>
<li><p>This continues until <code>null</code></p>
</li>
</ol>
<p>This process is called the <strong>prototype chain</strong>.</p>
<h2 id="heading-simple-example">Simple Example</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> human = {
  <span class="hljs-attr">canTalk</span>: <span class="hljs-literal">true</span>
};

<span class="hljs-keyword">const</span> arjun = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Arjun"</span>
};

arjun.__proto__ = human;

<span class="hljs-built_in">console</span>.log(arjun.canTalk); <span class="hljs-comment">// true</span>
</code></pre>
<p>👉 <code>arjun</code> doesn’t have <code>canTalk</code>,<br />👉 JavaScript looks at <code>human</code> (its prototype)</p>
<h2 id="heading-prototype-chain-visualization">Prototype Chain Visualization 🧠</h2>
<pre><code class="lang-javascript">arjun
 ↓
human
 ↓
<span class="hljs-built_in">Object</span>.prototype
 ↓
<span class="hljs-literal">null</span>
</code></pre>
<h2 id="heading-prototype-vs-proto">prototype vs __proto__</h2>
<p>This confuses almost everyone at first 😅</p>
<h3 id="heading-simple-rule-to-remember">Simple Rule to Remember ✅</h3>
<ul>
<li><p><code>prototype</code> → belongs to <strong>constructor functions</strong></p>
</li>
<li><p><code>__proto__</code> → belongs to <strong>objects</strong></p>
</li>
</ul>
<h2 id="heading-example-to-understand-clearly">Example to Understand Clearly</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-built_in">this</span>.name = name;
}

<span class="hljs-keyword">const</span> p1 = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">"Arjun"</span>);
</code></pre>
<h3 id="heading-what-happens-internally">What happens internally?</h3>
<pre><code class="lang-javascript">p1.__proto__ === Person.prototype  <span class="hljs-comment">// true</span>
</code></pre>
<h2 id="heading-comparison-table">Comparison Table 📊</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td><code>prototype</code></td><td><code>__proto__</code></td></tr>
</thead>
<tbody>
<tr>
<td>Belongs to</td><td>Constructor function</td><td>Object</td></tr>
<tr>
<td>Purpose</td><td>Blueprint for objects</td><td>Points to prototype</td></tr>
<tr>
<td>Used for</td><td>Inheritance</td><td>Lookup chain</td></tr>
</tbody>
</table>
</div><h2 id="heading-what-does-new-keyword-do">What Does <code>new</code> Keyword Do?</h2>
<p>When you write:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> p1 = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">"Arjun"</span>);
</code></pre>
<p>JavaScript does <strong>4 things automatically</strong>:</p>
<p>1️⃣ Creates a new empty object<br />2️⃣ Sets <code>p1.__proto__ = Person.prototype</code><br />3️⃣ Calls <code>Person()</code> with <code>this = p1</code><br />4️⃣ Returns the object</p>
<p>👉 That’s how inheritance starts ✨</p>
<h2 id="heading-adding-methods-using-prototype-best-practice">Adding Methods Using Prototype (Best Practice)</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-built_in">this</span>.name = name;
}

Person.prototype.sayHello = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello, my name is "</span> + <span class="hljs-built_in">this</span>.name);
};

<span class="hljs-keyword">const</span> p1 = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">"Arjun"</span>);
p1.sayHello();
</code></pre>
<p>✔️ Memory efficient<br />✔️ Shared across all objects</p>
<h2 id="heading-achieving-inheritance-without-extends">Achieving Inheritance WITHOUT extends 🚫</h2>
<p>Let’s say we want:</p>
<ul>
<li><code>Student</code> to inherit from <code>Person</code></li>
</ul>
<h3 id="heading-step-1-parent-constructor">Step 1: Parent Constructor</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-built_in">this</span>.name = name;
}
</code></pre>
<h3 id="heading-step-2-child-constructor">Step 2: Child Constructor</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Student</span>(<span class="hljs-params">name, rollNo</span>) </span>{
  Person.call(<span class="hljs-built_in">this</span>, name);
  <span class="hljs-built_in">this</span>.rollNo = rollNo;
}
</code></pre>
<h3 id="heading-step-3-link-prototypes">Step 3: Link Prototypes</h3>
<pre><code class="lang-javascript">Student.prototype = <span class="hljs-built_in">Object</span>.create(Person.prototype);
Student.prototype.constructor = Student;
</code></pre>
<h3 id="heading-step-4-add-methods">Step 4: Add Methods</h3>
<pre><code class="lang-javascript">Student.prototype.study = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.name + <span class="hljs-string">" is studying"</span>);
};
</code></pre>
<h3 id="heading-use-it">Use It</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> s1 = <span class="hljs-keyword">new</span> Student(<span class="hljs-string">"Arjun"</span>, <span class="hljs-number">101</span>);
s1.study();
</code></pre>
<p>Inheritance achieved without <code>extends</code></p>
<h2 id="heading-prototype-inheritance-analogy">Prototype Inheritance Analogy 🧬</h2>
<p>Think of <strong>genetic traits</strong>:</p>
<ul>
<li><p>Parents pass traits to children</p>
</li>
<li><p>Children can add their own traits</p>
</li>
</ul>
<p>Same with prototypes:</p>
<ul>
<li><p>Parent prototype → shared features</p>
</li>
<li><p>Child object → custom features</p>
</li>
</ul>
<h2 id="heading-analogy-based-events-in-javascript">Analogy-Based “Events” in JavaScript 🎯</h2>
<p>Think of a <strong>doorbell</strong> 🔔</p>
<ul>
<li><p>Press button → event happens</p>
</li>
<li><p>Bell rings → listener reacts</p>
</li>
</ul>
<h3 id="heading-javascript-version">JavaScript Version</h3>
<pre><code class="lang-javascript">button.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button clicked!"</span>);
});
</code></pre>
<p>👉 Event = button press<br />👉 Listener = bell ringing logic</p>
<h2 id="heading-event-propagation-real-life-analogy">Event Propagation (Real-Life Analogy)</h2>
<p>Imagine shouting in a building:</p>
<ul>
<li><p>Your voice goes to the room</p>
</li>
<li><p>Then hallway</p>
</li>
<li><p>Then entire building</p>
</li>
</ul>
<p>That’s <strong>event bubbling</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Events: Making Web Pages Interactive ⚡]]></title><description><![CDATA[Have you ever clicked a button and something happened on a website?Maybe text changed, a popup opened, or a form was submitted.
That magic happens because of JavaScript Events.
In this blog, we’ll learn:

What events are

Why events are important

Wh...]]></description><link>https://arjun-js-blog.hashnode.dev/javascript-events-making-web-pages-interactive</link><guid isPermaLink="true">https://arjun-js-blog.hashnode.dev/javascript-events-making-web-pages-interactive</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[events]]></category><category><![CDATA[DOM]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Arjun Saxena]]></dc:creator><pubDate>Sun, 07 Dec 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766396359987/a5f6cd8f-3a39-4379-9dcf-276f19358863.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever clicked a button and something happened on a website?<br />Maybe text changed, a popup opened, or a form was submitted.</p>
<p>That magic happens because of <strong>JavaScript Events</strong>.</p>
<p>In this blog, we’ll learn:</p>
<ul>
<li><p>What events are</p>
</li>
<li><p>Why events are important</p>
</li>
<li><p>What event listeners are</p>
</li>
<li><p>Event bubbling and capturing</p>
</li>
<li><p>How to stop event propagation<br />  All with <strong>easy examples</strong> 👇</p>
</li>
</ul>
<h2 id="heading-what-are-events-in-javascript">What Are Events in JavaScript?</h2>
<p>An <strong>event</strong> is something that happens on a webpage.</p>
<h3 id="heading-common-events">Common Events</h3>
<ul>
<li><p>Clicking a button</p>
</li>
<li><p>Hovering over an element</p>
</li>
<li><p>Typing in an input box</p>
</li>
<li><p>Submitting a form</p>
</li>
<li><p>Page loading</p>
</li>
</ul>
<p>👉 JavaScript listens for these events and <strong>responds</strong> to them.</p>
<h2 id="heading-why-are-events-important">Why Are Events Important?</h2>
<p>Without events ❌<br />A webpage is just <strong>static content</strong>.</p>
<p>With events ✅<br />A webpage becomes <strong>interactive and dynamic</strong>.</p>
<p>Examples:</p>
<ul>
<li><p>Clicking “Login” button</p>
</li>
<li><p>Changing theme (dark/light)</p>
</li>
<li><p>Showing error messages</p>
</li>
<li><p>Animations and popups</p>
</li>
</ul>
<h2 id="heading-simple-example-button-click-event">Simple Example: Button Click Event</h2>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-javascript">&lt;button id=<span class="hljs-string">"btn"</span>&gt;Click Me&lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"text"</span>&gt;</span>Hello!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>
</code></pre>
<h3 id="heading-javascript">JavaScript</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> button = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"btn"</span>);
<span class="hljs-keyword">const</span> text = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"text"</span>);

button.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  text.textContent = <span class="hljs-string">"You clicked the button!"</span>;
});
</code></pre>
<h3 id="heading-what-happens">What Happens?</h3>
<ol>
<li><p>User clicks the button</p>
</li>
<li><p><code>click</code> event fires</p>
</li>
<li><p>Text changes instantly 🎉</p>
</li>
</ol>
<h2 id="heading-what-is-an-event-listener">What Is an Event Listener?</h2>
<p>An <strong>event listener</strong> tells JavaScript:</p>
<blockquote>
<p>“Hey, when this event happens, run this code.”</p>
</blockquote>
<h3 id="heading-syntax">Syntax</h3>
<pre><code class="lang-javascript">element.addEventListener(<span class="hljs-string">"event"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>);</span>
</code></pre>
<h3 id="heading-example">Example</h3>
<pre><code class="lang-javascript">button.addEventListener(<span class="hljs-string">"click"</span>, sayHello);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHello</span>(<span class="hljs-params"></span>) </span>{
  alert(<span class="hljs-string">"Hello!"</span>);
}
</code></pre>
<h2 id="heading-common-event-types">Common Event Types</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Event</td><td>Trigger</td></tr>
</thead>
<tbody>
<tr>
<td><code>click</code></td><td>Mouse click</td></tr>
<tr>
<td><code>mouseover</code></td><td>Hover</td></tr>
<tr>
<td><code>keydown</code></td><td>Key press</td></tr>
<tr>
<td><code>submit</code></td><td>Form submit</td></tr>
<tr>
<td><code>load</code></td><td>Page load</td></tr>
</tbody>
</table>
</div><h2 id="heading-multiple-event-listeners">Multiple Event Listeners</h2>
<p>You can attach <strong>multiple listeners</strong> to the same element.</p>
<pre><code class="lang-javascript">button.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Clicked!"</span>);
});

button.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button pressed!"</span>);
});
</code></pre>
<p>Both will run ✔️</p>
<h2 id="heading-event-propagation-very-important-concept">Event Propagation (Very Important Concept)</h2>
<p>When an event happens, it doesn’t stop at one element.<br />It <strong>travels through the DOM</strong>.</p>
<p>This is called <strong>event propagation</strong>.</p>
<p>There are <strong>two phases</strong>:</p>
<ol>
<li><p>Capturing phase</p>
</li>
<li><p>Bubbling phase</p>
</li>
</ol>
<h2 id="heading-event-bubbling-default-behavior">Event Bubbling (Default Behavior)</h2>
<p>Event starts from the <strong>target element</strong> and moves <strong>upward</strong>.</p>
<h3 id="heading-example-1">Example</h3>
<pre><code class="lang-javascript">&lt;div id=<span class="hljs-string">"parent"</span>&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"child"</span>&gt;</span>Click Me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
&lt;/div&gt;
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"parent"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Parent clicked"</span>);
});

<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"child"</span>).addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button clicked"</span>);
});
</code></pre>
<h3 id="heading-output-when-button-is-clicked">Output When Button Is Clicked</h3>
<pre><code class="lang-javascript">Button clicked
Parent clicked
</code></pre>
<p>👉 Event bubbles <strong>up</strong> from child → parent</p>
<h2 id="heading-event-capturing-opposite-of-bubbling">Event Capturing (Opposite of Bubbling)</h2>
<p>Event starts from the <strong>top</strong> and goes <strong>downward</strong>.</p>
<p>To enable capturing, pass <code>true</code> as the third parameter.</p>
<pre><code class="lang-javascript">parent.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Parent clicked"</span>);
}, <span class="hljs-literal">true</span>);

child.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button clicked"</span>);
}, <span class="hljs-literal">true</span>);
</code></pre>
<h3 id="heading-output">Output</h3>
<pre><code class="lang-javascript">Parent clicked
Button clicked
</code></pre>
<h2 id="heading-bubbling-vs-capturing-comparison-table">Bubbling vs Capturing (Comparison Table)</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Bubbling</td><td>Capturing</td></tr>
</thead>
<tbody>
<tr>
<td>Direction</td><td>Bottom → Top</td><td>Top → Bottom</td></tr>
<tr>
<td>Default</td><td>✅ Yes</td><td>❌ No</td></tr>
<tr>
<td>Commonly used</td><td>✅ Yes</td><td>❌ Rare</td></tr>
</tbody>
</table>
</div><h2 id="heading-stopping-event-propagation">Stopping Event Propagation 🛑</h2>
<p>Sometimes, you <strong>don’t want the event to go further</strong>.</p>
<p>Use:</p>
<pre><code class="lang-javascript">event.stopPropagation();
</code></pre>
<h3 id="heading-example-2">Example</h3>
<pre><code class="lang-javascript">child.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
  event.stopPropagation();
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button clicked"</span>);
});
</code></pre>
<h3 id="heading-result">Result</h3>
<p>Only button event runs.<br />Parent event is stopped 🚫</p>
<h2 id="heading-real-world-use-case">Real-World Use Case</h2>
<ul>
<li><p>Clicking a <strong>modal button</strong> but not closing the modal</p>
</li>
<li><p>Preventing parent clicks in dropdown menus</p>
</li>
<li><p>Complex UI components</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[HTML for Beginners: Building the Skeleton of a Webpage]]></title><description><![CDATA[If you are starting your web development journey, HTML is the first thing you must learn.
Think of HTML as the blueprint of a building 🏠Before painting walls or adding furniture, you first need a strong structure.That structure on the web is HTML (H...]]></description><link>https://arjun-js-blog.hashnode.dev/html-for-beginners-building-the-skeleton-of-a-webpage</link><guid isPermaLink="true">https://arjun-js-blog.hashnode.dev/html-for-beginners-building-the-skeleton-of-a-webpage</guid><category><![CDATA[HTML5]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Learn HTML]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Arjun Saxena]]></dc:creator><pubDate>Sat, 06 Dec 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766395907672/37e48a37-abe1-4a3a-bce5-ba07a990d7ed.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are starting your web development journey, <strong>HTML is the first thing you must learn</strong>.</p>
<p>Think of HTML as the <strong>blueprint of a building</strong> 🏠<br />Before painting walls or adding furniture, you first need a <strong>strong structure</strong>.<br />That structure on the web is <strong>HTML (HyperText Markup Language)</strong>.</p>
<h2 id="heading-what-is-html">What is HTML?</h2>
<p>HTML is <strong>not a programming language</strong>.<br />It is a <strong>markup language</strong> used to <strong>structure content</strong> on a webpage.</p>
<p>HTML tells the browser:</p>
<ul>
<li><p>What is a heading</p>
</li>
<li><p>What is a paragraph</p>
</li>
<li><p>What is an image</p>
</li>
<li><p>What is a link</p>
</li>
</ul>
<h2 id="heading-html-blueprint-of-a-building-simple-analogy">HTML = Blueprint of a Building 🧱 (Simple Analogy)</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Building Part</td><td>HTML Equivalent</td></tr>
</thead>
<tbody>
<tr>
<td>Foundation</td><td><code>&lt;html&gt;</code></td></tr>
<tr>
<td>Rooms</td><td><code>&lt;body&gt;</code></td></tr>
<tr>
<td>Title Board</td><td><code>&lt;head&gt;</code></td></tr>
<tr>
<td>Labels</td><td>Tags like <code>&lt;h1&gt;</code>, <code>&lt;p&gt;</code></td></tr>
</tbody>
</table>
</div><p>Without a blueprint, a building collapses.<br />Without HTML, a website has <strong>no structure</strong>.</p>
<h2 id="heading-basic-html-document-structure">Basic HTML Document Structure</h2>
<p>Every HTML page follows a <strong>fixed structure</strong>.</p>
<h3 id="heading-example">Example</h3>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>My First Website<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is my first webpage.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="heading-understanding-each-part-very-easy">Understanding Each Part (Very Easy)</h2>
<h3 id="heading-yga"><code>&lt;!DOCTYPE html&gt;</code></h3>
<ul>
<li>Tells the browser: <strong>This is an HTML5 document</strong></li>
</ul>
<h3 id="heading-yga-1"><code>&lt;html&gt;</code></h3>
<ul>
<li><p>Root of the document</p>
</li>
<li><p>Everything goes inside it</p>
</li>
</ul>
<h3 id="heading-yga-2"><code>&lt;head&gt;</code></h3>
<ul>
<li><p>Contains <strong>meta information</strong></p>
</li>
<li><p>Title, styles, SEO data</p>
</li>
<li><p><strong>Not visible</strong> on the page</p>
</li>
</ul>
<h3 id="heading-yga-3"><code>&lt;body&gt;</code></h3>
<ul>
<li><p>Visible content</p>
</li>
<li><p>Text, images, buttons, links</p>
</li>
</ul>
<h2 id="heading-html-tags-and-elements">HTML Tags and Elements</h2>
<h3 id="heading-what-is-a-tag">What is a Tag?</h3>
<p>A tag is used to <strong>define content</strong>.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<ul>
<li><p><code>&lt;p&gt;</code> → Opening tag</p>
</li>
<li><p><code>&lt;/p&gt;</code> → Closing tag</p>
</li>
</ul>
<h3 id="heading-what-is-an-element">What is an Element?</h3>
<p>An <strong>element = opening tag + content + closing tag</strong></p>
<h2 id="heading-common-html-tags">Common HTML Tags</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Tag</td><td>Purpose</td></tr>
</thead>
<tbody>
<tr>
<td><code>&lt;h1&gt;</code></td><td>Main heading</td></tr>
<tr>
<td><code>&lt;p&gt;</code></td><td>Paragraph</td></tr>
<tr>
<td><code>&lt;a&gt;</code></td><td>Link</td></tr>
<tr>
<td><code>&lt;img&gt;</code></td><td>Image</td></tr>
<tr>
<td><code>&lt;ul&gt;</code></td><td>Unordered list</td></tr>
<tr>
<td><code>&lt;li&gt;</code></td><td>List item</td></tr>
</tbody>
</table>
</div><h3 id="heading-example-1">Example</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://google.com"</span>&gt;</span>Go to Google<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<h2 id="heading-good-html-practices">Good HTML Practices ✅</h2>
<h3 id="heading-1-properly-nest-tags">1. Properly Nest Tags</h3>
<p>❌ Wrong</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>Hello<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span>
</code></pre>
<p>✅ Correct</p>
<pre><code class="lang-javascript">&lt;p&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>Hello<span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span></span>&lt;/p&gt;
</code></pre>
<h3 id="heading-2-use-meaningful-tag-names">2. Use Meaningful Tag Names</h3>
<p>❌ Bad</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Article Title<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>✅ Good</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Article Title<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>Meaningful tags improve:</p>
<ul>
<li><p>Readability</p>
</li>
<li><p>SEO</p>
</li>
<li><p>Accessibility</p>
</li>
</ul>
<h2 id="heading-semantic-vs-non-semantic-tags">Semantic vs Non-Semantic Tags</h2>
<h3 id="heading-non-semantic-tags">Non-Semantic Tags ❌</h3>
<p>They <strong>don’t describe content meaning</strong>.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Text<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-semantic-tags">Semantic Tags ✅</h3>
<p>They clearly describe <strong>what the content is</strong>.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Blog<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is an article.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
</code></pre>
<h2 id="heading-comparison-table">Comparison Table 📊</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Semantic Tags</td><td>Non-Semantic Tags</td></tr>
</thead>
<tbody>
<tr>
<td><code>&lt;header&gt;</code></td><td><code>&lt;div&gt;</code></td></tr>
<tr>
<td><code>&lt;footer&gt;</code></td><td><code>&lt;span&gt;</code></td></tr>
<tr>
<td><code>&lt;article&gt;</code></td><td><code>&lt;div&gt;</code></td></tr>
<tr>
<td><code>&lt;section&gt;</code></td><td><code>&lt;div&gt;</code></td></tr>
</tbody>
</table>
</div><h2 id="heading-why-semantic-html-matters">Why Semantic HTML Matters?</h2>
<ul>
<li><p>✅ Better SEO</p>
</li>
<li><p>✅ Screen reader friendly</p>
</li>
<li><p>✅ Clean &amp; readable code</p>
</li>
<li><p>✅ Professional websites</p>
</li>
</ul>
<p>Google <strong>understands your content better</strong> when you use semantic tags.</p>
<h2 id="heading-simple-real-world-example">Simple Real-World Example</h2>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>My Blog<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to My Blog<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This blog is about web development.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>© 2025 My Blog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[JavaScript Functions Explained: Declaration vs Expression vs Arrow Functions]]></title><description><![CDATA[Functions are one of the most important concepts in JavaScript. They help us organize code, avoid repetition, and build reusable logic.
In this article, we’ll cover:

Why functions are important

Function Declaration vs Function Expression

Arrow Fun...]]></description><link>https://arjun-js-blog.hashnode.dev/javascript-functions-explained-declaration-vs-expression-vs-arrow-functions</link><guid isPermaLink="true">https://arjun-js-blog.hashnode.dev/javascript-functions-explained-declaration-vs-expression-vs-arrow-functions</guid><category><![CDATA[js]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Arjun Saxena]]></dc:creator><pubDate>Wed, 03 Dec 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766387612376/d3e71758-9ea6-4a06-8fe6-8fdc197efd71.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Functions are one of the most important concepts in JavaScript. They help us <strong>organize code</strong>, <strong>avoid repetition</strong>, and <strong>build reusable logic</strong>.</p>
<p>In this article, we’ll cover:</p>
<ul>
<li><p>Why functions are important</p>
</li>
<li><p>Function Declaration vs Function Expression</p>
</li>
<li><p>Arrow Functions (simple &amp; modern syntax)</p>
</li>
<li><p>Real-world use cases of closures</p>
</li>
<li><p>Easy diagrams &amp; tables to understand everything</p>
</li>
</ul>
<h2 id="heading-why-do-we-need-functions">Why Do We Need Functions?</h2>
<p>Imagine writing the same code again and again. That’s <strong>bad practice</strong>.</p>
<h3 id="heading-without-a-function">Without a function ❌</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">10</span>;
<span class="hljs-keyword">let</span> b = <span class="hljs-number">20</span>;
<span class="hljs-built_in">console</span>.log(a + b);

<span class="hljs-keyword">let</span> x = <span class="hljs-number">5</span>;
<span class="hljs-keyword">let</span> y = <span class="hljs-number">15</span>;
<span class="hljs-built_in">console</span>.log(x + y);
</code></pre>
<h3 id="heading-with-a-function">With a function ✅</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">num1, num2</span>) </span>{
  <span class="hljs-keyword">return</span> num1 + num2;
}

<span class="hljs-built_in">console</span>.log(add(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>));
<span class="hljs-built_in">console</span>.log(add(<span class="hljs-number">5</span>, <span class="hljs-number">15</span>));
</code></pre>
<h3 id="heading-benefits-of-functions">Benefits of Functions</h3>
<ul>
<li><p>✅ Code reusability</p>
</li>
<li><p>✅ Better readability</p>
</li>
<li><p>✅ Easy maintenance</p>
</li>
<li><p>✅ Modular code structure</p>
</li>
</ul>
<h2 id="heading-function-declaration">Function Declaration</h2>
<p>A <strong>function declaration</strong> defines a function using the <code>function</code> keyword.</p>
<h3 id="heading-example">Example</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`Hello, <span class="hljs-subst">${name}</span>`</span>;
}

<span class="hljs-built_in">console</span>.log(greet(<span class="hljs-string">"Arjun"</span>));
</code></pre>
<h3 id="heading-key-points">Key Points</h3>
<ul>
<li><p>Can be used <strong>before it is defined</strong></p>
</li>
<li><p>Hoisted by JavaScript</p>
</li>
</ul>
<pre><code class="lang-javascript">sayHello(); <span class="hljs-comment">// Works</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHello</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello!"</span>);
}
</code></pre>
<h2 id="heading-function-expression">Function Expression</h2>
<p>A <strong>function expression</strong> stores a function inside a variable.</p>
<h3 id="heading-example-1">Example</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> greet = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`Hello, <span class="hljs-subst">${name}</span>`</span>;
};

<span class="hljs-built_in">console</span>.log(greet(<span class="hljs-string">"Arjun"</span>));
</code></pre>
<h3 id="heading-important-note">Important Note ⚠️</h3>
<p>Function expressions are <strong>NOT hoisted</strong>.</p>
<pre><code class="lang-javascript">sayHi(); <span class="hljs-comment">// ❌ Error</span>

<span class="hljs-keyword">const</span> sayHi = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hi!"</span>);
};
</code></pre>
<h2 id="heading-comparison-table">Comparison Table 📊</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Function Declaration</td><td>Function Expression</td></tr>
</thead>
<tbody>
<tr>
<td>Syntax</td><td><code>function myFunc()</code></td><td><code>const myFunc = function()</code></td></tr>
<tr>
<td>Hoisting</td><td>✅ Yes</td><td>❌ No</td></tr>
<tr>
<td>Usage before definition</td><td>✅ Allowed</td><td>❌ Not allowed</td></tr>
<tr>
<td>Common Use</td><td>General purpose</td><td>Callbacks, dynamic logic</td></tr>
</tbody>
</table>
</div><h2 id="heading-arrow-functions-es6">Arrow Functions (ES6)</h2>
<p>Arrow functions provide a <strong>shorter and cleaner syntax</strong>.</p>
<h3 id="heading-normal-function">Normal Function</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">multiply</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a * b;
}
</code></pre>
<h3 id="heading-arrow-function">Arrow Function</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> multiply = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a * b;
</code></pre>
<h3 id="heading-single-parameter">Single Parameter</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> square = <span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> x * x;
</code></pre>
<h3 id="heading-multiple-lines">Multiple Lines</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> calculate = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> sum = a + b;
  <span class="hljs-keyword">return</span> sum;
};
</code></pre>
<h2 id="heading-arrow-functions-vs-normal-functions">Arrow Functions vs Normal Functions</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Normal Function</td><td>Arrow Function</td></tr>
</thead>
<tbody>
<tr>
<td>Syntax</td><td>Longer</td><td>Short &amp; clean</td></tr>
<tr>
<td><code>this</code> keyword</td><td>Has its own <code>this</code></td><td>Inherits <code>this</code></td></tr>
<tr>
<td>Best for</td><td>Methods, constructors</td><td>Callbacks, short logic</td></tr>
</tbody>
</table>
</div><h2 id="heading-real-world-use-case-closures">Real-World Use Case: Closures 🔐</h2>
<p>A <strong>closure</strong> is created when a function remembers variables from its outer scope.</p>
<h3 id="heading-example-private-counter">Example: Private Counter</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createCounter</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>; <span class="hljs-comment">// private variable</span>

  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    count++;
    <span class="hljs-keyword">return</span> count;
  };
}

<span class="hljs-keyword">const</span> counter = createCounter();

<span class="hljs-built_in">console</span>.log(counter()); <span class="hljs-comment">// 1</span>
<span class="hljs-built_in">console</span>.log(counter()); <span class="hljs-comment">// 2</span>
<span class="hljs-built_in">console</span>.log(counter()); <span class="hljs-comment">// 3</span>
</code></pre>
<h3 id="heading-why-this-is-useful">Why This Is Useful?</h3>
<ul>
<li><p><code>count</code> cannot be accessed directly</p>
</li>
<li><p>Used in:</p>
<ul>
<li><p>Authentication logic</p>
</li>
<li><p>Data privacy</p>
</li>
<li><p>State management</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-real-world-example-login-attempts">Real-World Example: Login Attempts</h2>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loginTracker</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">let</span> attempts = <span class="hljs-number">0</span>;

  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    attempts++;
    <span class="hljs-keyword">return</span> <span class="hljs-string">`Login attempt: <span class="hljs-subst">${attempts}</span>`</span>;
  };
}

<span class="hljs-keyword">const</span> trackLogin = loginTracker();

<span class="hljs-built_in">console</span>.log(trackLogin());
<span class="hljs-built_in">console</span>.log(trackLogin());
</code></pre>
]]></content:encoded></item></channel></rss>