<?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[ViralJain]]></title><description><![CDATA[ViralJain]]></description><link>https://blog.jainviral.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 22 May 2026 04:19:48 GMT</lastBuildDate><atom:link href="https://blog.jainviral.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[JavaScript Operators: The Basics You Need to Know]]></title><description><![CDATA[When writing programs in JavaScript, we often perform operations such as:

Adding numbers

Comparing values

Checking conditions


To perform these actions, JavaScript provides operators.
Operators he]]></description><link>https://blog.jainviral.com/javascript-operators-the-basics-you-need-to-know</link><guid isPermaLink="true">https://blog.jainviral.com/javascript-operators-the-basics-you-need-to-know</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:30:37 GMT</pubDate><content:encoded><![CDATA[<p>When writing programs in <strong>JavaScript</strong>, we often perform operations such as:</p>
<ul>
<li><p>Adding numbers</p>
</li>
<li><p>Comparing values</p>
</li>
<li><p>Checking conditions</p>
</li>
</ul>
<p>To perform these actions, JavaScript provides <strong>operators</strong>.</p>
<p>Operators help us <strong>manipulate values and perform calculations in code</strong>.</p>
<hr />
<h1>What Are Operators?</h1>
<p>An <strong>operator</strong> is a symbol used to perform an operation on values.</p>
<p>Example:</p>
<pre><code class="language-javascript">let result = 5 + 3;
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>5</code> and <code>3</code> are <strong>operands</strong></p>
</li>
<li><p><code>+</code> is the <strong>operator</strong></p>
</li>
</ul>
<p>Output:</p>
<pre><code class="language-plaintext">8
</code></pre>
<p>Operators allow JavaScript to perform <strong>mathematical operations, comparisons, and logical checks</strong>.</p>
<hr />
<h1>Arithmetic Operators</h1>
<p>Arithmetic operators are used to perform <strong>mathematical calculations</strong>.</p>
<table>
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td><code>+</code></td>
<td>Addition</td>
<td><code>5 + 3</code></td>
</tr>
<tr>
<td><code>-</code></td>
<td>Subtraction</td>
<td><code>5 - 3</code></td>
</tr>
<tr>
<td><code>*</code></td>
<td>Multiplication</td>
<td><code>5 * 3</code></td>
</tr>
<tr>
<td><code>/</code></td>
<td>Division</td>
<td><code>6 / 3</code></td>
</tr>
<tr>
<td><code>%</code></td>
<td>Modulus (remainder)</td>
<td><code>7 % 2</code></td>
</tr>
</tbody></table>
<p>Example:</p>
<pre><code class="language-javascript">let a = 10;
let b = 5;

console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">15
5
50
2
0
</code></pre>
<p>The <code>%</code> operator returns the <strong>remainder after division</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">7 % 2 = 1
</code></pre>
<hr />
<h1>Comparison Operators</h1>
<p>Comparison operators compare two values and return <strong>true or false</strong>.</p>
<table>
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>==</code></td>
<td>Equal to</td>
</tr>
<tr>
<td><code>===</code></td>
<td>Strict equal</td>
</tr>
<tr>
<td><code>!=</code></td>
<td>Not equal</td>
</tr>
<tr>
<td><code>&gt;</code></td>
<td>Greater than</td>
</tr>
<tr>
<td><code>&lt;</code></td>
<td>Less than</td>
</tr>
</tbody></table>
<p>Example:</p>
<pre><code class="language-javascript">console.log(5 &gt; 3);
console.log(5 &lt; 3);
console.log(5 == "5");
console.log(5 === "5");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
false
true
false
</code></pre>
<hr />
<h1>Difference Between <code>==</code> and <code>===</code></h1>
<p>This is a very important concept.</p>
<h3><code>==</code> (Loose Equality)</h3>
<p>Compares <strong>values only</strong>.</p>
<pre><code class="language-javascript">console.log(5 == "5");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
</code></pre>
<p>JavaScript converts the string <code>"5"</code> into a number.</p>
<hr />
<h3><code>===</code> (Strict Equality)</h3>
<p>Compares <strong>value AND data type</strong>.</p>
<pre><code class="language-javascript">console.log(5 === "5");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">false
</code></pre>
<p>Because:</p>
<ul>
<li><p><code>5</code> → number</p>
</li>
<li><p><code>"5"</code> → string</p>
</li>
</ul>
<p>Best practice: <strong>prefer</strong> <code>===</code> <strong>in most cases</strong>.</p>
<hr />
<h1>Logical Operators</h1>
<p>Logical operators are used when <strong>working with conditions</strong>.</p>
<table>
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>&amp;&amp;</code></td>
<td>AND</td>
</tr>
<tr>
<td>`</td>
<td></td>
</tr>
<tr>
<td><code>!</code></td>
<td>NOT</td>
</tr>
</tbody></table>
<hr />
<h3>Logical AND <code>&amp;&amp;</code></h3>
<p>Returns true only if <strong>both conditions are true</strong>.</p>
<pre><code class="language-javascript">let age = 20;

console.log(age &gt; 18 &amp;&amp; age &lt; 30);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
</code></pre>
<hr />
<h3>Logical OR <code>||</code></h3>
<p>Returns true if <strong>at least one condition is true</strong>.</p>
<pre><code class="language-javascript">console.log(5 &gt; 10 || 10 &gt; 5);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
</code></pre>
<hr />
<h3>Logical NOT <code>!</code></h3>
<p>Reverses a boolean value.</p>
<pre><code class="language-javascript">console.log(!true);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">false
</code></pre>
<hr />
<h1>Truth Table for Logical Operators</h1>
<p>| A | B | A &amp;&amp; B | A || B |
| --- | --- | --- | --- |
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |</p>
<hr />
<h1>Assignment Operators</h1>
<p>Assignment operators assign values to variables.</p>
<table>
<thead>
<tr>
<th>Operator</th>
<th>Example</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>=</code></td>
<td><code>x = 5</code></td>
<td>Assign value</td>
</tr>
<tr>
<td><code>+=</code></td>
<td><code>x += 2</code></td>
<td>Add and assign</td>
</tr>
<tr>
<td><code>-=</code></td>
<td><code>x -= 2</code></td>
<td>Subtract and assign</td>
</tr>
</tbody></table>
<p>Example:</p>
<pre><code class="language-javascript">let x = 10;

x += 5;
console.log(x);

x -= 3;
console.log(x);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">15
12
</code></pre>
<hr />
<h1>Assignment Practice</h1>
<h2>Perform Arithmetic Operations</h2>
<pre><code class="language-javascript">let a = 8;
let b = 4;

console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
</code></pre>
<hr />
<h1>Compare Values Using <code>==</code> and <code>===</code></h1>
<pre><code class="language-javascript">console.log(10 == "10");
console.log(10 === "10");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
false
</code></pre>
<hr />
<h1>Logical Operator Example</h1>
<pre><code class="language-javascript">let age = 22;

if (age &gt; 18 &amp;&amp; age &lt; 60) {
  console.log("Eligible to work");
}
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Eligible to work
</code></pre>
<hr />
<h1>Operator Categories Summary</h1>
<table>
<thead>
<tr>
<th>Category</th>
<th>Operators</th>
</tr>
</thead>
<tbody><tr>
<td>Arithmetic</td>
<td><code>+ - * / %</code></td>
</tr>
<tr>
<td>Comparison</td>
<td><code>== === != &gt; &lt;</code></td>
</tr>
<tr>
<td>Logical</td>
<td>`&amp;&amp;</td>
</tr>
<tr>
<td>Assignment</td>
<td><code>= += -=</code></td>
</tr>
</tbody></table>
<hr />
]]></content:encoded></item><item><title><![CDATA[The Magic of this, call(), apply(), and bind() in JavaScript]]></title><description><![CDATA[When working with JavaScript, you will often encounter the keyword this.
Many beginners find this confusing at first, but once you understand how it works, it becomes a powerful feature for writing fl]]></description><link>https://blog.jainviral.com/the-magic-of-this-call-apply-and-bind-in-javascript</link><guid isPermaLink="true">https://blog.jainviral.com/the-magic-of-this-call-apply-and-bind-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:28:33 GMT</pubDate><content:encoded><![CDATA[<p>When working with <strong>JavaScript</strong>, you will often encounter the keyword <code>this</code>.</p>
<p>Many beginners find <code>this</code> confusing at first, but once you understand how it works, it becomes a powerful feature for writing flexible and reusable code.</p>
<p>In this article, we will understand:</p>
<ul>
<li><p>What <code>this</code> means in JavaScript</p>
</li>
<li><p><code>this</code> inside normal functions</p>
</li>
<li><p><code>this</code> inside objects</p>
</li>
<li><p>What <code>call()</code>, <code>apply()</code>, and <code>bind()</code> do</p>
</li>
<li><p>Differences between them</p>
</li>
</ul>
<hr />
<h1>What <code>this</code> Means in JavaScript</h1>
<p>In simple terms:</p>
<p>👉 <code>this</code> <strong>refers to the object that is calling the function.</strong></p>
<p>You can think of it as answering the question:</p>
<p><strong>“Who is calling this function?”</strong></p>
<hr />
<h1><code>this</code> Inside Normal Functions</h1>
<p>When <code>this</code> is used in a normal function (in a browser environment), it usually refers to the <strong>global object</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">function show() {
  console.log(this);
}

show();
</code></pre>
<p>In browsers, this typically prints the <strong>window object</strong>.</p>
<hr />
<h1><code>this</code> Inside Objects</h1>
<p>When a function is inside an object, <code>this</code> refers to <strong>that object</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Rahul",
  greet: function() {
    console.log("Hello, my name is " + this.name);
  }
};

person.greet();
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;6dbgs9&quot;">Hello, my name is Rahul
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>this</code> refers to the <strong>person object</strong></p>
</li>
<li><p><code>this.name</code> accesses the property of that object</p>
</li>
</ul>
<hr />
<h1>What <code>call()</code> Does</h1>
<p>The <code>call()</code> method allows us to <strong>call a function with a specific object as</strong> <code>this</code>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person1 = {
  name: "Rahul"
};

let person2 = {
  name: "Amit"
};

function greet(city) {
  console.log("Hello " + this.name + " from " + city);
}

greet.call(person1, "Delhi");
greet.call(person2, "Mumbai");
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;3okg1k&quot;">Hello Rahul from Delhi
Hello Amit from Mumbai
</code></pre>
<p>Here <code>call()</code> sets <strong>which object</strong> <code>this</code> <strong>refers to</strong>.</p>
<hr />
<h1>What <code>apply()</code> Does</h1>
<p><code>apply()</code> works almost the same as <code>call()</code>.</p>
<p>The difference is <strong>how arguments are passed</strong>.</p>
<ul>
<li><p><code>call()</code> → arguments passed individually</p>
</li>
<li><p><code>apply()</code> → arguments passed as an array</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Rahul"
};

function greet(city, country) {
  console.log(this.name + " from " + city + ", " + country);
}

greet.apply(person, ["Delhi", "India"]);
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;ra5b68&quot;">Rahul from Delhi, India
</code></pre>
<hr />
<h1>What <code>bind()</code> Does</h1>
<p>Unlike <code>call()</code> and <code>apply()</code>, the <code>bind()</code> method <strong>does not execute the function immediately</strong>.</p>
<p>Instead, it <strong>returns a new function with</strong> <code>this</code> <strong>bound to the given object</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Rahul"
};

function greet() {
  console.log("Hello " + this.name);
}

let greetPerson = greet.bind(person);

greetPerson();
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;vdphk0&quot;">Hello Rahul
</code></pre>
<p>Here <code>bind()</code> creates a <strong>new function with fixed</strong> <code>this</code>.</p>
<hr />
<h1>Difference Between <code>call()</code>, <code>apply()</code>, and <code>bind()</code></h1>
<table>
<thead>
<tr>
<th>Method</th>
<th>Executes Immediately</th>
<th>Arguments Format</th>
<th>Returns New Function</th>
</tr>
</thead>
<tbody><tr>
<td>call()</td>
<td>Yes</td>
<td>Individual arguments</td>
<td>No</td>
</tr>
<tr>
<td>apply()</td>
<td>Yes</td>
<td>Array of arguments</td>
<td>No</td>
</tr>
<tr>
<td>bind()</td>
<td>No</td>
<td>Individual arguments</td>
<td>Yes</td>
</tr>
</tbody></table>
<hr />
<h1>Assignment Practice</h1>
<h2>Create an Object with a Method</h2>
<pre><code class="language-javascript">let student = {
  name: "Ravi",
  showName: function() {
    console.log(this.name);
  }
};

student.showName();
</code></pre>
<hr />
<h1>Borrow Method Using <code>call()</code></h1>
<pre><code class="language-javascript">let student1 = { name: "Ravi" };
let student2 = { name: "Priya" };

function showName() {
  console.log(this.name);
}

showName.call(student1);
showName.call(student2);
</code></pre>
<hr />
<h1>Use <code>apply()</code> with Array Arguments</h1>
<pre><code class="language-javascript">function introduce(city, country) {
  console.log(this.name + " from " + city + ", " + country);
}

let person = { name: "Rahul" };

introduce.apply(person, ["Delhi", "India"]);
</code></pre>
<hr />
<h1>Use <code>bind()</code> and Store Function</h1>
<pre><code class="language-javascript">let person = { name: "Amit" };

function greet() {
  console.log("Hello " + this.name);
}

let greetAmit = greet.bind(person);

greetAmit();
</code></pre>
<hr />
<h1>Visual Idea: Who Calls the Function?</h1>
<p>Example:</p>
<pre><code class="language-id=&quot;57bdcd&quot;">Function → greet()

Caller → person object

this → person
</code></pre>
<p>So the <strong>caller determines the value of</strong> <code>this</code>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Function Declaration vs Function Expression: What’s the Difference?]]></title><description><![CDATA[Functions are one of the most important concepts in JavaScript.
They allow developers to reuse code instead of writing the same logic multiple times.
For example, if we need to calculate something lik]]></description><link>https://blog.jainviral.com/function-declaration-vs-function-expression-what-s-the-difference</link><guid isPermaLink="true">https://blog.jainviral.com/function-declaration-vs-function-expression-what-s-the-difference</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:26:53 GMT</pubDate><content:encoded><![CDATA[<p>Functions are one of the most important concepts in <strong>JavaScript</strong>.</p>
<p>They allow developers to <strong>reuse code</strong> instead of writing the same logic multiple times.</p>
<p>For example, if we need to calculate something like addition or multiplication multiple times, we can create a <strong>function</strong> and call it whenever needed.</p>
<hr />
<h1>What Are Functions?</h1>
<p>A <strong>function</strong> is a <strong>reusable block of code that performs a specific task</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">function add(a, b) {
  return a + b;
}

console.log(add(5, 3));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">8
</code></pre>
<p>Here the function <strong>adds two numbers</strong> and returns the result.</p>
<hr />
<h1>Function Declaration</h1>
<p>A <strong>function declaration</strong> defines a function using the <code>function</code> keyword with a name.</p>
<h3>Syntax</h3>
<pre><code class="language-javascript">function functionName(parameters) {
  // code
}
</code></pre>
<h3>Example</h3>
<pre><code class="language-javascript">function multiply(a, b) {
  return a * b;
}

console.log(multiply(4, 5));
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">20
</code></pre>
<p>This is the <strong>traditional and commonly used way</strong> to define functions.</p>
<hr />
<h1>Function Expression</h1>
<p>A <strong>function expression</strong> is when a function is <strong>stored inside a variable</strong>.</p>
<h3>Syntax</h3>
<pre><code class="language-javascript">const functionName = function(parameters) {
  // code
};
</code></pre>
<h3>Example</h3>
<pre><code class="language-javascript">const multiply = function(a, b) {
  return a * b;
};

console.log(multiply(4, 5));
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">20
</code></pre>
<p>Here the function is <strong>assigned to a variable</strong>.</p>
<hr />
<h1>Declaration vs Expression (Side-by-Side)</h1>
<h3>Function Declaration</h3>
<pre><code class="language-javascript">function greet(name) {
  return "Hello " + name;
}
</code></pre>
<h3>Function Expression</h3>
<pre><code class="language-javascript">const greet = function(name) {
  return "Hello " + name;
};
</code></pre>
<p>Both produce the <strong>same output</strong>, but they behave slightly differently.</p>
<hr />
<h1>Basic Idea of Hoisting</h1>
<p>In JavaScript, some declarations are <strong>moved to the top of their scope during execution</strong>.<br />This behavior is called <strong>hoisting</strong>.</p>
<hr />
<h3>Function Declaration (Hoisted)</h3>
<p>You can call the function <strong>before it is defined</strong>.</p>
<pre><code class="language-javascript">console.log(add(2,3));

function add(a,b){
  return a+b;
}
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">5
</code></pre>
<p>This works because <strong>function declarations are hoisted</strong>.</p>
<hr />
<h3>Function Expression (Not Hoisted)</h3>
<p>Calling it before definition causes an error.</p>
<pre><code class="language-javascript">console.log(add(2,3));

const add = function(a,b){
  return a+b;
};
</code></pre>
<p>This will cause an error because the variable is <strong>not initialized yet</strong>.</p>
<hr />
<h1>Key Differences</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Function Declaration</th>
<th>Function Expression</th>
</tr>
</thead>
<tbody><tr>
<td>Syntax</td>
<td>Uses <code>function</code> keyword</td>
<td>Function stored in variable</td>
</tr>
<tr>
<td>Hoisting</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td>Call before definition</td>
<td>Works</td>
<td>Causes error</td>
</tr>
<tr>
<td>Usage</td>
<td>General functions</td>
<td>Callbacks, dynamic functions</td>
</tr>
</tbody></table>
<hr />
<h1>When to Use Each Type</h1>
<h3>Use Function Declaration</h3>
<ul>
<li><p>For <strong>general reusable functions</strong></p>
</li>
<li><p>When you want the function available anywhere in the file</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">function calculateTotal(price, tax) {
  return price + tax;
}
</code></pre>
<hr />
<h3>Use Function Expression</h3>
<ul>
<li><p>When assigning functions to variables</p>
</li>
<li><p>When passing functions as arguments</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">const greetUser = function(name) {
  return "Hello " + name;
};
</code></pre>
<hr />
<h1>Assignment Practice</h1>
<h2>Function Declaration</h2>
<pre><code class="language-javascript">function multiply(a, b) {
  return a * b;
}

console.log(multiply(3, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">12
</code></pre>
<hr />
<h1>Function Expression</h1>
<pre><code class="language-javascript">const multiplyExp = function(a, b) {
  return a * b;
};

console.log(multiplyExp(3, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">12
</code></pre>
<hr />
<h1>Try Calling Before Definition</h1>
<h3>Declaration (Works)</h3>
<pre><code class="language-javascript">console.log(square(4));

function square(num){
  return num * num;
}
</code></pre>
<hr />
<h3>Expression (Error)</h3>
<pre><code class="language-javascript">console.log(square(4));

const square = function(num){
  return num * num;
};
</code></pre>
<p>This will produce an <strong>error because function expressions are not hoisted</strong>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[JavaScript Arrays 101]]></title><description><![CDATA[When writing programs in JavaScript, we often need to store multiple values together.
For example:

A list of favorite movies

A list of student marks

A list of tasks


Instead of creating many varia]]></description><link>https://blog.jainviral.com/javascript-arrays-101</link><guid isPermaLink="true">https://blog.jainviral.com/javascript-arrays-101</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:24:49 GMT</pubDate><content:encoded><![CDATA[<p>When writing programs in <strong>JavaScript</strong>, we often need to store <strong>multiple values together</strong>.</p>
<p>For example:</p>
<ul>
<li><p>A list of <strong>favorite movies</strong></p>
</li>
<li><p>A list of <strong>student marks</strong></p>
</li>
<li><p>A list of <strong>tasks</strong></p>
</li>
</ul>
<p>Instead of creating many variables, JavaScript provides <strong>arrays</strong> to store collections of values efficiently.</p>
<hr />
<h1>What Are Arrays?</h1>
<p>An <strong>array</strong> is a <strong>collection of values stored in a specific order</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];
</code></pre>
<p>Here the array contains <strong>three elements</strong>:</p>
<table>
<thead>
<tr>
<th>Index</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>Apple</td>
</tr>
<tr>
<td>1</td>
<td>Banana</td>
</tr>
<tr>
<td>2</td>
<td>Orange</td>
</tr>
</tbody></table>
<p>Important point:</p>
<p>⚠️ <strong>Array indexing starts from 0</strong>.</p>
<hr />
<h1>Why We Need Arrays</h1>
<p>Imagine storing fruit names using separate variables.</p>
<pre><code class="language-javascript">let fruit1 = "Apple";
let fruit2 = "Banana";
let fruit3 = "Orange";
</code></pre>
<p>This works, but managing many variables becomes difficult.</p>
<p>Using an array is much easier:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];
</code></pre>
<p>Now all values are stored <strong>in one structure</strong>.</p>
<hr />
<h1>How to Create an Array</h1>
<p>Arrays are created using <strong>square brackets</strong> <code>[ ]</code>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let numbers = [10, 20, 30, 40];
</code></pre>
<p>You can store different types of values:</p>
<pre><code class="language-javascript">let data = ["Viral", 22, true];
</code></pre>
<p>But usually arrays store <strong>similar types of data</strong>.</p>
<hr />
<h1>Accessing Elements Using Index</h1>
<p>Each array element has an <strong>index position</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];

console.log(fruits[0]);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Apple
</code></pre>
<p>Access second element:</p>
<pre><code class="language-javascript">console.log(fruits[1]);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Banana
</code></pre>
<hr />
<h1>Updating Array Elements</h1>
<p>Array values can be changed using their index.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];

fruits[1] = "Mango";

console.log(fruits);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">["Apple", "Mango", "Orange"]
</code></pre>
<p>Here <strong>Banana was replaced by Mango</strong>.</p>
<hr />
<h1>Array Length Property</h1>
<p>The <code>.length</code> property tells us <strong>how many elements are in the array</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];

console.log(fruits.length);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">3
</code></pre>
<p>This is very useful when working with loops.</p>
<hr />
<h1>Looping Over Arrays</h1>
<p>To access all elements, we usually use a <strong>loop</strong>.</p>
<p>Example using a <strong>for loop</strong>:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];

for (let i = 0; i &lt; fruits.length; i++) {
  console.log(fruits[i]);
}
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Apple
Banana
Orange
</code></pre>
<p>The loop runs <strong>once for each element in the array</strong>.</p>
<hr />
<h1>Visual Representation of an Array</h1>
<p>Example array:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Orange"];
</code></pre>
<p>Visual structure:</p>
<pre><code class="language-plaintext">Index →   0        1        2
        -------------------------
Value →  Apple   Banana   Orange
</code></pre>
<p>Each value is stored at a <strong>specific index position</strong>.</p>
<hr />
<h1>Assignment Practice</h1>
<h2>1️⃣ Create an Array of Favorite Movies</h2>
<pre><code class="language-javascript">let movies = [
  "Inception",
  "Interstellar",
  "Avengers",
  "Batman",
  "Joker"
];
</code></pre>
<hr />
<h1>2️⃣ Print First and Last Element</h1>
<pre><code class="language-javascript">console.log(movies[0]);
console.log(movies[movies.length - 1]);
</code></pre>
<hr />
<h1>3️⃣ Change One Value</h1>
<pre><code class="language-javascript">movies[2] = "Spider-Man";

console.log(movies);
</code></pre>
<hr />
<h1>4️⃣ Loop Through the Array</h1>
<pre><code class="language-javascript">for (let i = 0; i &lt; movies.length; i++) {
  console.log(movies[i]);
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Understanding Object-Oriented Programming in JavaScript]]></title><description><![CDATA[Modern applications in JavaScript often deal with complex data and behaviors.To organize code better, developers use a programming style called Object-Oriented Programming (OOP).
OOP helps us structur]]></description><link>https://blog.jainviral.com/understanding-object-oriented-programming-in-javascript</link><guid isPermaLink="true">https://blog.jainviral.com/understanding-object-oriented-programming-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:15:14 GMT</pubDate><content:encoded><![CDATA[<p>Modern applications in <strong>JavaScript</strong> often deal with complex data and behaviors.<br />To organize code better, developers use a programming style called <strong>Object-Oriented Programming (OOP)</strong>.</p>
<p>OOP helps us structure programs using <strong>objects and classes</strong>, making code easier to manage, reuse, and understand.</p>
<hr />
<h1>What is Object-Oriented Programming (OOP)?</h1>
<p><strong>Object-Oriented Programming</strong> is a programming approach where we organize code into <strong>objects that contain data and functions</strong>.</p>
<p>In simple words:</p>
<ul>
<li><p><strong>Objects</strong> store information</p>
</li>
<li><p><strong>Methods</strong> perform actions on that information</p>
</li>
</ul>
<p>Example:</p>
<p>A <strong>student object</strong> might have:</p>
<ul>
<li><p>name</p>
</li>
<li><p>age</p>
</li>
<li><p>course</p>
</li>
</ul>
<p>And a method like:</p>
<ul>
<li>displayStudentDetails()</li>
</ul>
<p>This approach helps keep related data and behavior together.</p>
<hr />
<h1>Real-World Analogy: Blueprint → Objects</h1>
<p>Think about building cars.</p>
<p>A <strong>blueprint</strong> describes how a car should look and behave:</p>
<ul>
<li><p>color</p>
</li>
<li><p>engine</p>
</li>
<li><p>speed</p>
</li>
<li><p>start()</p>
</li>
</ul>
<p>From that blueprint, we can create many <strong>cars</strong>.</p>
<p>In programming:</p>
<table>
<thead>
<tr>
<th>Real World</th>
<th>Programming</th>
</tr>
</thead>
<tbody><tr>
<td>Blueprint</td>
<td>Class</td>
</tr>
<tr>
<td>Actual Car</td>
<td>Object</td>
</tr>
<tr>
<td>Features</td>
<td>Properties</td>
</tr>
<tr>
<td>Actions</td>
<td>Methods</td>
</tr>
</tbody></table>
<p>So a <strong>class acts as a blueprint</strong>, and objects are created from that blueprint.</p>
<hr />
<h1>What is a Class in JavaScript?</h1>
<p>A <strong>class</strong> is a template used to create objects.</p>
<p>Classes were introduced in modern JavaScript through <strong>ES6</strong>.</p>
<p>Example class:</p>
<pre><code class="language-javascript">class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>Person</code> is the <strong>class</strong></p>
</li>
<li><p><code>name</code> and <code>age</code> are <strong>properties</strong></p>
</li>
</ul>
<hr />
<h1>Creating Objects Using Classes</h1>
<p>Objects are created using the <strong>new keyword</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}

let person1 = new Person("Rahul", 25);
let person2 = new Person("Amit", 30);

console.log(person1.name);
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;f6khcs&quot;">Rahul
</code></pre>
<p>Each object has <strong>its own data</strong>.</p>
<hr />
<h1>Constructor Method</h1>
<p>The <strong>constructor</strong> is a special method inside a class.</p>
<p>It runs <strong>automatically when an object is created</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">class Car {
  constructor(brand, year) {
    this.brand = brand;
    this.year = year;
  }
}
</code></pre>
<p>When we create an object:</p>
<pre><code class="language-javascript">let myCar = new Car("Toyota", 2022);
</code></pre>
<p>The constructor automatically assigns:</p>
<pre><code class="language-id=&quot;gecv9e&quot;">brand = Toyota
year = 2022
</code></pre>
<hr />
<h1>Methods Inside a Class</h1>
<p>Classes can also contain <strong>methods</strong> (functions inside the class).</p>
<p>Example:</p>
<pre><code class="language-javascript">class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log("Hello, my name is " + this.name);
  }
}
</code></pre>
<p>Using the method:</p>
<pre><code class="language-javascript">let user = new Person("Ravi", 22);

user.greet();
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;ufnuxp&quot;">Hello, my name is Ravi
</code></pre>
<hr />
<h1>Basic Idea of Encapsulation</h1>
<p>Encapsulation means <strong>keeping related data and methods together inside a class</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">class BankAccount {
  constructor(balance) {
    this.balance = balance;
  }

  deposit(amount) {
    this.balance += amount;
  }
}
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>balance</code> is stored inside the object</p>
</li>
<li><p><code>deposit()</code> modifies it</p>
</li>
</ul>
<p>So <strong>data and behavior stay together</strong>.</p>
<p>This makes code <strong>organized and easier to maintain</strong>.</p>
<hr />
<h1>Assignment Practice</h1>
<h2>Create a Student Class</h2>
<pre><code class="language-javascript">class Student {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  printDetails() {
    console.log("Name: " + this.name);
    console.log("Age: " + this.age);
  }
}
</code></pre>
<hr />
<h1>Create Multiple Student Objects</h1>
<pre><code class="language-javascript">let student1 = new Student("Rahul", 20);
let student2 = new Student("Priya", 21);

student1.printDetails();
student2.printDetails();
</code></pre>
<p>Output:</p>
<pre><code class="language-id=&quot;rl0fyj&quot;">Name: Rahul
Age: 20

Name: Priya
Age: 21
</code></pre>
<p>Each student object has <strong>its own properties but shares the same class structure</strong>.</p>
<hr />
<h1>Visual Representation</h1>
<h3>Class → Objects</h3>
<pre><code class="language-id=&quot;94t73a&quot;">Student (Class)
│
├── student1 → Rahul, 20
└── student2 → Priya, 21
</code></pre>
<p>The <strong>class defines the structure</strong>, while <strong>objects store actual values</strong>.</p>
<hr />
<h1>Why OOP is Important</h1>
<p>Object-Oriented Programming helps developers:</p>
<ul>
<li><p>Organize large programs</p>
</li>
<li><p>Reuse code easily</p>
</li>
<li><p>Model real-world systems</p>
</li>
<li><p>Keep code clean and maintainable</p>
</li>
</ul>
<p>You will see OOP concepts used heavily in frameworks like <strong>React</strong>, backend development, and large-scale applications.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Objects in JavaScript]]></title><description><![CDATA[In JavaScript, objects are one of the most powerful ways to store and organize data.
Sometimes storing values in separate variables is not practical.
Example:
let name = "Rahul";
let age = 21;
let cit]]></description><link>https://blog.jainviral.com/understanding-objects-in-javascript</link><guid isPermaLink="true">https://blog.jainviral.com/understanding-objects-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:10:40 GMT</pubDate><content:encoded><![CDATA[<p>In <strong>JavaScript</strong>, objects are one of the most powerful ways to store and organize data.</p>
<p>Sometimes storing values in separate variables is not practical.</p>
<p>Example:</p>
<pre><code class="language-javascript">let name = "Rahul";
let age = 21;
let city = "Delhi";
</code></pre>
<p>This works, but managing related information separately becomes difficult.</p>
<p>Instead, JavaScript provides <strong>objects</strong>, which allow us to store related data together.</p>
<hr />
<h1>What Are Objects?</h1>
<p>An <strong>object</strong> is a collection of <strong>key-value pairs</strong>.</p>
<p>Example structure:</p>
<pre><code class="language-plaintext">key : value
</code></pre>
<p>Example object:</p>
<pre><code class="language-javascript">let person = {
  name: "Rahul",
  age: 21,
  city: "Delhi"
};
</code></pre>
<p>Here:</p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>Rahul</td>
</tr>
<tr>
<td>age</td>
<td>21</td>
</tr>
<tr>
<td>city</td>
<td>Delhi</td>
</tr>
</tbody></table>
<p>So the object <strong>groups related information together</strong>.</p>
<hr />
<h1>Why Objects Are Needed</h1>
<p>Objects help developers:</p>
<ul>
<li><p>Organize related data</p>
</li>
<li><p>Represent real-world entities</p>
</li>
<li><p>Make code more readable</p>
</li>
</ul>
<p>Example: representing a person.</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25,
  city: "Mumbai"
};
</code></pre>
<p>Instead of multiple variables, everything is stored <strong>inside one object</strong>.</p>
<hr />
<h1>Creating Objects</h1>
<p>Objects are created using <strong>curly braces</strong> <code>{}</code>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let car = {
  brand: "Toyota",
  model: "Camry",
  year: 2022
};
</code></pre>
<p>This object contains <strong>three properties</strong>.</p>
<hr />
<h1>Accessing Object Properties</h1>
<p>We can access object values in two ways.</p>
<hr />
<h1>Dot Notation</h1>
<p>The most common way.</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25,
  city: "Mumbai"
};

console.log(person.name);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Amit
</code></pre>
<hr />
<h1>Bracket Notation</h1>
<p>Another way to access properties.</p>
<pre><code class="language-javascript">console.log(person["age"]);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">25
</code></pre>
<p>Bracket notation is useful when property names are dynamic.</p>
<hr />
<h1>Updating Object Properties</h1>
<p>We can change existing values easily.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25
};

person.age = 26;

console.log(person.age);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">26
</code></pre>
<p>The value changed from <strong>25 → 26</strong>.</p>
<hr />
<h1>Adding New Properties</h1>
<p>Objects can grow by adding new properties.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25
};

person.city = "Mumbai";

console.log(person);
</code></pre>
<p>Output:</p>
<pre><code class="language-javascript">{
  name: "Amit",
  age: 25,
  city: "Mumbai"
}
</code></pre>
<hr />
<h1>Deleting Properties</h1>
<p>We can remove properties using the <code>delete</code> keyword.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25,
  city: "Mumbai"
};

delete person.city;

console.log(person);
</code></pre>
<p>Output:</p>
<pre><code class="language-javascript">{
  name: "Amit",
  age: 25
}
</code></pre>
<hr />
<h1>Looping Through Object Keys</h1>
<p>Sometimes we want to access <strong>all properties of an object</strong>.</p>
<p>We can use a <strong>for...in loop</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let person = {
  name: "Amit",
  age: 25,
  city: "Mumbai"
};

for (let key in person) {
  console.log(key + ": " + person[key]);
}
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">name: Amit
age: 25
city: Mumbai
</code></pre>
<p>This loop goes through <strong>every key in the object</strong>.</p>
<hr />
<h1>Difference Between Array and Object</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Array</th>
<th>Object</th>
</tr>
</thead>
<tbody><tr>
<td>Structure</td>
<td>Ordered list</td>
<td>Key-value pairs</td>
</tr>
<tr>
<td>Access</td>
<td>Index (0,1,2)</td>
<td>Property name</td>
</tr>
<tr>
<td>Use Case</td>
<td>Lists of items</td>
<td>Structured data</td>
</tr>
</tbody></table>
<p>Example array:</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "orange"];
</code></pre>
<p>Example object:</p>
<pre><code class="language-javascript">let fruit = {
  name: "apple",
  color: "red"
};
</code></pre>
<p>Arrays are used for <strong>lists</strong>, while objects are used for <strong>structured information</strong>.</p>
<hr />
<h1>Assignment Practice</h1>
<h2>Create a Student Object</h2>
<pre><code class="language-javascript">let student = {
  name: "Ravi",
  age: 20,
  course: "Computer Science"
};
</code></pre>
<hr />
<h1>Update a Property</h1>
<pre><code class="language-javascript">student.age = 21;
</code></pre>
<hr />
<h1>Loop Through Keys and Values</h1>
<pre><code class="language-javascript">for (let key in student) {
  console.log(key + ": " + student[key]);
}
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">name: Ravi
age: 21
course: Computer Science
</code></pre>
<hr />
<h1>Visual Idea of Object Structure</h1>
<p>Example object:</p>
<pre><code class="language-plaintext">student
│
├── name  → Ravi
├── age   → 21
└── course → Computer Science
</code></pre>
<p>This shows how objects store data in <strong>key-value pairs</strong>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[When learning JavaScript, one of the first things you encounter is variables and data types.
Variables allow us to store and manage information inside a program.
For example:

A user’s name

A person’]]></description><link>https://blog.jainviral.com/understanding-variables-and-data-types-in-javascript</link><guid isPermaLink="true">https://blog.jainviral.com/understanding-variables-and-data-types-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:08:20 GMT</pubDate><content:encoded><![CDATA[<p>When learning <strong>JavaScript</strong>, one of the first things you encounter is <strong>variables</strong> and <strong>data types</strong>.</p>
<p>Variables allow us to <strong>store and manage information</strong> inside a program.</p>
<p>For example:</p>
<ul>
<li><p>A user’s <strong>name</strong></p>
</li>
<li><p>A person’s <strong>age</strong></p>
</li>
<li><p>Whether a student is <strong>enrolled or not</strong></p>
</li>
</ul>
<p>Understanding these concepts is essential because almost every program relies on variables.</p>
<hr />
<h1>What Are Variables?</h1>
<p>A <strong>variable</strong> is like a <strong>box used to store information</strong>.</p>
<p>Imagine you have labeled boxes:</p>
<table>
<thead>
<tr>
<th>Box Label</th>
<th>Stored Value</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>Viral</td>
</tr>
<tr>
<td>age</td>
<td>22</td>
</tr>
<tr>
<td>city</td>
<td>Ahmedabad</td>
</tr>
</tbody></table>
<p>In programming, we store these values using variables.</p>
<p>Example:</p>
<pre><code class="language-javascript">let name = "Viral";
let age = 22;
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>name</code> stores <code>"Viral"</code></p>
</li>
<li><p><code>age</code> stores <code>22</code></p>
</li>
</ul>
<p>The program can <strong>use or modify these values later</strong>.</p>
<hr />
<h1>Declaring Variables in JavaScript</h1>
<p>In JavaScript, variables can be declared using:</p>
<ul>
<li><p><code>var</code></p>
</li>
<li><p><code>let</code></p>
</li>
<li><p><code>const</code></p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">var city = "Ahmedabad";
let age = 22;
const country = "India";
</code></pre>
<p>Each keyword behaves slightly differently.</p>
<hr />
<h1>var</h1>
<p><code>var</code> is the <strong>older way</strong> to declare variables.</p>
<p>Example:</p>
<pre><code class="language-javascript">var language = "JavaScript";

console.log(language);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">JavaScript
</code></pre>
<p>However, modern JavaScript developers prefer <strong>let</strong> and <strong>const</strong>.</p>
<hr />
<h1>let</h1>
<p><code>let</code> is used when the value <strong>may change later</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let score = 10;

score = 20;

console.log(score);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">20
</code></pre>
<p>Here the value changed from <strong>10 → 20</strong>.</p>
<hr />
<h1>const</h1>
<p><code>const</code> is used when the value <strong>should not change</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">const pi = 3.14;

console.log(pi);
</code></pre>
<p>If we try to change it:</p>
<pre><code class="language-javascript">pi = 3.1415;
</code></pre>
<p>JavaScript will produce an <strong>error</strong>.</p>
<p>So <code>const</code> is used for <strong>fixed values</strong>.</p>
<hr />
<h1>Primitive Data Types in JavaScript</h1>
<p>Data types define <strong>what type of value a variable holds</strong>.</p>
<p>Here are the most common primitive data types.</p>
<hr />
<h1>String</h1>
<p>Strings represent <strong>text values</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let name = "Viral Jain";
</code></pre>
<p>Examples of strings:</p>
<ul>
<li><p>Names</p>
</li>
<li><p>Cities</p>
</li>
<li><p>Messages</p>
</li>
</ul>
<hr />
<h1>Number</h1>
<p>Numbers represent <strong>numeric values</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let age = 22;
let price = 199.99;
</code></pre>
<p>Numbers can represent:</p>
<ul>
<li><p>age</p>
</li>
<li><p>marks</p>
</li>
<li><p>price</p>
</li>
<li><p>quantity</p>
</li>
</ul>
<hr />
<h1>Boolean</h1>
<p>Booleans represent <strong>true or false values</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let isStudent = true;
</code></pre>
<p>Boolean values are often used in <strong>conditions</strong>.</p>
<hr />
<h1>null</h1>
<p><code>null</code> means <strong>intentional empty value</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let selectedUser = null;
</code></pre>
<p>It means the variable <strong>currently has no value assigned intentionally</strong>.</p>
<hr />
<h1>undefined</h1>
<p><code>undefined</code> means a variable <strong>exists but has not been assigned a value yet</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">let phoneNumber;

console.log(phoneNumber);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">undefined
</code></pre>
<hr />
<h1>Difference Between var, let, and const</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<th>var</th>
<th>let</th>
<th>const</th>
</tr>
</thead>
<tbody><tr>
<td>Modern JavaScript</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>Can change value</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td>Recommended</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>Used for constants</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody></table>
<p>In modern JavaScript:</p>
<ul>
<li><p>Use <strong>let</strong> for variables that change</p>
</li>
<li><p>Use <strong>const</strong> for fixed values</p>
</li>
</ul>
<hr />
<h1>What is Scope? (Beginner Explanation)</h1>
<p><strong>Scope</strong> means <strong>where a variable can be accessed in your code</strong>.</p>
<p>Example:</p>
<pre><code class="language-javascript">{
  let message = "Hello World";
  console.log(message);
}
</code></pre>
<p>Inside the block <code>{ }</code>, the variable is accessible.</p>
<p>But outside:</p>
<pre><code class="language-javascript">console.log(message);
</code></pre>
<p>This would cause an <strong>error</strong> because the variable exists only inside that block.</p>
<p>So scope defines <strong>where variables live and can be used</strong>.</p>
<hr />
<h1>Assignment Practice</h1>
<p>Try the following example in your browser console.</p>
<h3>Step 1: Declare Variables</h3>
<pre><code class="language-javascript">let name = "Viral";
let age = 22;
let isStudent = true;
</code></pre>
<h3>Step 2: Print Them</h3>
<pre><code class="language-javascript">console.log(name);
console.log(age);
console.log(isStudent);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Viral
22
true
</code></pre>
<hr />
<h1>Experiment With let and const</h1>
<h3>Changing a let value</h3>
<pre><code class="language-javascript">let age = 22;
age = 23;

console.log(age);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">23
</code></pre>
<hr />
<h3>Changing a const value</h3>
<pre><code class="language-javascript">const country = "India";

country = "USA";
</code></pre>
<p>This will produce an <strong>error</strong> because <code>const</code> values cannot change.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Control Flow in JavaScript: If, Else, and Switch Explained]]></title><description><![CDATA[When writing programs in JavaScript, we often need the program to make decisions.
For example:

If a user is logged in, show the dashboard

If a student’s marks are above 40, they pass

If today is Mo]]></description><link>https://blog.jainviral.com/control-flow-in-javascript-if-else-and-switch-explained</link><guid isPermaLink="true">https://blog.jainviral.com/control-flow-in-javascript-if-else-and-switch-explained</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:05:56 GMT</pubDate><content:encoded><![CDATA[<p>When writing programs in <strong>JavaScript</strong>, we often need the program to <strong>make decisions</strong>.</p>
<p>For example:</p>
<ul>
<li><p>If a user is <strong>logged in</strong>, show the dashboard</p>
</li>
<li><p>If a student’s <strong>marks are above 40</strong>, they pass</p>
</li>
<li><p>If today is <strong>Monday</strong>, display the schedule</p>
</li>
</ul>
<p>This decision-making process is called <strong>control flow</strong>.</p>
<p>Control flow determines <strong>which code runs and when it runs</strong>.</p>
<hr />
<h1>What Control Flow Means in Programming</h1>
<p>Control flow refers to <strong>the order in which statements are executed in a program</strong>.</p>
<p>Sometimes code runs <strong>line by line</strong>, but sometimes we need conditions.</p>
<p>Example:</p>
<pre><code class="language-javascript">let age = 20;

if (age &gt;= 18) {
  console.log("You can vote");
}
</code></pre>
<p>Here, the program checks a <strong>condition</strong> before running the code.</p>
<hr />
<h1>The if Statement</h1>
<p>The <code>if</code> statement executes code <strong>only if a condition is true</strong>.</p>
<h3>Syntax</h3>
<pre><code class="language-javascript">if (condition) {
  // code runs if condition is true
}
</code></pre>
<h3>Example</h3>
<pre><code class="language-javascript">let marks = 75;

if (marks &gt;= 40) {
  console.log("You passed the exam");
}
</code></pre>
<h3>Step-by-step execution</h3>
<ol>
<li><p>Condition checked → <code>marks &gt;= 40</code></p>
</li>
<li><p>If <strong>true</strong>, code runs</p>
</li>
<li><p>If <strong>false</strong>, nothing happens</p>
</li>
</ol>
<p>Output</p>
<pre><code class="language-plaintext">You passed the exam
</code></pre>
<hr />
<h1>The if-else Statement</h1>
<p>Sometimes we want <strong>two possible outcomes</strong>.</p>
<ul>
<li><p>One if the condition is true</p>
</li>
<li><p>Another if the condition is false</p>
</li>
</ul>
<h3>Syntax</h3>
<pre><code class="language-javascript">if (condition) {
  // runs if true
} else {
  // runs if false
}
</code></pre>
<h3>Example</h3>
<pre><code class="language-javascript">let age = 16;

if (age &gt;= 18) {
  console.log("You can vote");
} else {
  console.log("You cannot vote yet");
}
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">You cannot vote yet
</code></pre>
<hr />
<h1>The else if Ladder</h1>
<p>Sometimes we need to check <strong>multiple conditions</strong>.</p>
<p>Example: grading system.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let marks = 82;

if (marks &gt;= 90) {
  console.log("Grade A");
} 
else if (marks &gt;= 75) {
  console.log("Grade B");
} 
else if (marks &gt;= 50) {
  console.log("Grade C");
} 
else {
  console.log("Fail");
}
</code></pre>
<h3>How it works</h3>
<p>The program checks conditions <strong>from top to bottom</strong>.</p>
<ol>
<li><p><code>marks &gt;= 90</code> → false</p>
</li>
<li><p><code>marks &gt;= 75</code> → true</p>
</li>
</ol>
<p>So the output is:</p>
<pre><code class="language-plaintext">Grade B
</code></pre>
<p>Once a condition becomes <strong>true</strong>, the rest of the ladder <strong>stops executing</strong>.</p>
<hr />
<h1>The switch Statement</h1>
<p>The <code>switch</code> statement is used when we want to <strong>compare one value against multiple possible cases</strong>.</p>
<h3>Syntax</h3>
<pre><code class="language-javascript">switch(value) {
  case value1:
    // code
    break;

  case value2:
    // code
    break;

  default:
    // fallback
}
</code></pre>
<hr />
<h3>Example: Day of the Week</h3>
<pre><code class="language-javascript">let day = 3;

switch(day) {
  case 1:
    console.log("Monday");
    break;

  case 2:
    console.log("Tuesday");
    break;

  case 3:
    console.log("Wednesday");
    break;

  case 4:
    console.log("Thursday");
    break;

  case 5:
    console.log("Friday");
    break;

  default:
    console.log("Weekend");
}
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">Wednesday
</code></pre>
<hr />
<h1>Why break is Important</h1>
<p>Without <code>break</code>, the program continues executing <strong>all remaining cases</strong>.</p>
<p>Example without break:</p>
<pre><code class="language-javascript">let day = 1;

switch(day) {
  case 1:
    console.log("Monday");
  case 2:
    console.log("Tuesday");
}
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">Monday
Tuesday
</code></pre>
<p>This happens because <strong>execution falls through to the next case</strong>.</p>
<p>So we use <strong>break</strong> to stop the execution.</p>
<hr />
<h1>When to Use switch vs if-else</h1>
<table>
<thead>
<tr>
<th>Situation</th>
<th>Best Choice</th>
</tr>
</thead>
<tbody><tr>
<td>Checking ranges (marks, age)</td>
<td>if-else</td>
</tr>
<tr>
<td>Multiple fixed values</td>
<td>switch</td>
</tr>
<tr>
<td>Complex conditions</td>
<td>if-else</td>
</tr>
<tr>
<td>Clean menu-style logic</td>
<td>switch</td>
</tr>
</tbody></table>
<p>Example:</p>
<p>Checking marks → use <strong>if-else</strong></p>
<p>Checking weekday → use <strong>switch</strong></p>
<hr />
<h1>Assignment Practice</h1>
<h2>1️⃣ Check if a Number is Positive, Negative, or Zero</h2>
<pre><code class="language-javascript">let num = -5;

if (num &gt; 0) {
  console.log("Positive number");
}
else if (num &lt; 0) {
  console.log("Negative number");
}
else {
  console.log("Zero");
}
</code></pre>
<hr />
<h2>2️⃣ Print Day of Week Using switch</h2>
<pre><code class="language-javascript">let day = 5;

switch(day) {
  case 1:
    console.log("Monday");
    break;

  case 2:
    console.log("Tuesday");
    break;

  case 3:
    console.log("Wednesday");
    break;

  case 4:
    console.log("Thursday");
    break;

  case 5:
    console.log("Friday");
    break;

  default:
    console.log("Weekend");
}
</code></pre>
<hr />
<h1>Why These Structures Were Used</h1>
<ul>
<li><p><strong>if-else</strong> was used for <strong>number checking</strong> because we are dealing with <strong>conditions and ranges</strong>.</p>
</li>
<li><p><strong>switch</strong> was used for <strong>days of the week</strong> because we are matching <strong>specific values</strong>.</p>
</li>
</ul>
<hr />
]]></content:encoded></item><item><title><![CDATA[Arrow Functions in JavaScript: A Simpler Way to Write Functions
]]></title><description><![CDATA[Functions are one of the most important concepts in JavaScript.
Traditionally, we create functions using the function keyword. But modern JavaScript introduced arrow functions, which allow us to write]]></description><link>https://blog.jainviral.com/arrow-functions-in-javascript-a-simpler-way-to-write-functions</link><guid isPermaLink="true">https://blog.jainviral.com/arrow-functions-in-javascript-a-simpler-way-to-write-functions</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 10:02:40 GMT</pubDate><content:encoded><![CDATA[<p>Functions are one of the most important concepts in <strong>JavaScript</strong>.</p>
<p>Traditionally, we create functions using the <code>function</code> keyword. But modern JavaScript introduced <strong>arrow functions</strong>, which allow us to write functions in a <strong>shorter and cleaner way</strong>.</p>
<p>In this article, we’ll learn:</p>
<ul>
<li><p>What arrow functions are</p>
</li>
<li><p>Basic arrow function syntax</p>
</li>
<li><p>Arrow functions with one parameter</p>
</li>
<li><p>Arrow functions with multiple parameters</p>
</li>
<li><p>Implicit return vs explicit return</p>
</li>
<li><p>Difference between arrow functions and normal functions</p>
</li>
</ul>
<hr />
<h1>What Are Arrow Functions?</h1>
<p>Arrow functions are a <strong>shorter way to write functions</strong> in JavaScript.</p>
<p>They were introduced in <strong>ES6</strong> to make code more <strong>concise and readable</strong>.</p>
<p>Instead of using the <code>function</code> keyword, arrow functions use the <code>=&gt;</code> <strong>arrow syntax</strong>.</p>
<hr />
<h1>Basic Arrow Function Syntax</h1>
<h3>Normal Function</h3>
<pre><code class="language-javascript">function greet(name) {
  return "Hello " + name;
}
</code></pre>
<h3>Arrow Function</h3>
<pre><code class="language-javascript">const greet = (name) =&gt; {
  return "Hello " + name;
};
</code></pre>
<p>Both functions do the <strong>same thing</strong>, but the arrow function is <strong>shorter and more modern</strong>.</p>
<hr />
<h1>Arrow Functions with One Parameter</h1>
<p>If a function has <strong>only one parameter</strong>, the parentheses are optional.</p>
<h3>Normal Function</h3>
<pre><code class="language-javascript">function square(num) {
  return num * num;
}
</code></pre>
<h3>Arrow Function</h3>
<pre><code class="language-javascript">const square = num =&gt; {
  return num * num;
};
</code></pre>
<p>Example:</p>
<pre><code class="language-javascript">console.log(square(5));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">25
</code></pre>
<hr />
<h1>Arrow Functions with Multiple Parameters</h1>
<p>If there are <strong>multiple parameters</strong>, parentheses are required.</p>
<h3>Example</h3>
<pre><code class="language-javascript">const add = (a, b) =&gt; {
  return a + b;
};

console.log(add(5, 3));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">8
</code></pre>
<hr />
<h1>Implicit Return vs Explicit Return</h1>
<p>Arrow functions allow a <strong>shortcut return</strong> called <strong>implicit return</strong>.</p>
<hr />
<h2>Explicit Return</h2>
<p>You use <code>return</code> and curly braces <code>{}</code>.</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; {
  return a * b;
};
</code></pre>
<hr />
<h2>Implicit Return</h2>
<p>If the function has <strong>one expression</strong>, you can remove <code>{}</code> and <code>return</code>.</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; a * b;
</code></pre>
<p>Example:</p>
<pre><code class="language-javascript">console.log(multiply(4, 3));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">12
</code></pre>
<p>This makes the code <strong>shorter and cleaner</strong>.</p>
<hr />
<h1>Difference Between Arrow Function and Normal Function</h1>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Normal Function</th>
<th>Arrow Function</th>
</tr>
</thead>
<tbody><tr>
<td>Syntax</td>
<td>Uses <code>function</code> keyword</td>
<td>Uses <code>=&gt;</code></td>
</tr>
<tr>
<td>Length</td>
<td>Longer</td>
<td>Shorter</td>
</tr>
<tr>
<td>Return</td>
<td>Requires <code>return</code></td>
<td>Can use implicit return</td>
</tr>
<tr>
<td>Modern JS</td>
<td>Older style</td>
<td>Modern ES6 style</td>
</tr>
</tbody></table>
<p>Example comparison:</p>
<pre><code class="language-javascript">// Normal function
function greet(name) {
  return "Hello " + name;
}

// Arrow function
const greetArrow = name =&gt; "Hello " + name;
</code></pre>
<hr />
<h1>Assignment Practice</h1>
<h2>1️⃣ Normal Function to Calculate Square</h2>
<pre><code class="language-javascript">function square(num) {
  return num * num;
}

console.log(square(4));
</code></pre>
<hr />
<h2>2️⃣ Arrow Function Version</h2>
<pre><code class="language-javascript">const square = num =&gt; num * num;

console.log(square(4));
</code></pre>
<hr />
<h2>3️⃣ Arrow Function to Check Even or Odd</h2>
<pre><code class="language-javascript">const isEven = num =&gt; num % 2 === 0;

console.log(isEven(10));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">true
</code></pre>
<hr />
<h2>4️⃣ Arrow Function with map()</h2>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4];

let doubled = numbers.map(num =&gt; num * 2);

console.log(doubled);
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">[2, 4, 6, 8]
</code></pre>
<p>This is one of the <strong>most common real-world uses of arrow functions</strong>.</p>
<hr />
<h1>Why Developers Prefer Arrow Functions</h1>
<p>Arrow functions help developers:</p>
<ul>
<li><p>Write <strong>shorter code</strong></p>
</li>
<li><p>Improve <strong>readability</strong></p>
</li>
<li><p>Follow <strong>modern JavaScript practices</strong></p>
</li>
<li><p>Work better with array methods like <code>map()</code>, <code>filter()</code>, and <code>reduce()</code></p>
</li>
</ul>
<hr />
<hr />
]]></content:encoded></item><item><title><![CDATA[Array Methods You Must Know]]></title><description><![CDATA[Array Methods Every JavaScript Developer Must Know
Arrays are one of the most commonly used data structures in JavaScript.To work efficiently with arrays, developers rely on built-in array methods tha]]></description><link>https://blog.jainviral.com/array-methods-you-must-know</link><guid isPermaLink="true">https://blog.jainviral.com/array-methods-you-must-know</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chai-code ]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Sun, 15 Mar 2026 09:59:10 GMT</pubDate><content:encoded><![CDATA[<hr />
<h1>Array Methods Every JavaScript Developer Must Know</h1>
<p>Arrays are one of the most commonly used data structures in <strong>JavaScript</strong>.<br />To work efficiently with arrays, developers rely on built-in <strong>array methods</strong> that help manipulate and transform data easily.</p>
<p>In this article, we will learn some of the <strong>most important array methods</strong> every developer should know.</p>
<hr />
<h1>1. push() and pop()</h1>
<p>These methods are used to <strong>add or remove elements from the end of an array</strong>.</p>
<h3>push()</h3>
<p>Adds an element to the <strong>end</strong> of an array.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana"];

fruits.push("orange");

console.log(fruits);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">["apple", "banana"]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">["apple", "banana", "orange"]
</code></pre>
<hr />
<h3>pop()</h3>
<p>Removes the <strong>last element</strong> from the array.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "orange"];

fruits.pop();

console.log(fruits);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">["apple", "banana", "orange"]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">["apple", "banana"]
</code></pre>
<hr />
<h1>2. shift() and unshift()</h1>
<p>These methods work with the <strong>start of the array</strong>.</p>
<h3>shift()</h3>
<p>Removes the <strong>first element</strong>.</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3];

numbers.shift();

console.log(numbers);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">[1, 2, 3]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">[2, 3]
</code></pre>
<hr />
<h3>unshift()</h3>
<p>Adds an element to the <strong>beginning</strong> of the array.</p>
<pre><code class="language-javascript">let numbers = [2, 3];

numbers.unshift(1);

console.log(numbers);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">[2, 3]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">[1, 2, 3]
</code></pre>
<hr />
<h1>3. forEach()</h1>
<p>The <code>forEach()</code> method runs a function <strong>once for every element in an array</strong>.</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3];

numbers.forEach(function(num) {
  console.log(num);
});
</code></pre>
<h3>Output</h3>
<pre><code class="language-plaintext">1
2
3
</code></pre>
<p>⚠️ Important:</p>
<ul>
<li><p><code>forEach()</code> <strong>does not return a new array</strong></p>
</li>
<li><p>It is mainly used for <strong>side effects</strong> like logging or updating values.</p>
</li>
</ul>
<hr />
<h1>4. map()</h1>
<p>The <code>map()</code> method creates a <strong>new array by transforming each element</strong>.</p>
<h3>Example: Double each number</h3>
<pre><code class="language-javascript">let numbers = [2, 4, 6];

let doubled = numbers.map(function(num) {
  return num * 2;
});

console.log(doubled);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">[2, 4, 6]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">[4, 8, 12]
</code></pre>
<hr />
<h1>Traditional Loop vs map()</h1>
<h3>Using for loop</h3>
<pre><code class="language-javascript">let numbers = [2,4,6];
let result = [];

for(let i = 0; i &lt; numbers.length; i++){
  result.push(numbers[i] * 2);
}
</code></pre>
<h3>Using map()</h3>
<pre><code class="language-javascript">let result = numbers.map(num =&gt; num * 2);
</code></pre>
<p>✅ <code>map()</code> is <strong>shorter, cleaner, and easier to read</strong>.</p>
<hr />
<h1>5. filter()</h1>
<p>The <code>filter()</code> method creates a <strong>new array containing only elements that pass a condition</strong>.</p>
<h3>Example: Get numbers greater than 10</h3>
<pre><code class="language-javascript">let numbers = [5, 12, 8, 20];

let filtered = numbers.filter(function(num) {
  return num &gt; 10;
});

console.log(filtered);
</code></pre>
<h3>Before</h3>
<pre><code class="language-plaintext">[5, 12, 8, 20]
</code></pre>
<h3>After</h3>
<pre><code class="language-plaintext">[12, 20]
</code></pre>
<hr />
<h1>6. reduce() (Beginner Friendly)</h1>
<p>The <code>reduce()</code> method <strong>combines all values of an array into a single result</strong>.</p>
<p>It works using an <strong>accumulator</strong>.</p>
<h3>Example: Calculate total sum</h3>
<pre><code class="language-javascript">let numbers = [10, 20, 30];

let sum = numbers.reduce(function(acc, num) {
  return acc + num;
}, 0);

console.log(sum);
</code></pre>
<h3>How it works</h3>
<table>
<thead>
<tr>
<th>Step</th>
<th>Accumulator</th>
<th>Current Value</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>0</td>
<td>10</td>
<td>10</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>20</td>
<td>30</td>
</tr>
<tr>
<td>3</td>
<td>30</td>
<td>30</td>
<td>60</td>
</tr>
</tbody></table>
<p>Final Result:</p>
<pre><code class="language-plaintext">60
</code></pre>
<hr />
<h1>Assignment Practice</h1>
<p>Try this yourself in the console.</p>
<pre><code class="language-javascript">let numbers = [5, 8, 12, 20];

// double numbers
let doubled = numbers.map(num =&gt; num * 2);

// numbers greater than 10
let filtered = numbers.filter(num =&gt; num &gt; 10);

// total sum
let sum = numbers.reduce((acc, num) =&gt; acc + num, 0);

console.log(doubled);
console.log(filtered);
console.log(sum);
</code></pre>
<hr />
]]></content:encoded></item><item><title><![CDATA[Emmet for HTML: A Beginner’s Guide to Writing Faster Markup]]></title><description><![CDATA[What is Emmet?
Emmet is a shortcut system for writing HTML faster.
Instead of typing full HTML tags again and again, you type a short abbreviation, and your code editor expands it into proper HTML.
Think of Emmet as:

“Short form → Full HTML”


Why E...]]></description><link>https://blog.jainviral.com/emmet-learn</link><guid isPermaLink="true">https://blog.jainviral.com/emmet-learn</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 07:01:56 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-is-emmet">What is Emmet?</h2>
<p><strong>Emmet is a shortcut system for writing HTML faster.</strong></p>
<p>Instead of typing full HTML tags again and again, you type a <strong>short abbreviation</strong>, and your code editor expands it into proper HTML.</p>
<p>Think of Emmet as:</p>
<blockquote>
<p><em>“Short form → Full HTML”</em></p>
</blockquote>
<hr />
<h2 id="heading-why-emmet-is-useful-for-html-beginners">Why Emmet is Useful for HTML Beginners</h2>
<ul>
<li><p>You write <strong>less code</strong></p>
</li>
<li><p>You make <strong>fewer typing mistakes</strong></p>
</li>
<li><p>You focus on <strong>structure</strong>, not syntax</p>
</li>
<li><p>HTML feels <strong>less boring and repetitive</strong></p>
</li>
<li><p>It is already built into <strong>VS Code</strong></p>
</li>
</ul>
<p>Important to know:</p>
<blockquote>
<p>Emmet is <strong>optional</strong>, but extremely helpful for daily HTML work.</p>
</blockquote>
<hr />
<h2 id="heading-how-emmet-works-inside-code-editors">How Emmet Works Inside Code Editors</h2>
<ol>
<li><p>You type an Emmet abbreviation</p>
</li>
<li><p>Press <strong>Tab</strong> or <strong>Enter</strong></p>
</li>
<li><p>The editor converts it into full HTML</p>
</li>
</ol>
<p>Emmet works <strong>inside the editor</strong>, not in the browser.</p>
<hr />
<h2 id="heading-basic-emmet-syntax-only-what-beginners-need">Basic Emmet Syntax (Only What Beginners Need)</h2>
<h3 id="heading-1-creating-an-html-element">1. Creating an HTML Element</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">div
</code></pre>
<p><strong>HTML Output</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<hr />
<h3 id="heading-2-adding-a-class">2. Adding a Class (<code>.</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">div.container
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<hr />
<h3 id="heading-3-adding-an-id">3. Adding an ID (<code>#</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">section#hero
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"hero"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<hr />
<h3 id="heading-4-adding-attributes">4. Adding Attributes (<code>[]</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">input[type=text][placeholder=Name]
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Name"</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-creating-nested-elements-gt">Creating Nested Elements (<code>&gt;</code>)</h2>
<p>Use <code>&gt;</code> for <strong>parent → child</strong></p>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">div&gt;p
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<hr />
<h3 id="heading-nested-example">Nested Example</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">ul&gt;li
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-repeating-elements">Repeating Elements (<code>*</code>)</h2>
<p>Use <code>*</code> to repeat elements.</p>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">li*3
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
</code></pre>
<hr />
<h3 id="heading-nested-repeated">Nested + Repeated</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">ul&gt;li*3
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-sibling-elements">Sibling Elements (<code>+</code>)</h2>
<p>Use <code>+</code> for elements at the same level.</p>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">h1+p
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><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><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-adding-text-content">Adding Text Content (<code>{}</code>)</h2>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">p{Hello World}
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><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>
<hr />
<h2 id="heading-real-beginner-example">Real Beginner Example</h2>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">div.card&gt;h2{Product}+p{Nice product}+button{Buy}
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Product<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Nice product<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Buy<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-generating-full-html-boilerplate">Generating Full HTML Boilerplate</h2>
<p><strong>Emmet</strong></p>
<pre><code class="lang-plaintext">!
</code></pre>
<p>or</p>
<pre><code class="lang-plaintext">html:5
</code></pre>
<p><strong>HTML Output</strong></p>
<pre><code class="lang-html"><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> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</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">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<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">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<hr />
<h2 id="heading-beginner-tips-important">Beginner Tips (Important)</h2>
<ul>
<li><p>Learn <strong>one shortcut at a time</strong></p>
</li>
<li><p>Practice directly in <strong>VS Code</strong></p>
</li>
<li><p>Always try the abbreviation yourself</p>
</li>
<li><p>Do not try to memorize everything</p>
</li>
<li><p>Focus on <strong>daily-use patterns only</strong></p>
</li>
</ul>
<hr />
<h2 id="heading-final-takeaway">Final Takeaway</h2>
<p>Emmet is not magic.<br />It’s just a <strong>faster way to write HTML</strong>.</p>
<p>If you know basic HTML and practice Emmet a little every day, your speed will naturally improve.</p>
]]></content:encoded></item><item><title><![CDATA[CSS Selectors 101: Targeting Elements with Precision]]></title><description><![CDATA[Why CSS Selectors Are Needed
HTML creates structure (what is on the page).CSS controls style (how it looks).
But CSS needs to know which HTML element to style.
That’s where CSS selectors come in.

CSS selectors are rules that tell CSS which elements ...]]></description><link>https://blog.jainviral.com/css-selector</link><guid isPermaLink="true">https://blog.jainviral.com/css-selector</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 07:01:20 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-why-css-selectors-are-needed">Why CSS Selectors Are Needed</h2>
<p>HTML creates <strong>structure</strong> (what is on the page).<br />CSS controls <strong>style</strong> (how it looks).</p>
<p>But CSS needs to know <strong>which HTML element to style</strong>.</p>
<p>That’s where <strong>CSS selectors</strong> come in.</p>
<blockquote>
<p><strong>CSS selectors are rules that tell CSS <em>which elements to select and style</em>.</strong></p>
</blockquote>
<p>Without selectors, CSS wouldn’t know <em>where</em> to apply styles.</p>
<hr />
<h2 id="heading-real-world-analogy-very-important">Real-World Analogy (Very Important)</h2>
<p>Imagine a classroom:</p>
<ul>
<li><p>Calling <strong>“Everyone”</strong> → element selector</p>
</li>
<li><p>Calling <strong>“All students wearing blue shirts”</strong> → class selector</p>
</li>
<li><p>Calling <strong>“Only Rahul”</strong> → ID selector</p>
</li>
</ul>
<p>CSS selectors work the same way:<br />they <strong>target elements</strong> based on rules.</p>
<hr />
<h2 id="heading-css-selector-targeting-flow">CSS Selector Targeting Flow</h2>
<p><img src="https://quizzets.wgu.edu/assets/images/tutorial/css-selectors.png" alt="Image" /></p>
<p><img src="https://d11a6trkgmumsb.cloudfront.net/original/3X/6/e/6eb372d7b45aa17f165c01b9da631b2151e74d07.png" alt="Image" /></p>
<p><img src="https://d2o2utebsixu4k.cloudfront.net/image2-c9d8999488774b27be471d7d3a63ee83.png" alt="Image" /></p>
<hr />
<h2 id="heading-1-element-selector">1. Element Selector</h2>
<p>The <strong>element selector</strong> selects all elements of a specific type.</p>
<h3 id="heading-example">Example</h3>
<p><strong>HTML</strong></p>
<pre><code class="lang-html">p {
  color: blue;
}
</code></pre>
<p><strong>What it selects</strong></p>
<ul>
<li>All <code>&lt;p&gt;</code> elements on the page</li>
</ul>
<p><strong>Use case</strong></p>
<ul>
<li>When you want to style <strong>every element of one type</strong></li>
</ul>
<hr />
<h2 id="heading-2-class-selector">2. Class Selector</h2>
<p>The <strong>class selector</strong> selects elements with a specific class.</p>
<p>It starts with a <strong>dot (</strong><code>.</code>).</p>
<h3 id="heading-example-1">Example</h3>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"highlight"</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">p</span>&gt;</span>World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><strong>CSS</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.highlight</span> {
  <span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p><strong>What it selects</strong></p>
<ul>
<li>Only elements with <code>class="highlight"</code></li>
</ul>
<p><strong>Key points</strong></p>
<ul>
<li><p>Can be used on <strong>multiple elements</strong></p>
</li>
<li><p>Most commonly used selector in real projects</p>
</li>
</ul>
<hr />
<h2 id="heading-3-id-selector">3. ID Selector</h2>
<p>The <strong>ID selector</strong> selects <strong>one unique element</strong>.</p>
<p>It starts with a <strong>hash (</strong><code>#</code>).</p>
<h3 id="heading-example-2">Example</h3>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"title"</span>&gt;</span>Welcome<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p><strong>CSS</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-id">#title</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">32px</span>;
}
</code></pre>
<p><strong>What it selects</strong></p>
<ul>
<li>Only the element with <code>id="title"</code></li>
</ul>
<p><strong>Important rule</strong></p>
<ul>
<li>An ID should be <strong>used only once per page</strong></li>
</ul>
<hr />
<h2 id="heading-class-vs-id-conceptual-difference">Class vs ID (Conceptual Difference)</h2>
<hr />
<h2 id="heading-4-group-selector">4. Group Selector</h2>
<p>The <strong>group selector</strong> applies the same style to <strong>multiple selectors</strong>.</p>
<p>Use <strong>comma (</strong><code>,</code>) to group them.</p>
<h3 id="heading-example-3">Example</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span>, <span class="hljs-selector-tag">h2</span>, <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">color</span>: green;
}
</code></pre>
<p><strong>What it selects</strong></p>
<ul>
<li>All <code>&lt;h1&gt;</code>, <code>&lt;h2&gt;</code>, and <code>&lt;p&gt;</code> elements</li>
</ul>
<p><strong>Why useful</strong></p>
<ul>
<li>Avoids repeating the same CSS again and again</li>
</ul>
<hr />
<h2 id="heading-5-descendant-selector">5. Descendant Selector</h2>
<p>The <strong>descendant selector</strong> selects elements <strong>inside another element</strong>.</p>
<p>Use a <strong>space</strong> between selectors.</p>
<h3 id="heading-example-4">Example</h3>
<p><strong>HTML</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</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">div</span>&gt;</span>
</code></pre>
<p><strong>CSS</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">color</span>: purple;
}
</code></pre>
<p><strong>What it selects</strong></p>
<ul>
<li><code>&lt;p&gt;</code> elements <strong>inside</strong> <code>&lt;div&gt;</code></li>
</ul>
<p><strong>Does not select</strong></p>
<ul>
<li><code>&lt;p&gt;</code> elements outside the <code>&lt;div&gt;</code></li>
</ul>
<hr />
<h2 id="heading-before-vs-after-styling-conceptual">Before vs After Styling (Conceptual)</h2>
<p><strong>Before CSS</strong></p>
<ul>
<li><p>All text looks the same</p>
</li>
<li><p>No visual hierarchy</p>
</li>
</ul>
<p><strong>After CSS with selectors</strong></p>
<ul>
<li><p>Headings stand out</p>
</li>
<li><p>Important content highlighted</p>
</li>
<li><p>Layout becomes readable</p>
</li>
</ul>
<p>Selectors make this possible.</p>
<hr />
<h2 id="heading-basic-selector-priority-very-high-level">Basic Selector Priority (Very High Level)</h2>
<p>When multiple selectors target the same element, <strong>priority matters</strong>.</p>
<p>From <strong>low → high priority</strong>:</p>
<ol>
<li><p>Element selector (<code>p</code>)</p>
</li>
<li><p>Class selector (<code>.box</code>)</p>
</li>
<li><p>ID selector (<code>#main</code>)</p>
</li>
</ol>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> { <span class="hljs-attribute">color</span>: blue; }
<span class="hljs-selector-class">.text</span> { <span class="hljs-attribute">color</span>: red; }
<span class="hljs-selector-id">#special</span> { <span class="hljs-attribute">color</span>: green; }
</code></pre>
<p>If an element has all three, <strong>green wins</strong> (ID has highest priority).</p>
<p>No need to memorize details now—just remember:</p>
<blockquote>
<p><strong>ID &gt; Class &gt; Element</strong></p>
</blockquote>
<hr />
<h2 id="heading-key-takeaways-for-beginners">Key Takeaways for Beginners</h2>
<ul>
<li><p>CSS selectors are the <strong>foundation of CSS</strong></p>
</li>
<li><p>They decide <strong>what gets styled</strong></p>
</li>
<li><p>Start learning in this order:</p>
<ol>
<li><p>Element</p>
</li>
<li><p>Class</p>
</li>
<li><p>ID</p>
</li>
</ol>
</li>
<li><p>Avoid advanced selectors early</p>
</li>
<li><p>Master selectors before layouts and animations</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding HTML Tags and Elements]]></title><description><![CDATA[What HTML Is and Why We Use It
HTML stands for HyperText Markup Language.
HTML is used to create the structure of a webpage.
Think of a webpage like a building:

HTML = skeleton / structure

CSS = design

JavaScript = behavior


Without HTML, a webpa...]]></description><link>https://blog.jainviral.com/html-tag</link><guid isPermaLink="true">https://blog.jainviral.com/html-tag</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 07:00:55 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-html-is-and-why-we-use-it">What HTML Is and Why We Use It</h2>
<p>HTML stands for <strong>HyperText Markup Language</strong>.</p>
<p>HTML is used to <strong>create the structure of a webpage</strong>.</p>
<p>Think of a webpage like a building:</p>
<ul>
<li><p>HTML = <strong>skeleton / structure</strong></p>
</li>
<li><p>CSS = design</p>
</li>
<li><p>JavaScript = behavior</p>
</li>
</ul>
<p>Without HTML, a webpage has <strong>nothing to show</strong>.</p>
<hr />
<h2 id="heading-html-as-the-skeleton-of-a-webpage">HTML as the Skeleton of a Webpage</h2>
<p>HTML decides:</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 button</p>
</li>
</ul>
<p>Browsers read HTML and display content based on it.</p>
<hr />
<h2 id="heading-what-is-an-html-tag">What Is an HTML Tag</h2>
<p>An <strong>HTML tag</strong> is a keyword written inside angle brackets <code>&lt; &gt;</code>.</p>
<p>Example:</p>
<pre><code class="lang-plaintext">&lt;p&gt;
</code></pre>
<p>Tags tell the browser <strong>what kind of content</strong> it is dealing with.</p>
<hr />
<h2 id="heading-opening-tag-closing-tag-and-content">Opening Tag, Closing Tag, and Content</h2>
<p>Most HTML tags come in pairs.</p>
<p>Example:</p>
<pre><code class="lang-plaintext">&lt;p&gt;Hello World&lt;/p&gt;
</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>
<li><p><code>Hello World</code> → content</p>
</li>
</ul>
<p>Together, they form something meaningful.</p>
<hr />
<h2 id="heading-what-an-html-element-means">What an HTML Element Means</h2>
<p>An <strong>HTML element</strong> includes:</p>
<ul>
<li><p>Opening tag</p>
</li>
<li><p>Content</p>
</li>
<li><p>Closing tag</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-plaintext">&lt;h1&gt;Welcome&lt;/h1&gt;
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>&lt;h1&gt;</code> = tag</p>
</li>
<li><p><code>Welcome</code> = content</p>
</li>
<li><p>Entire line = <strong>HTML element</strong></p>
</li>
</ul>
<h3 id="heading-important-difference">Important Difference</h3>
<ul>
<li><p><strong>Tag</strong> → just the markup (<code>&lt;p&gt;</code>)</p>
</li>
<li><p><strong>Element</strong> → tag + content + closing tag</p>
</li>
</ul>
<hr />
<h2 id="heading-html-tag-vs-element-visual-idea">HTML Tag vs Element (Visual Idea)</h2>
<p><img src="https://images.openai.com/thumbnails/url/_0YmhXicu5mZUVJSUGylr5-al1xUWVCSmqJbkpRnoJdeXJJYkpmsl5yfq5-Zm5ieWmxfaAuUsXL0S7F0Tw7MNjbINUx1MXNNzqoMy3Kr9CpNqgyJ9_T2DE5PibeMKiw3colID080cYkK93YtMg1VKwYAWUAl8A" alt="https://i.sstatic.net/UCxMx.png" /></p>
<p><img src="https://pbs.twimg.com/media/F3yW2CMbcAA_q6Z.png" alt="https://pbs.twimg.com/media/F3yW2CMbcAA_q6Z.png" /></p>
<p><img src="https://assets.digitalocean.com/django_gunicorn_nginx_2004/articles/new_learners/html-element-diagram.png" alt="https://assets.digitalocean.com/django_gunicorn_nginx_2004/articles/new_learners/html-element-diagram.png" /></p>
<hr />
<h2 id="heading-self-closing-void-elements">Self-Closing (Void) Elements</h2>
<p>Some HTML elements <strong>do not have content</strong>, so they don’t need a closing tag.</p>
<p>Examples:</p>
<pre><code class="lang-plaintext">&lt;img src="image.jpg"&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;input&gt;
</code></pre>
<p>These are called:</p>
<ul>
<li><p>Self-closing elements</p>
</li>
<li><p>Void elements</p>
</li>
</ul>
<p>They exist to perform a single job, like showing an image or breaking a line.</p>
<hr />
<h2 id="heading-block-level-vs-inline-elements">Block-Level vs Inline Elements</h2>
<h3 id="heading-block-level-elements">Block-Level Elements</h3>
<ul>
<li><p>Take <strong>full width</strong></p>
</li>
<li><p>Always start on a <strong>new line</strong></p>
</li>
</ul>
<p>Examples:</p>
<pre><code class="lang-plaintext">&lt;h1&gt;
&lt;p&gt;
&lt;div&gt;
</code></pre>
<h3 id="heading-inline-elements">Inline Elements</h3>
<ul>
<li><p>Take <strong>only required width</strong></p>
</li>
<li><p>Stay in the <strong>same line</strong></p>
</li>
</ul>
<p>Examples:</p>
<pre><code class="lang-plaintext">&lt;span&gt;
&lt;a&gt;
&lt;strong&gt;
</code></pre>
<hr />
<h2 id="heading-block-vs-inline-layout-visual-idea">Block vs Inline Layout (Visual Idea)</h2>
<p><img src="https://miro.medium.com/1%2A8RH99a28L6LCFA04FJ25VQ.jpeg" alt="https://miro.medium.com/1%2A8RH99a28L6LCFA04FJ25VQ.jpeg" /></p>
<p><img src="https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content/inline_layout.png" alt="https://developer.mozilla.org/en-US/docs/Glossary/Inline-level_content/inline_layout.png" /></p>
<p><img src="https://miro.medium.com/1%2A6APfWf2BWiyFawjwH4C9-g.jpeg" alt="https://miro.medium.com/1%2A6APfWf2BWiyFawjwH4C9-g.jpeg" /></p>
<hr />
<h2 id="heading-simple-examples-beginner-level">Simple Examples (Beginner Level)</h2>
<h3 id="heading-paragraph">Paragraph</h3>
<pre><code class="lang-plaintext">&lt;p&gt;This is a paragraph&lt;/p&gt;
</code></pre>
<h3 id="heading-heading">Heading</h3>
<pre><code class="lang-plaintext">&lt;h1&gt;Main Heading&lt;/h1&gt;
</code></pre>
<h3 id="heading-div-container">Div (Container)</h3>
<pre><code class="lang-plaintext">&lt;div&gt;
  Content here
&lt;/div&gt;
</code></pre>
<h3 id="heading-span-inline-text">Span (Inline Text)</h3>
<pre><code class="lang-plaintext">&lt;p&gt;This is &lt;span&gt;important&lt;/span&gt; text&lt;/p&gt;
</code></pre>
<hr />
<h2 id="heading-commonly-used-html-tags-start-here">Commonly Used HTML Tags (Start Here)</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;div&gt;</code></td><td>Container</td></tr>
<tr>
<td><code>&lt;span&gt;</code></td><td>Inline text</td></tr>
<tr>
<td><code>&lt;img&gt;</code></td><td>Image</td></tr>
<tr>
<td><code>&lt;a&gt;</code></td><td>Link</td></tr>
<tr>
<td><code>&lt;br&gt;</code></td><td>Line break</td></tr>
</tbody>
</table>
</div><p>These tags cover <strong>most beginner needs</strong>.</p>
<hr />
<h2 id="heading-encourage-inspect-html-in-the-browser">Encourage: Inspect HTML in the Browser</h2>
<p>You don’t have to guess how HTML works.</p>
<p>Steps:</p>
<ol>
<li><p>Open any website</p>
</li>
<li><p>Right-click → <strong>Inspect</strong></p>
</li>
<li><p>Look at the <strong>HTML structure</strong></p>
</li>
</ol>
<p>This is one of the <strong>best ways to learn HTML faster</strong>.</p>
<hr />
<h2 id="heading-key-takeaways-for-beginners">Key Takeaways for Beginners</h2>
<ul>
<li><p>HTML is the <strong>foundation</strong> of every webpage</p>
</li>
<li><p>Tags describe content</p>
</li>
<li><p>Elements are complete structures</p>
</li>
<li><p>Block and inline elements behave differently</p>
</li>
<li><p>Master basic tags before moving forward</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[How a Browser Works: A Beginner-Friendly Guide to Browser Internals]]></title><description><![CDATA[First Question
What actually happens after I type a URL and press Enter?
A lot more than “the website opens”.
A browser is not one thing.It’s a collection of parts working together to turn code into pixels on your screen.

What a Browser Actually Is
...]]></description><link>https://blog.jainviral.com/browser</link><guid isPermaLink="true">https://blog.jainviral.com/browser</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 07:00:28 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-first-question">First Question</h2>
<p><strong>What actually happens after I type a URL and press Enter?</strong></p>
<p>A lot more than “the website opens”.</p>
<p>A browser is not one thing.<br />It’s a <strong>collection of parts working together</strong> to turn code into pixels on your screen.</p>
<hr />
<h2 id="heading-what-a-browser-actually-is">What a Browser Actually Is</h2>
<p>A browser is a <strong>software program that:</strong></p>
<ul>
<li><p>Fetches files from the internet (HTML, CSS, JS, images)</p>
</li>
<li><p>Understands those files</p>
</li>
<li><p>Converts them into a <strong>visual page</strong></p>
</li>
<li><p>Lets users interact with it</p>
</li>
</ul>
<p>In short:</p>
<blockquote>
<p><strong>Browser = code reader + painter + traffic manager</strong></p>
</blockquote>
<hr />
<h2 id="heading-high-level-parts-of-a-browser">High-Level Parts of a Browser</h2>
<p>Think of a browser like a small factory.</p>
<p><img src="https://beehiiv-images-production.s3.amazonaws.com/uploads/asset/file/e525ea1b-f275-45e2-bd83-cb6725583b22/bb4ed1cf-6143-48b5-b9af-60f65d921e68_500x339.png?t=1651893384" alt="Image" /></p>
<p><img src="https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1jalr50iq0qbcljula7.png" alt="Image" /></p>
<p><img src="https://files.codingninjas.in/article_images/what-is-a-web-browser-2-1635103986.webp" alt="Image" /></p>
<h3 id="heading-main-parts-high-level">Main Parts (High Level)</h3>
<ol>
<li><p><strong>User Interface (UI)</strong> – what you see and click</p>
</li>
<li><p><strong>Browser Engine</strong> – connects UI with the engine</p>
</li>
<li><p><strong>Rendering Engine</strong> – turns code into visuals</p>
</li>
<li><p><strong>Networking</strong> – fetches files from the internet</p>
</li>
<li><p><strong>JavaScript Engine</strong> – runs JavaScript code</p>
</li>
</ol>
<p>You don’t need to remember names yet. Focus on the <strong>flow</strong>.</p>
<hr />
<h2 id="heading-user-interface-ui">User Interface (UI)</h2>
<p>This is the visible part of the browser.</p>
<p>Includes:</p>
<ul>
<li><p>Address bar</p>
</li>
<li><p>Tabs</p>
</li>
<li><p>Back / Forward buttons</p>
</li>
<li><p>Refresh button</p>
</li>
</ul>
<p>UI’s job is simple:</p>
<blockquote>
<p>Take user input and show output.</p>
</blockquote>
<hr />
<h2 id="heading-browser-engine-vs-rendering-engine-simple">Browser Engine vs Rendering Engine (Simple)</h2>
<p>This sounds complex, but it’s not.</p>
<ul>
<li><p><strong>Browser Engine</strong><br />  Acts as a <strong>manager</strong><br />  It tells the rendering engine <em>what to load and when</em></p>
</li>
<li><p><strong>Rendering Engine</strong><br />  Acts as a <strong>builder + painter</strong><br />  It reads HTML/CSS and draws the page</p>
</li>
</ul>
<p>Popular rendering engines (name level only):</p>
<ul>
<li><p>Chromium</p>
</li>
<li><p>Gecko</p>
</li>
</ul>
<p>No deep dive needed.</p>
<hr />
<h2 id="heading-networking-how-files-are-fetched">Networking: How Files Are Fetched</h2>
<p>When you press Enter:</p>
<ol>
<li><p>Browser sends a request to the server</p>
</li>
<li><p>Server responds with files:</p>
<ul>
<li><p>HTML</p>
</li>
<li><p>CSS</p>
</li>
<li><p>JavaScript</p>
</li>
<li><p>Images</p>
</li>
</ul>
</li>
</ol>
<p>This is handled by the <strong>networking layer</strong>.</p>
<p>Think of it as:</p>
<blockquote>
<p>Browser ordering food, server delivering items.</p>
</blockquote>
<hr />
<h2 id="heading-html-parsing-and-dom-creation">HTML Parsing and DOM Creation</h2>
<p>The browser <strong>reads HTML from top to bottom</strong>.</p>
<p>This process is called <strong>parsing</strong>.</p>
<p>While parsing, the browser builds something called the <strong>DOM</strong>.</p>
<h3 id="heading-what-is-the-dom">What Is the DOM?</h3>
<p>DOM = <strong>Document Object Model</strong></p>
<p>It is a <strong>tree structure</strong> representing HTML.</p>
<p><img src="https://www.w3schools.com/js/pic_htmltree.gif" alt="Image" /></p>
<p><img src="https://www.w3schools.com/whatis/img_htmltree.gif" alt="Image" /></p>
<p><img src="https://i.sstatic.net/kBF3j.png" alt="Image" /></p>
<p>Example:</p>
<pre><code class="lang-html"><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<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>World<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>
</code></pre>
<p>Becomes a <strong>tree</strong>, not text.</p>
<blockquote>
<p>DOM helps the browser understand <strong>relationships</strong> between elements.</p>
</blockquote>
<hr />
<h2 id="heading-css-parsing-and-cssom-creation">CSS Parsing and CSSOM Creation</h2>
<p>CSS is parsed separately.</p>
<p>Browser builds the <strong>CSSOM</strong> (CSS Object Model).</p>
<p><img src="https://miro.medium.com/0%2AFp3mesmVsWB7z0OD" alt="Image" /></p>
<p><img src="https://res.cloudinary.com/dcxnnco0b/image/upload/w_728%2Cf_auto%2Cq_auto%2Cdpr_auto/v1729886519/cssdom_k1fr2i.webp" alt="Image" /></p>
<p><img src="https://web.dev/static/articles/critical-rendering-path/render-tree-construction/image/dom-cssom-are-combined-8de5805b2061e.png" alt="Image" /></p>
<p>CSSOM answers:</p>
<ul>
<li><p>Which styles apply</p>
</li>
<li><p>To which elements</p>
</li>
<li><p>With what priority</p>
</li>
</ul>
<hr />
<h2 id="heading-dom-cssom-render-tree">DOM + CSSOM → Render Tree</h2>
<p>DOM and CSSOM are combined to create the <strong>Render Tree</strong>.</p>
<p><img src="https://web.dev/static/articles/critical-rendering-path/render-tree-construction/image/dom-cssom-are-combined-8de5805b2061e.png" alt="Image" /></p>
<p><img src="https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56cdizmlhcvpwgjx55k7.png" alt="Image" /></p>
<p><img src="https://pbs.twimg.com/media/FUqUKK1UYAUjdVq.jpg" alt="Image" /></p>
<p>Important:</p>
<ul>
<li><p>Only <strong>visible elements</strong> are included</p>
</li>
<li><p><code>display: none</code> elements are ignored</p>
</li>
</ul>
<p>Render Tree = <em>what actually needs to be drawn</em></p>
<hr />
<h2 id="heading-layout-reflow">Layout (Reflow)</h2>
<p>Now the browser calculates:</p>
<ul>
<li><p>Width</p>
</li>
<li><p>Height</p>
</li>
<li><p>Position</p>
</li>
</ul>
<p>This step is called <strong>layout</strong> or <strong>reflow</strong>.</p>
<blockquote>
<p>“Where should everything go?”</p>
</blockquote>
<hr />
<h2 id="heading-painting-and-display">Painting and Display</h2>
<p>After layout:</p>
<ol>
<li><p>Browser paints colors, text, borders, images</p>
</li>
<li><p>Everything is drawn onto the screen</p>
</li>
</ol>
<p><img src="https://webperf.tips/static/d77eb220c5dd10181dc361c4ff0051da/906b5/BrowserRenderingPipeline17.png" alt="Image" /></p>
<p><img src="https://substackcdn.com/image/fetch/%24s_%2101rE%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8d3d92c-f0bf-44b8-a24e-4960b8dd63b5_2840x1184.png" alt="Image" /></p>
<p><img src="https://webperf.tips/static/4e73c9992ce3b9177bcc80a2113b3138/906b5/BrowserRenderingPipeline01.png" alt="Image" /></p>
<p>Final result:</p>
<blockquote>
<p><strong>Pixels on your screen</strong></p>
</blockquote>
<hr />
<h2 id="heading-very-basic-idea-of-parsing-simple-example">Very Basic Idea of Parsing (Simple Example)</h2>
<p>Parsing means <strong>breaking something into meaningful pieces</strong>.</p>
<p>Example:</p>
<pre><code class="lang-plaintext">2 + 3 × 4
</code></pre>
<p>Parser turns it into a tree:</p>
<ul>
<li><p>Multiply first</p>
</li>
<li><p>Then add</p>
</li>
</ul>
<p>Same idea with HTML:</p>
<ul>
<li><p>Tags</p>
</li>
<li><p>Nesting</p>
</li>
<li><p>Meaning</p>
</li>
</ul>
<p><img src="https://runestone.academy/ns/books/published/pythonds/_images/meParse.png" alt="Image" /></p>
<p><img src="https://runestone.academy/ns/books/published/pythonds/_images/nlParse.png" alt="Image" /></p>
<p><img src="https://www.krivalar.com/picture/tree/exp/exp.jpg" alt="Image" /></p>
<hr />
<h2 id="heading-full-browser-flow-big-picture">Full Browser Flow (Big Picture)</h2>
<p><img src="https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnmgeburj0q5o1vazjkxr.png" alt="Image" /></p>
<p><img src="https://miro.medium.com/v2/resize%3Afit%3A2000/1%2AAjwXe0spMClgE9KhBxuB1Q.png" alt="Image" /></p>
<p><img src="https://i.sstatic.net/nxhk6.jpg" alt="Image" /></p>
<p>Flow summary:</p>
<ol>
<li><p>URL entered</p>
</li>
<li><p>Files fetched</p>
</li>
<li><p>HTML → DOM</p>
</li>
<li><p>CSS → CSSOM</p>
</li>
<li><p>DOM + CSSOM → Render Tree</p>
</li>
<li><p>Layout</p>
</li>
<li><p>Paint</p>
</li>
<li><p>Display</p>
</li>
</ol>
<hr />
<h2 id="heading-important-reassurance-for-beginners">Important Reassurance for Beginners</h2>
<ul>
<li><p>You <strong>do not</strong> need to remember everything</p>
</li>
<li><p>Understanding the <strong>flow</strong> is enough</p>
</li>
<li><p>These concepts will repeat naturally in:</p>
<ul>
<li><p>CSS</p>
</li>
<li><p>JavaScript</p>
</li>
<li><p>Performance topics</p>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>If the flow makes sense, you are learning correctly.</p>
</blockquote>
<hr />
<h2 id="heading-key-takeaway">Key Takeaway</h2>
<p>A browser is not magic.<br />It’s a <strong>well-organized pipeline</strong> that turns text files into visuals.</p>
]]></content:encoded></item><item><title><![CDATA[TCP Working: 3-Way Handshake & Reliable Communication]]></title><description><![CDATA[Start With a Simple Question
What happens if computers send data without rules?
Imagine sending a long message in pieces:

Some pieces arrive late

Some arrive twice

Some never arrive

Some arrive in the wrong order


The receiver gets confused data...]]></description><link>https://blog.jainviral.com/tcp-3-way</link><guid isPermaLink="true">https://blog.jainviral.com/tcp-3-way</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:59:48 GMT</pubDate><content:encoded><![CDATA[<hr />
<h2 id="heading-start-with-a-simple-question">Start With a Simple Question</h2>
<p><strong>What happens if computers send data without rules?</strong></p>
<p>Imagine sending a long message in pieces:</p>
<ul>
<li><p>Some pieces arrive late</p>
</li>
<li><p>Some arrive twice</p>
</li>
<li><p>Some never arrive</p>
</li>
<li><p>Some arrive in the wrong order</p>
</li>
</ul>
<p>The receiver gets <strong>confused data</strong>.</p>
<p>This is exactly the problem the internet faced early on.</p>
<hr />
<h2 id="heading-what-is-tcp-and-why-it-is-needed">What Is TCP and Why It Is Needed</h2>
<p><strong>TCP (Transmission Control Protocol)</strong> is a set of rules that makes sure data is:</p>
<ul>
<li><p>Delivered</p>
</li>
<li><p>Delivered in order</p>
</li>
<li><p>Delivered correctly</p>
</li>
</ul>
<p>Simple definition:</p>
<blockquote>
<p><strong>TCP is a protocol that guarantees reliable communication between two computers.</strong></p>
</blockquote>
<p>Without TCP, most internet applications would break.</p>
<hr />
<h2 id="heading-problems-tcp-is-designed-to-solve">Problems TCP Is Designed to Solve</h2>
<p>TCP exists to solve these real problems:</p>
<ol>
<li><p><strong>Data loss</strong> – packets may disappear</p>
</li>
<li><p><strong>Out-of-order delivery</strong> – packets may arrive mixed</p>
</li>
<li><p><strong>Duplicate packets</strong> – packets may arrive twice</p>
</li>
<li><p><strong>Network congestion</strong> – network may be slow or overloaded</p>
</li>
<li><p><strong>Unreliable connections</strong> – sender and receiver may not be ready</p>
</li>
</ol>
<p>TCP handles all of this <strong>automatically</strong>.</p>
<hr />
<h2 id="heading-big-picture-tcp-connection-lifecycle">Big Picture: TCP Connection Lifecycle</h2>
<p><img src="https://www.ibm.com/support/pages/system/files/inline-images/Flow%20chart%20TCP%20connection_0.jpg" alt="Image" /></p>
<p><img src="https://www.tcpipguide.com/free/diagrams/tcpclose.png" alt="Image" /></p>
<p><img src="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" alt="Image" /></p>
<p>TCP has three main phases:</p>
<ol>
<li><p>Connection setup</p>
</li>
<li><p>Data transfer</p>
</li>
<li><p>Connection close</p>
</li>
</ol>
<hr />
<h2 id="heading-what-is-the-tcp-3-way-handshake">What Is the TCP 3-Way Handshake</h2>
<p>Before sending data, TCP first asks:</p>
<blockquote>
<p>“Are you ready to talk reliably?”</p>
</blockquote>
<p>This is done using the <strong>3-Way Handshake</strong>.</p>
<p>Purpose:</p>
<ul>
<li><p>Make sure both sides are reachable</p>
</li>
<li><p>Agree to start a connection</p>
</li>
<li><p>Synchronize communication</p>
</li>
</ul>
<hr />
<h2 id="heading-3-way-handshake-conversation-analogy">3-Way Handshake (Conversation Analogy)</h2>
<p>Think of a phone call:</p>
<ol>
<li><p><strong>Client</strong>: “Can you hear me?”</p>
</li>
<li><p><strong>Server</strong>: “Yes, I hear you. Can you hear me?”</p>
</li>
<li><p><strong>Client</strong>: “Yes, let’s talk.”</p>
</li>
</ol>
<p>Only after this does the conversation start.</p>
<hr />
<h2 id="heading-step-by-step-syn-syn-ack-ack">Step-by-Step: SYN, SYN-ACK, ACK</h2>
<p><img src="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" alt="Image" /></p>
<p><img src="https://www.flamingbytes.com/images/tcp-handshake-1.png" alt="Image" /></p>
<p><img src="https://miro.medium.com/v2/resize%3Afit%3A1200/1%2AQSRdzOUUaloxzs84nl7exA.jpeg" alt="Image" /></p>
<h3 id="heading-step-1-syn">Step 1: SYN</h3>
<p>Client → Server</p>
<blockquote>
<p>“I want to connect.”</p>
</blockquote>
<p>This packet is called <strong>SYN</strong> (synchronize).</p>
<hr />
<h3 id="heading-step-2-syn-ack">Step 2: SYN-ACK</h3>
<p>Server → Client</p>
<blockquote>
<p>“I received your request, and I’m ready.”</p>
</blockquote>
<p>This packet is <strong>SYN + ACK</strong>.</p>
<hr />
<h3 id="heading-step-3-ack">Step 3: ACK</h3>
<p>Client → Server</p>
<blockquote>
<p>“I received your response.”</p>
</blockquote>
<p>Connection is now <strong>established</strong>.</p>
<p>Important:</p>
<blockquote>
<p>No application data is sent before this completes.</p>
</blockquote>
<hr />
<h2 id="heading-how-data-transfer-works-in-tcp">How Data Transfer Works in TCP</h2>
<p>Once connected, TCP starts sending data in <strong>small pieces</strong> called segments.</p>
<p>Each piece has:</p>
<ul>
<li><p>A <strong>sequence number</strong></p>
</li>
<li><p>An expected <strong>acknowledgement</strong></p>
</li>
</ul>
<p>You don’t need exact numbers—just the idea.</p>
<hr />
<h2 id="heading-sequence-numbers-high-level">Sequence Numbers (High Level)</h2>
<p>Sequence numbers answer:</p>
<blockquote>
<p>“Which part of the data is this?”</p>
</blockquote>
<p>Example idea:</p>
<ul>
<li><p>Packet 1 → bytes 1–100</p>
</li>
<li><p>Packet 2 → bytes 101–200</p>
</li>
</ul>
<p>This allows the receiver to:</p>
<ul>
<li><p>Reorder packets</p>
</li>
<li><p>Detect missing data</p>
</li>
</ul>
<hr />
<h2 id="heading-acknowledgements-acks">Acknowledgements (ACKs)</h2>
<p>After receiving data, the receiver sends back:</p>
<blockquote>
<p>“I got everything up to here.”</p>
</blockquote>
<p>This ACK tells the sender:</p>
<ul>
<li><p>What arrived successfully</p>
</li>
<li><p>What needs to be resent</p>
</li>
</ul>
<hr />
<h2 id="heading-tcp-data-transfer-flow">TCP Data Transfer Flow</h2>
<p><img src="https://static.wixstatic.com/media/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg/v1/fill/w_566%2Ch_480%2Cal_c%2Clg_1%2Cq_80/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg" alt="Image" /></p>
<p><img src="https://www.firewall.cx/images/stories/tcp-analysis-section-2-5.gif" alt="Image" /></p>
<p><img src="https://miro.medium.com/1%2AFwXZ_kk0uVwSfHhsoLA1uw.png" alt="Image" /></p>
<hr />
<h2 id="heading-how-tcp-ensures-reliability-order-and-correctness">How TCP Ensures Reliability, Order, and Correctness</h2>
<h3 id="heading-1-reliability">1. Reliability</h3>
<ul>
<li><p>Lost packets are detected</p>
</li>
<li><p>Missing data is resent</p>
</li>
</ul>
<h3 id="heading-2-order">2. Order</h3>
<ul>
<li><p>Sequence numbers allow reordering</p>
</li>
<li><p>Application receives data in correct order</p>
</li>
</ul>
<h3 id="heading-3-correctness">3. Correctness</h3>
<ul>
<li><p>Checksums detect corrupted data</p>
</li>
<li><p>Corrupted packets are discarded and resent</p>
</li>
</ul>
<p>All of this happens <strong>behind the scenes</strong>.</p>
<hr />
<h2 id="heading-packet-loss-and-retransmission">Packet Loss and Retransmission</h2>
<p>What if a packet is lost?</p>
<p><img src="https://www.researchgate.net/publication/382092781/figure/fig1/AS%3A11431281259508197%401720533616113/TCP-packet-loss-detection-and-retransmission-triggered-by-a-timeout-or-by-three-duplicate.ppm" alt="Image" /></p>
<p><img src="https://assets.extrahop.com/images/infographics/TCP-RTO-Retransmission-Timeout-Diagram.jpg" alt="Image" /></p>
<p><img src="https://book.systemsapproach.org/_images/f06-12-9780123850591.png" alt="Image" /></p>
<p>Flow:</p>
<ol>
<li><p>Sender sends data</p>
</li>
<li><p>ACK is not received</p>
</li>
<li><p>Sender waits</p>
</li>
<li><p>Sender retransmits missing data</p>
</li>
</ol>
<p>Application code never sees this complexity.</p>
<hr />
<h2 id="heading-how-a-tcp-connection-is-closed">How a TCP Connection Is Closed</h2>
<p>Closing a TCP connection is also controlled.</p>
<p>TCP does <strong>not</strong> just disappear.</p>
<hr />
<h2 id="heading-connection-termination-fin-and-ack">Connection Termination (FIN and ACK)</h2>
<p><img src="https://www.tcpipguide.com/free/diagrams/tcpclose.png" alt="Image" /></p>
<p><img src="https://www.excentis.com/web/image/122886-2cd58847/tekening_website_blog.webp?access_token=ecea94ef-81de-4cf4-93a0-58e365abdb55" alt="Image" /></p>
<p><img src="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" alt="Image" /></p>
<p>Simple idea:</p>
<ol>
<li><p>One side sends <strong>FIN</strong> → “I’m done sending”</p>
</li>
<li><p>Other side sends <strong>ACK</strong></p>
</li>
<li><p>Other side sends <strong>FIN</strong></p>
</li>
<li><p>First side sends <strong>ACK</strong></p>
</li>
</ol>
<p>Connection is now <strong>cleanly closed</strong>.</p>
<p>Why this matters:</p>
<ul>
<li><p>Prevents data loss</p>
</li>
<li><p>Frees system resources safely</p>
</li>
</ul>
<hr />
<h2 id="heading-key-mental-model-keep-this">Key Mental Model (Keep This)</h2>
<ul>
<li><p>TCP is <strong>careful</strong></p>
</li>
<li><p>TCP checks everything</p>
</li>
<li><p>TCP fixes problems automatically</p>
</li>
<li><p>TCP trades speed for correctness</p>
</li>
</ul>
<p>That’s why TCP is used for:</p>
<ul>
<li><p>HTTP / APIs</p>
</li>
<li><p>Logins</p>
</li>
<li><p>Payments</p>
</li>
<li><p>File transfers</p>
</li>
</ul>
<hr />
<h2 id="heading-final-reassurance">Final Reassurance</h2>
<p>You do <strong>not</strong> need to:</p>
<ul>
<li><p>Memorize packet formats</p>
</li>
<li><p>Remember flags in detail</p>
</li>
<li><p>Know exact numbers</p>
</li>
</ul>
<p>If you understand:</p>
<blockquote>
<p><strong>Handshake → Reliable transfer → Clean close</strong></p>
</blockquote>
<p>You understand TCP well enough to move forward.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[TCP vs UDP: When to Use What, and How TCP Relates to HTTP]]></title><description><![CDATA[Start With the Big Idea
The internet needs rules to send data.
When one computer sends data to another, both sides must agree on:

How data is sent

How errors are handled

What happens if data is lost


These rules are called protocols.
At a very hi...]]></description><link>https://blog.jainviral.com/tcp-vs-udp</link><guid isPermaLink="true">https://blog.jainviral.com/tcp-vs-udp</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:59:18 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-start-with-the-big-idea">Start With the Big Idea</h2>
<p><strong>The internet needs rules to send data.</strong></p>
<p>When one computer sends data to another, both sides must agree on:</p>
<ul>
<li><p>How data is sent</p>
</li>
<li><p>How errors are handled</p>
</li>
<li><p>What happens if data is lost</p>
</li>
</ul>
<p>These rules are called <strong>protocols</strong>.</p>
<p>At a very high level:</p>
<blockquote>
<p><strong>TCP and UDP are rules for how data is transported.</strong></p>
</blockquote>
<hr />
<h2 id="heading-what-are-tcp-and-udp-very-high-level">What Are TCP and UDP? (Very High Level)</h2>
<h3 id="heading-tcp-transmission-control-protocol">TCP (Transmission Control Protocol)</h3>
<p>TCP is <strong>reliable and safe</strong>.</p>
<p>Simple definition:</p>
<blockquote>
<p><strong>TCP makes sure data arrives correctly, in order, and completely.</strong></p>
</blockquote>
<p>If something goes wrong, TCP fixes it.</p>
<hr />
<h3 id="heading-udp-user-datagram-protocol">UDP (User Datagram Protocol)</h3>
<p>UDP is <strong>fast but unreliable</strong>.</p>
<p>Simple definition:</p>
<blockquote>
<p><strong>UDP sends data quickly without checking if it arrived safely.</strong></p>
</blockquote>
<p>If data is lost, UDP does <strong>nothing</strong> about it.</p>
<hr />
<h2 id="heading-core-difference-one-line-each">Core Difference (One Line Each)</h2>
<ul>
<li><p><strong>TCP</strong>: “Send carefully, confirm everything.”</p>
</li>
<li><p><strong>UDP</strong>: “Send fast, don’t ask questions.”</p>
</li>
</ul>
<hr />
<h2 id="heading-tcp-vs-udp-communication-flow">TCP vs UDP Communication Flow</h2>
<p><img src="https://miro.medium.com/1%2AZPtAG6N2qQB_iIFzEtPP7Q.png" alt="Image" /></p>
<p><img src="https://www.metered.ca/blog/content/images/2024/10/image.png" alt="Image" /></p>
<p><img src="https://www.cloud4y.ru/upload/medialibrary/b74/d97dkgfm5tu0ngqu8oirrev3ltj4rqql/TCP-i-UDP.jpeg" alt="Image" /></p>
<hr />
<h2 id="heading-key-differences-between-tcp-and-udp">Key Differences Between TCP and UDP</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>TCP</td><td>UDP</td></tr>
</thead>
<tbody>
<tr>
<td>Reliability</td><td>Guaranteed</td><td>Not guaranteed</td></tr>
<tr>
<td>Order of data</td><td>Maintained</td><td>Not maintained</td></tr>
<tr>
<td>Speed</td><td>Slower</td><td>Faster</td></tr>
<tr>
<td>Error handling</td><td>Yes</td><td>No</td></tr>
<tr>
<td>Connection</td><td>Required</td><td>Not required</td></tr>
</tbody>
</table>
</div><p>You don’t choose TCP or UDP based on preference.<br />You choose based on <strong>use case</strong>.</p>
<hr />
<h2 id="heading-when-to-use-tcp">When to Use TCP</h2>
<p>Use TCP when <strong>correctness matters more than speed</strong>.</p>
<p>Examples:</p>
<ul>
<li><p>Web pages</p>
</li>
<li><p>APIs</p>
</li>
<li><p>Login systems</p>
</li>
<li><p>Payments</p>
</li>
<li><p>File downloads</p>
</li>
<li><p>Emails</p>
</li>
</ul>
<p>Why:</p>
<blockquote>
<p>Missing or incorrect data is unacceptable.</p>
</blockquote>
<hr />
<h2 id="heading-when-to-use-udp">When to Use UDP</h2>
<p>Use UDP when <strong>speed matters more than perfection</strong>.</p>
<p>Examples:</p>
<ul>
<li><p>Video streaming</p>
</li>
<li><p>Online gaming</p>
</li>
<li><p>Live audio calls</p>
</li>
<li><p>DNS queries</p>
</li>
</ul>
<p>Why:</p>
<blockquote>
<p>A small data loss is better than delay.</p>
</blockquote>
<hr />
<h2 id="heading-real-world-analogy-important">Real-World Analogy (Important)</h2>
<h3 id="heading-tcp-analogy">TCP Analogy</h3>
<p>Courier service with tracking:</p>
<ul>
<li><p>Package must arrive</p>
</li>
<li><p>Signature required</p>
</li>
<li><p>Resend if lost</p>
</li>
</ul>
<h3 id="heading-udp-analogy">UDP Analogy</h3>
<p>Live announcement on loudspeaker:</p>
<ul>
<li><p>Fast</p>
</li>
<li><p>No retry</p>
</li>
<li><p>Miss it once, it’s gone</p>
</li>
</ul>
<hr />
<h2 id="heading-real-world-use-cases-mapped">Real-World Use Cases Mapped</h2>
<p><img src="https://robinchen.me/uploads/tech/tcp-udp-comparison-diagram-2.jpg" alt="Image" /></p>
<p><img src="https://www.metered.ca/blog/content/images/2024/10/tcp-vs-udp-1.png" alt="Image" /></p>
<p><img src="https://pinggy.io/images/udp_vs_tcp_complete_guide/udp_vs_tcp.webp" alt="Image" /></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Application</td><td>Protocol</td></tr>
</thead>
<tbody>
<tr>
<td>Web browsing</td><td>TCP</td></tr>
<tr>
<td>REST APIs</td><td>TCP</td></tr>
<tr>
<td>Video call</td><td>UDP</td></tr>
<tr>
<td>Online games</td><td>UDP</td></tr>
<tr>
<td>File transfer</td><td>TCP</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-what-is-http-and-where-it-fits">What Is HTTP and Where It Fits</h2>
<p>HTTP stands for <strong>HyperText Transfer Protocol</strong>.</p>
<p>Important clarification:</p>
<blockquote>
<p><strong>HTTP is NOT responsible for sending data over the network.</strong></p>
</blockquote>
<p>HTTP defines:</p>
<ul>
<li><p>Requests (GET, POST, etc.)</p>
</li>
<li><p>Responses (status codes, headers, body)</p>
</li>
<li><p>Rules for web communication</p>
</li>
</ul>
<p>Think of HTTP as:</p>
<blockquote>
<p><strong>What is being said</strong>, not <strong>how it travels</strong></p>
</blockquote>
<hr />
<h2 id="heading-relationship-between-tcp-and-http">Relationship Between TCP and HTTP</h2>
<p>HTTP <strong>runs on top of TCP</strong>.</p>
<p>That means:</p>
<ul>
<li><p>TCP handles delivery</p>
</li>
<li><p>HTTP handles meaning</p>
</li>
</ul>
<p><img src="https://www.researchgate.net/publication/2851190/figure/fig4/AS%3A668708510908419%401536443941338/HTTP-GET-request-and-reply-over-TCP.png" alt="Image" /></p>
<p><img src="https://miro.medium.com/1%2ARTG5CBW7BIfCFLirf4S5XA.png" alt="Image" /></p>
<p><img src="https://images.openai.com/static-rsc-3/QwQ3Y2GvTk_wZlpNJJnpez4hI1Y10EocUTXlBTjvQj96sIHNm8aZjX4cvtk0DdyDQt30zgEXGaiUHdbHLP6IEiKVMvvKqH-cb42R8UGTJDg?purpose=fullsize" alt="Image" /></p>
<p>Flow:</p>
<ol>
<li><p>TCP connection is established</p>
</li>
<li><p>HTTP request is sent</p>
</li>
<li><p>HTTP response is received</p>
</li>
<li><p>TCP ensures everything arrives correctly</p>
</li>
</ol>
<hr />
<h2 id="heading-why-http-does-not-replace-tcp">Why HTTP Does NOT Replace TCP</h2>
<p>This is a common beginner confusion.</p>
<ul>
<li><p>TCP = delivery system</p>
</li>
<li><p>HTTP = communication format</p>
</li>
</ul>
<p>Analogy:</p>
<ul>
<li><p>TCP is the road</p>
</li>
<li><p>HTTP is the language spoken by vehicles</p>
</li>
</ul>
<p>HTTP <strong>cannot work without a transport protocol</strong>.</p>
<hr />
<h2 id="heading-simplified-layering-mental-model">Simplified Layering (Mental Model)</h2>
<p><img src="https://images.openai.com/static-rsc-3/0WQejBCqkoIauD04XRwVXXvBGbrbp53tsxecM7fpalksI0dXtqgEBcHZnBt7XeweVIQVbpN50ARgilxMaqesBWkhLJhvgOdFEFyOpjALOZw?purpose=fullsize" alt="Image" /></p>
<p><img src="https://images.openai.com/static-rsc-3/aYoO7ZisGkk4PBVULClsTzjzIvXcZazSuAv36PREQ4OsCcz-pp-lNf7dBlJ-aswM-fShajCo7suANgcrU6eyUHFF2cnTFrwlk0vk77TxXm0?purpose=fullsize" alt="Image" /></p>
<p><img src="https://images.openai.com/static-rsc-3/QwQ3Y2GvTk_wZlpNJJnpez4hI1Y10EocUTXlBTjvQj96sIHNm8aZjX4cvtk0DdyDQt30zgEXGaiUHdbHLP6IEiKVMvvKqH-cb42R8UGTJDg?purpose=fullsize" alt="Image" /></p>
<p>Simplified stack:</p>
<ul>
<li><p>Application layer → HTTP</p>
</li>
<li><p>Transport layer → TCP / UDP</p>
</li>
<li><p>Network layer → IP</p>
</li>
</ul>
<p>Each layer has <strong>one job</strong>.</p>
<hr />
<h2 id="heading-common-beginner-confusion-cleared">Common Beginner Confusion (Cleared)</h2>
<p><strong>“Is HTTP the same as TCP?”</strong><br />No.</p>
<p><strong>“Can HTTP work without TCP?”</strong><br />No (traditional HTTP).</p>
<p><strong>“Does UDP use HTTP?”</strong><br />No.</p>
<p>Just remember:</p>
<blockquote>
<p><strong>HTTP explains the message. TCP delivers it safely.</strong></p>
</blockquote>
<hr />
<h2 id="heading-final-takeaway">Final Takeaway</h2>
<ul>
<li><p>TCP and UDP are <strong>transport rules</strong></p>
</li>
<li><p>TCP = reliable, UDP = fast</p>
</li>
<li><p>HTTP is an <strong>application-level protocol</strong></p>
</li>
<li><p>HTTP depends on TCP</p>
</li>
<li><p>They solve different problems</p>
</li>
</ul>
<p>You don’t need protocol internals to use them well.<br />You just need to understand <strong>behavior and purpose</strong>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Understanding Network Devices]]></title><description><![CDATA[Start With the Big Picture
How does the internet reach your home or office?
When you open a website, data travels through multiple devices, each with a very specific job.None of them are optional in real systems — they work together.
High-level flow:...]]></description><link>https://blog.jainviral.com/understanding-network-devices</link><guid isPermaLink="true">https://blog.jainviral.com/understanding-network-devices</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:58:53 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-start-with-the-big-picture">Start With the Big Picture</h2>
<p><strong>How does the internet reach your home or office?</strong></p>
<p>When you open a website, data travels through <strong>multiple devices</strong>, each with a very specific job.<br />None of them are optional in real systems — they work <strong>together</strong>.</p>
<p>High-level flow:</p>
<pre><code class="lang-plaintext">Internet → Modem → Router → Switch → Devices / Servers
</code></pre>
<p>Let’s break this down one device at a time.</p>
<hr />
<h2 id="heading-what-is-a-modem-and-how-it-connects-you-to-the-internet">What Is a Modem and How It Connects You to the Internet?</h2>
<p>A <strong>modem</strong> is the device that <strong>connects your local network to your Internet Service Provider (ISP)</strong>.</p>
<h3 id="heading-responsibility-one-line">Responsibility (one line)</h3>
<blockquote>
<p><strong>Modem = translator between ISP signals and your network</strong></p>
</blockquote>
<p>Your ISP sends data using:</p>
<ul>
<li><p>Fiber signals</p>
</li>
<li><p>Cable signals</p>
</li>
<li><p>DSL signals</p>
</li>
</ul>
<p>Your devices don’t understand those formats.<br />The modem <strong>converts</strong> them into usable digital data.</p>
<h3 id="heading-important-clarification">Important clarification</h3>
<ul>
<li><p>Modem <strong>does NOT manage traffic</strong></p>
</li>
<li><p>Modem <strong>does NOT decide destinations</strong></p>
</li>
<li><p>It only <strong>connects you to the internet</strong></p>
</li>
</ul>
<hr />
<h2 id="heading-what-is-a-router-and-how-it-directs-traffic">What Is a Router and How It Directs Traffic?</h2>
<p>A <strong>router</strong> decides <strong>where data should go</strong>.</p>
<h3 id="heading-responsibility">Responsibility</h3>
<blockquote>
<p><strong>Router = traffic police of the network</strong></p>
</blockquote>
<p>It:</p>
<ul>
<li><p>Assigns local IP addresses</p>
</li>
<li><p>Sends data to the correct device</p>
</li>
<li><p>Connects your local network to the modem</p>
</li>
<li><p>Routes packets between networks</p>
</li>
</ul>
<p>Example:</p>
<ul>
<li><p>Laptop requests Google</p>
</li>
<li><p>Router forwards request to modem</p>
</li>
<li><p>Response comes back</p>
</li>
<li><p>Router sends it to the correct laptop</p>
</li>
</ul>
<hr />
<h2 id="heading-internet-to-device-flow-typical-setup">Internet to Device Flow (Typical Setup)</h2>
<p><img src="https://cdn.shopify.com/s/files/1/0613/4041/8306/files/LO-Connection_of_networks_through_Router.png?v=1659944198" alt="Image" /></p>
<p><img src="https://www.uml-diagrams.org/examples/home-network-diagram-example.png" alt="Image" /></p>
<p><img src="https://www.researchgate.net/publication/349839218/figure/fig1/AS%3A1075919410204674%401633530585687/An-overview-of-the-network-traffic-flow-between-various-devices.ppm" alt="Image" /></p>
<hr />
<h2 id="heading-switch-vs-hub-how-local-networks-actually-work">Switch vs Hub: How Local Networks Actually Work</h2>
<p>Both <strong>hub</strong> and <strong>switch</strong> connect multiple devices, but they behave very differently.</p>
<hr />
<h2 id="heading-what-is-a-hub">What Is a Hub?</h2>
<p>A <strong>hub</strong> is a very basic device.</p>
<h3 id="heading-how-it-works">How it works</h3>
<ul>
<li><p>Receives data</p>
</li>
<li><p>Sends it to <strong>every device</strong></p>
</li>
<li><p>No intelligence</p>
</li>
</ul>
<p>Analogy:</p>
<blockquote>
<p>A person shouting in a room so everyone hears the message</p>
</blockquote>
<p>Problems:</p>
<ul>
<li><p>Wastes bandwidth</p>
</li>
<li><p>Security risk</p>
</li>
<li><p>Almost obsolete today</p>
</li>
</ul>
<hr />
<h2 id="heading-what-is-a-switch">What Is a Switch?</h2>
<p>A <strong>switch</strong> is a smarter device used in real networks.</p>
<h3 id="heading-how-it-works-1">How it works</h3>
<ul>
<li><p>Learns device addresses</p>
</li>
<li><p>Sends data <strong>only to the target device</strong></p>
</li>
<li><p>Efficient and secure</p>
</li>
</ul>
<p>Analogy:</p>
<blockquote>
<p>Delivering a letter directly to the correct house</p>
</blockquote>
<hr />
<h2 id="heading-hub-vs-switch-visual-difference">Hub vs Switch (Visual Difference)</h2>
<p><img src="https://www.scaler.com/topics/images/difference-between-hub-and-switch_thumbnail.webp" alt="Image" /></p>
<p><img src="https://scaler.com/topics/images/device-connected-by-hub.webp" alt="Image" /></p>
<p><img src="https://media.licdn.com/dms/image/v2/D4D22AQG8aoMnKkTc2w/feedshare-shrink_800/B4DZaBWhKIHwAg-/0/1745926887187?e=2147483647&amp;t=yvOqO7pzNqG-fBSyVUE2i2tXmS0Ieru3-btav0uWjb8&amp;v=beta" alt="Image" /></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Hub</td><td>Switch</td></tr>
</thead>
<tbody>
<tr>
<td>Sends data to</td><td>Everyone</td><td>Only target</td></tr>
<tr>
<td>Intelligence</td><td>None</td><td>High</td></tr>
<tr>
<td>Used today</td><td>Rare</td><td>Everywhere</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-what-is-a-firewall-and-why-security-lives-here">What Is a Firewall and Why Security Lives Here?</h2>
<p>A <strong>firewall</strong> controls <strong>what traffic is allowed or blocked</strong>.</p>
<h3 id="heading-responsibility-1">Responsibility</h3>
<blockquote>
<p><strong>Firewall = security gate</strong></p>
</blockquote>
<p>It:</p>
<ul>
<li><p>Allows trusted traffic</p>
</li>
<li><p>Blocks malicious traffic</p>
</li>
<li><p>Protects internal systems</p>
</li>
<li><p>Applies security rules</p>
</li>
</ul>
<p>Firewalls can exist:</p>
<ul>
<li><p>In routers</p>
</li>
<li><p>As separate hardware</p>
</li>
<li><p>As cloud services</p>
</li>
</ul>
<p>Without firewalls, networks are <strong>open targets</strong>.</p>
<hr />
<h2 id="heading-firewall-placement-in-a-network">Firewall Placement in a Network</h2>
<p><img src="https://community.ja.net/system/files/images/firewalls-tg-05.jpg" alt="Image" /></p>
<p><img src="https://i.sstatic.net/WadM1.png" alt="Image" /></p>
<p><img src="https://images.openai.com/static-rsc-3/sUFAfX6QnPAeq38h-74Zlg6qG8N2awhQRfd-8Vd40P-yIZQ7xBt1lnfR_sFsODBC93Lew3UXbJLIlxZfgniFK4RdCZvZDZo9O-Y65pIdgaA?purpose=fullsize" alt="Image" /></p>
<p>Think of it as:</p>
<blockquote>
<p>Every packet must pass through security before entering the system.</p>
</blockquote>
<hr />
<h2 id="heading-what-is-a-load-balancer-and-why-scalable-systems-need-it">What Is a Load Balancer and Why Scalable Systems Need It?</h2>
<p>A <strong>load balancer</strong> sits in front of <strong>multiple servers</strong>.</p>
<h3 id="heading-responsibility-2">Responsibility</h3>
<blockquote>
<p><strong>Load balancer = traffic distributor</strong></p>
</blockquote>
<p>Instead of one server handling everything:</p>
<ul>
<li><p>Traffic is spread across many servers</p>
</li>
<li><p>Systems stay fast</p>
</li>
<li><p>Failures are handled gracefully</p>
</li>
</ul>
<p>Analogy:</p>
<blockquote>
<p>Toll booth with multiple lanes instead of one</p>
</blockquote>
<hr />
<h2 id="heading-load-balancer-in-action">Load Balancer in Action</h2>
<p><img src="https://substackcdn.com/image/fetch/%24s_%214Uyj%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a1213e2-86cb-4fa8-bf72-e37ffe0da44d_2250x2624.heic" alt="Image" /></p>
<p><img src="https://severalnines.com/sites/default/files/blog/node_6056/image1.png" alt="Image" /></p>
<p><img src="https://cdn.document360.io/69e9f9c7-5da8-45e7-a671-4b8287f36122/Images/Documentation/image-1678474126859.png" alt="Image" /></p>
<p>If one server goes down:</p>
<ul>
<li><p>Load balancer stops sending traffic to it</p>
</li>
<li><p>Users don’t notice</p>
</li>
</ul>
<p>This is critical for:</p>
<ul>
<li><p>High traffic websites</p>
</li>
<li><p>APIs</p>
</li>
<li><p>Fintech and SaaS systems</p>
</li>
</ul>
<hr />
<h2 id="heading-how-all-these-devices-work-together-real-world">How All These Devices Work Together (Real World)</h2>
<p>Let’s combine everything.</p>
<p><img src="https://cdn.sayonetech.com/media/media/2024/01/11/responsive-web-design-vs-adaptive-web-design-1.jpg" alt="Image" /></p>
<p><img src="https://images.wondershare.com/edrawmax/templates/network-diagram-for-load-balancing.png" alt="Image" /></p>
<p><img src="https://ars.els-cdn.com/content/image/1-s2.0-B9780323885065502849-f284-01-9780323885065.jpg" alt="Image" /></p>
<h3 id="heading-end-to-end-flow">End-to-End Flow</h3>
<ol>
<li><p>Internet traffic reaches the <strong>modem</strong></p>
</li>
<li><p>Router directs it to the correct network</p>
</li>
<li><p>Firewall checks security rules</p>
</li>
<li><p>Load balancer distributes requests</p>
</li>
<li><p>Switch connects internal servers</p>
</li>
<li><p>Application responds</p>
</li>
</ol>
<p>Every step has a <strong>single responsibility</strong>.</p>
<hr />
<h2 id="heading-why-this-matters-for-software-engineers">Why This Matters for Software Engineers</h2>
<p>Even if you write only code:</p>
<ul>
<li><p>APIs depend on routers and firewalls</p>
</li>
<li><p>Scalability depends on load balancers</p>
</li>
<li><p>Downtime often starts at the network level</p>
</li>
</ul>
<p>Understanding this helps with:</p>
<ul>
<li><p>Debugging production issues</p>
</li>
<li><p>Designing scalable systems</p>
</li>
<li><p>Communicating with DevOps teams</p>
</li>
</ul>
<hr />
<h2 id="heading-final-mental-model-keep-this">Final Mental Model (Keep This)</h2>
<ul>
<li><p><strong>Modem</strong> → connects you to ISP</p>
</li>
<li><p><strong>Router</strong> → directs traffic</p>
</li>
<li><p><strong>Switch</strong> → connects devices efficiently</p>
</li>
<li><p><strong>Firewall</strong> → protects the network</p>
</li>
<li><p><strong>Load Balancer</strong> → scales applications</p>
</li>
</ul>
<p>You don’t need to memorize hardware models.<br />You just need to understand <strong>who does what</strong>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[DNS Record Types Explained]]></title><description><![CDATA[How Does a Browser Know Where a Website Lives?
Imagine you want to visit a friend's house, but you only know their name — not their actual street address. You'd probably look them up in your contacts or a phone book to find where they live. The inter...]]></description><link>https://blog.jainviral.com/dns-record</link><guid isPermaLink="true">https://blog.jainviral.com/dns-record</guid><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:53:20 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-how-does-a-browser-know-where-a-website-lives">How Does a Browser Know Where a Website Lives?</h2>
<p>Imagine you want to visit a friend's house, but you only know their name — not their actual street address. You'd probably look them up in your contacts or a phone book to find where they live. The internet works in a remarkably similar way.</p>
<p>When you type <a target="_blank" href="http://www.example.com"><code>www.example.com</code></a> into your browser, your computer doesn't actually know where that website "lives" on the internet. It needs to look up the actual location, just like you'd look up a friend's address. This is where DNS comes in.</p>
<h2 id="heading-what-is-dns-the-internets-phone-book">What is DNS? (The Internet's Phone Book)</h2>
<p><strong>DNS</strong> stands for <strong>Domain Name System</strong>, but you can think of it simply as the internet's phone book or address directory.</p>
<p>Here's the basic idea: computers and servers on the internet communicate using numbers called IP addresses (like <code>192.168.1.1</code>). But humans aren't great at remembering long strings of numbers. We're much better with names like <a target="_blank" href="http://google.com"><code>google.com</code></a> or <a target="_blank" href="http://amazon.com"><code>amazon.com</code></a>.</p>
<p>DNS is the system that translates human-friendly domain names into computer-friendly IP addresses. It's the bridge between what we want (easy-to-remember names) and what computers need (numerical addresses).</p>
<p><strong>The simple flow:</strong></p>
<pre><code class="lang-plaintext">You type: www.example.com
    ↓
DNS translates it to: 93.184.216.34
    ↓
Your browser connects to: 93.184.216.34
    ↓
You see: The website!
</code></pre>
<h2 id="heading-why-do-we-need-dns-records">Why Do We Need DNS Records?</h2>
<p>Think of DNS records as different types of information stored in that internet phone book. Just like a contact card might have someone's home address, work address, email, and phone number, a domain name needs different types of information to work properly.</p>
<p>DNS records tell the internet:</p>
<ul>
<li><p>Where to find your website</p>
</li>
<li><p>Where to send your emails</p>
</li>
<li><p>Who's responsible for managing your domain</p>
</li>
<li><p>And much more</p>
</li>
</ul>
<p>Without DNS records, domain names would be useless — like having a business card with just a name and no contact information.</p>
<h2 id="heading-dns-record-types-your-internet-contact-card">DNS Record Types: Your Internet Contact Card</h2>
<p>Let's explore the most important types of DNS records. We'll introduce them one at a time, showing what problem each one solves.</p>
<h3 id="heading-1-ns-record-name-server-record-whos-in-charge-here">1. NS Record (Name Server Record) — Who's in Charge Here?</h3>
<p><strong>The problem it solves:</strong> When someone asks about your domain, who should they ask for the official information?</p>
<p>Think of NS records as the manager or authority for your domain. They tell the internet, "If you want to know anything about this domain, ask these specific servers."</p>
<p><strong>Real-life comparison:</strong> If someone wants to know your work schedule, they should ask your manager, not a random person on the street.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">example.com    NS    ns1.hostingcompany.com
example.com    NS    ns2.hostingcompany.com
</code></pre>
<p>This says: "For any information about <a target="_blank" href="http://example.com">example.com</a>, check with <a target="_blank" href="http://ns1.hostingcompany.com">ns1.hostingcompany.com</a> and <a target="_blank" href="http://ns2.hostingcompany.com">ns2.hostingcompany.com</a> — they're the official sources."</p>
<p>You typically have multiple NS records for backup. If one name server is down, the other can still answer questions.</p>
<hr />
<h3 id="heading-2-a-record-address-record-where-does-your-website-live">2. A Record (Address Record) — Where Does Your Website Live?</h3>
<p><strong>The problem it solves:</strong> When someone types your domain into a browser, where should their computer actually connect?</p>
<p>The A record is the most fundamental DNS record. It maps your domain name to an IPv4 address (the current standard for internet addresses).</p>
<p><strong>Real-life comparison:</strong> This is like saying "John Smith lives at 123 Main Street." The A record connects a name to a physical location.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">example.com           A    93.184.216.34
www.example.com       A    93.184.216.34
blog.example.com      A    198.51.100.10
</code></pre>
<p>Here we're saying:</p>
<ul>
<li><p><a target="_blank" href="http://example.com"><code>example.com</code></a> points to server <code>93.184.216.34</code></p>
</li>
<li><p><a target="_blank" href="http://www.example.com"><code>www.example.com</code></a> also points to <code>93.184.216.34</code> (same server)</p>
</li>
<li><p><a target="_blank" href="http://blog.example.com"><code>blog.example.com</code></a> points to a different server at <code>198.51.100.10</code></p>
</li>
</ul>
<p>Notice how you can have different subdomains (www, blog, shop) pointing to different servers, each with their own A record.</p>
<hr />
<h3 id="heading-3-aaaa-record-ipv6-address-record-the-future-of-addresses">3. AAAA Record (IPv6 Address Record) — The Future of Addresses</h3>
<p><strong>The problem it solves:</strong> The same as an A record, but for the newer IPv6 address system.</p>
<p>As the internet grows, we're running out of IPv4 addresses (there are only about 4 billion possible combinations). IPv6 was created to solve this problem, offering vastly more address possibilities.</p>
<p><strong>Real-life comparison:</strong> Like upgrading from a 7-digit phone number to a 10-digit one because we ran out of 7-digit combinations.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">example.com    AAAA    2001:0db8:85a3:0000:0000:8a2e:0370:7334
</code></pre>
<p>The address is much longer, but the concept is identical to an A record — it's just the newer addressing system. Most modern websites have both A and AAAA records to support all visitors.</p>
<hr />
<h3 id="heading-4-cname-record-canonical-name-record-the-nickname">4. CNAME Record (Canonical Name Record) — The Nickname</h3>
<p><strong>The problem it solves:</strong> What if you want multiple domain names to point to the same place without managing multiple IP addresses?</p>
<p>A CNAME record creates an alias — it makes one domain name point to another domain name, rather than directly to an IP address.</p>
<p><strong>Real-life comparison:</strong> If someone asks for "Bob," you might say "Bob is actually Robert Wilson — look him up under that name." You're redirecting them to the canonical (official) name.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">www.example.com       CNAME    example.com
shop.example.com      CNAME    example.com
mobile.example.com    CNAME    example.com
</code></pre>
<p>This says: "Don't ask me for the IP address of <a target="_blank" href="http://www.example.com">www.example.com</a> — just look up <a target="_blank" href="http://example.com">example.com</a> instead." Then when <a target="_blank" href="http://example.com">example.com</a> is looked up, its A record provides the actual IP address.</p>
<p><strong>Important distinction:</strong></p>
<ul>
<li><p><strong>A record:</strong> Points directly to an IP address</p>
</li>
<li><p><strong>CNAME record:</strong> Points to another domain name (which then has its own A record)</p>
</li>
</ul>
<p><strong>Why use CNAME instead of multiple A records?</strong></p>
<p>If your server's IP address changes, you only need to update one A record instead of five. All the CNAME records automatically follow the change.</p>
<p><strong>Common beginner confusion:</strong> You cannot have a CNAME record for your root domain (<a target="_blank" href="http://example.com">example.com</a> itself) — only for subdomains like <a target="_blank" href="http://www.example.com">www.example.com</a> or <a target="_blank" href="http://blog.example.com">blog.example.com</a>. The root must always have an A record.</p>
<hr />
<h3 id="heading-5-mx-record-mail-exchange-record-where-should-email-go">5. MX Record (Mail Exchange Record) — Where Should Email Go?</h3>
<p><strong>The problem it solves:</strong> Email and website hosting are often on different servers. How does an email know where to go?</p>
<p>When someone sends an email to <a target="_blank" href="mailto:hello@example.com"><code>hello@example.com</code></a>, the MX record tells the sending mail server where to deliver it.</p>
<p><strong>Real-life comparison:</strong> Your home address and your PO box might be different. If someone wants to mail you something, you tell them to use the PO box. MX records work the same way for email.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">example.com    MX    10    mail.example.com
example.com    MX    20    backup-mail.example.com
</code></pre>
<p>The numbers (10, 20) are priority levels. Lower numbers = higher priority. So email will try <a target="_blank" href="http://mail.example.com"><code>mail.example.com</code></a> first, and if that's unavailable, try <a target="_blank" href="http://backup-mail.example.com"><code>backup-mail.example.com</code></a>.</p>
<p><strong>Common beginner confusion:</strong> Your website might be hosted at Company A, but your email might be hosted at Company B (like Google Workspace). That's perfectly fine — the MX record handles that separation.</p>
<hr />
<h3 id="heading-6-txt-record-text-record-extra-information-and-verification">6. TXT Record (Text Record) — Extra Information and Verification</h3>
<p><strong>The problem it solves:</strong> Sometimes you need to prove you own a domain or provide additional configuration information.</p>
<p>TXT records hold arbitrary text information. They're incredibly flexible and used for various purposes, most commonly for verification and email security.</p>
<p><strong>Real-life comparison:</strong> Like putting a "Verified by..." sticker on your business window to prove authenticity.</p>
<p><strong>Common uses:</strong></p>
<p><strong>Domain verification:</strong></p>
<pre><code class="lang-plaintext">example.com    TXT    "google-site-verification=abc123xyz789"
</code></pre>
<p>Google asks you to add this record to prove you control the domain.</p>
<p><strong>Email security (SPF - Sender Policy Framework):</strong></p>
<pre><code class="lang-plaintext">example.com    TXT    "v=spf1 include:_spf.google.com ~all"
</code></pre>
<p>This tells email servers which computers are allowed to send email from your domain, helping prevent spam and spoofing.</p>
<p><strong>Email security (DKIM - DomainKeys Identified Mail):</strong></p>
<pre><code class="lang-plaintext">default._domainkey.example.com    TXT    "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
</code></pre>
<p>Provides a cryptographic signature to verify your emails are authentic.</p>
<p>TXT records might look confusing at first, but you'll typically just copy-paste them exactly as provided by your email or web hosting provider.</p>
<hr />
<h2 id="heading-how-all-dns-records-work-together">How All DNS Records Work Together</h2>
<p>Let's see how these records work together for a real website. Imagine you run a small business called "Example Company" with a domain <a target="_blank" href="http://example.com"><code>example.com</code></a>.</p>
<p><strong>Your complete DNS setup might look like this:</strong></p>
<pre><code class="lang-plaintext">; Name Servers - Who manages this domain
example.com              NS      ns1.cloudprovider.com
example.com              NS      ns2.cloudprovider.com

; Website Records
example.com              A       93.184.216.34
www.example.com          A       93.184.216.34
blog.example.com         A       198.51.100.10

; IPv6 support
example.com              AAAA    2001:db8::1
www.example.com          AAAA    2001:db8::1

; Helpful aliases
shop.example.com         CNAME   example.com
store.example.com        CNAME   example.com

; Email routing
example.com              MX      10    mail.google.com
example.com              MX      20    backup.mail.google.com

; Verification and security
example.com              TXT     "google-site-verification=abc123"
example.com              TXT     "v=spf1 include:_spf.google.com ~all"
</code></pre>
<p><strong>What happens when someone visits your website:</strong></p>
<ol>
<li><p>User types <a target="_blank" href="http://www.example.com"><code>www.example.com</code></a> in their browser</p>
</li>
<li><p>Computer asks DNS: "What's the A record for <a target="_blank" href="http://www.example.com">www.example.com</a>?"</p>
</li>
<li><p>DNS responds: "93.184.216.34"</p>
</li>
<li><p>Browser connects to that IP address</p>
</li>
<li><p>Website loads!</p>
</li>
</ol>
<p><strong>What happens when someone sends you an email:</strong></p>
<ol>
<li><p>Someone sends email to <a target="_blank" href="mailto:contact@example.com"><code>contact@example.com</code></a></p>
</li>
<li><p>Their email server asks DNS: "What's the MX record for <a target="_blank" href="http://example.com">example.com</a>?"</p>
</li>
<li><p>DNS responds: "Priority 10: <a target="_blank" href="http://mail.google.com">mail.google.com</a>"</p>
</li>
<li><p>Email is delivered to Google's mail servers</p>
</li>
<li><p>You receive it in your Gmail!</p>
</li>
</ol>
<p><strong>What happens when someone visits</strong> <a target="_blank" href="http://shop.example.com"><code>shop.example.com</code></a>:</p>
<ol>
<li><p>Browser asks: "What's the A record for <a target="_blank" href="http://shop.example.com">shop.example.com</a>?"</p>
</li>
<li><p>DNS responds: "That's a CNAME to <a target="_blank" href="http://example.com">example.com</a>, look that up instead"</p>
</li>
<li><p>Browser asks: "What's the A record for <a target="_blank" href="http://example.com">example.com</a>?"</p>
</li>
<li><p>DNS responds: "93.184.216.34"</p>
</li>
<li><p>Browser connects and website loads!</p>
</li>
</ol>
<hr />
<h2 id="heading-visual-summary-complete-dns-flow">Visual Summary: Complete DNS Flow</h2>
<pre><code class="lang-plaintext">                           ┌─────────────────────┐
                           │   User types URL    │
                           │  www.example.com    │
                           └──────────┬──────────┘
                                      │
                                      ▼
                           ┌─────────────────────┐
                           │   DNS Lookup        │
                           │  "Where is this?"   │
                           └──────────┬──────────┘
                                      │
                   ┌──────────────────┼──────────────────┐
                   │                  │                  │
                   ▼                  ▼                  ▼
         ┌──────────────┐   ┌──────────────┐   ┌──────────────┐
         │  NS Record   │   │   A Record   │   │ CNAME Record │
         │ (Authority)  │   │   (IPv4)     │   │   (Alias)    │
         └──────────────┘   └──────┬───────┘   └──────────────┘
                                   │
                                   ▼
                        ┌────────────────────┐
                        │   IP Address       │
                        │   93.184.216.34    │
                        └──────────┬─────────┘
                                   │
                                   ▼
                        ┌────────────────────┐
                        │   Web Server       │
                        │   Returns Website  │
                        └────────────────────┘


         Email Flow (Separate Path):

         email@example.com
                │
                ▼
         ┌──────────────┐
         │  MX Record   │──────► mail.example.com
         └──────────────┘
                                       │
                                       ▼
                                ┌─────────────┐
                                │ Mail Server │
                                └─────────────┘
</code></pre>
<hr />
<h2 id="heading-quick-reference-guide">Quick Reference Guide</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Record Type</td><td>Purpose</td><td>Points To</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><strong>NS</strong></td><td>Authority for domain</td><td>Name servers</td><td><a target="_blank" href="http://ns1.provider.com"><code>ns1.provider.com</code></a></td></tr>
<tr>
<td><strong>A</strong></td><td>Website location (IPv4)</td><td>IP address</td><td><code>93.184.216.34</code></td></tr>
<tr>
<td><strong>AAAA</strong></td><td>Website location (IPv6)</td><td>IPv6 address</td><td><code>2001:db8::1</code></td></tr>
<tr>
<td><strong>CNAME</strong></td><td>Alias/nickname</td><td>Another domain</td><td><a target="_blank" href="http://example.com"><code>example.com</code></a></td></tr>
<tr>
<td><strong>MX</strong></td><td>Email routing</td><td>Mail server</td><td><a target="_blank" href="http://mail.example.com"><code>mail.example.com</code></a></td></tr>
<tr>
<td><strong>TXT</strong></td><td>Verification/info</td><td>Text data</td><td><code>"verification=abc"</code></td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-common-questions-answered">Common Questions Answered</h2>
<p><strong>Q: Do I need all these record types?</strong><br />At minimum, you need NS records (your provider sets these), A records (for your website), and if you have email, MX records. The others are optional but useful.</p>
<p><strong>Q: Can I have multiple A records for one domain?</strong><br />Yes! This is used for load balancing. The DNS system will rotate between them to distribute traffic.</p>
<p><strong>Q: What's the difference between</strong> <a target="_blank" href="http://example.com"><strong>example.com</strong></a> <strong>and</strong> <a target="_blank" href="http://www.example.com"><strong>www.example.com</strong></a><strong>?</strong><br />They're technically different! <a target="_blank" href="http://example.com"><code>example.com</code></a> is your root domain, and <a target="_blank" href="http://www.example.com"><code>www.example.com</code></a> is a subdomain. You need separate records for each (though they usually point to the same place).</p>
<p><strong>Q: How long do DNS changes take to work?</strong><br />Usually 5 minutes to 48 hours. This is called DNS propagation — the time it takes for the change to spread across all DNS servers worldwide.</p>
<p><strong>Q: Can I see my own DNS records?</strong><br />Yes! Use online tools like "DNS lookup" or "dig" (a command-line tool). Just search for "DNS checker" in your browser.</p>
<hr />
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>DNS might seem complex at first, but at its heart, it's just a directory system — helping computers find each other using friendly names instead of numbers. Each record type solves a specific problem:</p>
<ul>
<li><p><strong>NS</strong>: Who's in charge?</p>
</li>
<li><p><strong>A/AAAA</strong>: Where does the website live?</p>
</li>
<li><p><strong>CNAME</strong>: What are the alternative names?</p>
</li>
<li><p><strong>MX</strong>: Where does email go?</p>
</li>
<li><p><strong>TXT</strong>: Proof and configuration</p>
</li>
</ul>
<p>Once you understand what problem each record solves, DNS becomes much less mysterious. You're not expected to memorize everything — even experienced developers look up syntax regularly. What matters is understanding the purpose of each record type and how they work together to make the internet function smoothly.</p>
<p>Welcome to the world of DNS — you now understand one of the internet's most fundamental systems!</p>
]]></content:encoded></item><item><title><![CDATA[How DNS Resolution Works]]></title><description><![CDATA[What Is DNS and Why Name Resolution Exists
Computers don’t understand names like google.com.They understand IP addresses like 142.250.183.14.
DNS (Domain Name System) exists to translate human-friendly names into machine-friendly IP addresses.
Simple...]]></description><link>https://blog.jainviral.com/how-dns-resolution-works</link><guid isPermaLink="true">https://blog.jainviral.com/how-dns-resolution-works</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:51:52 GMT</pubDate><content:encoded><![CDATA[<hr />
<h2 id="heading-what-is-dns-and-why-name-resolution-exists">What Is DNS and Why Name Resolution Exists</h2>
<p>Computers don’t understand names like <a target="_blank" href="http://google.com"><code>google.com</code></a>.<br />They understand <strong>IP addresses</strong> like <code>142.250.183.14</code>.</p>
<p>DNS (Domain Name System) exists to <strong>translate human-friendly names into machine-friendly IP addresses</strong>.</p>
<p>Simple definition:</p>
<blockquote>
<p><strong>DNS is the internet’s phonebook.</strong></p>
</blockquote>
<p>You remember names.<br />Computers use numbers.<br />DNS connects the two.</p>
<hr />
<h2 id="heading-why-dns-is-needed-real-world-analogy">Why DNS Is Needed (Real-World Analogy)</h2>
<p>Think of calling someone:</p>
<ul>
<li><p>You search a <strong>name</strong> in your contacts</p>
</li>
<li><p>Your phone finds the <strong>number</strong></p>
</li>
<li><p>The call connects</p>
</li>
</ul>
<p>DNS works the same way:</p>
<ul>
<li><p>You type a <strong>domain name</strong></p>
</li>
<li><p>DNS finds the <strong>IP address</strong></p>
</li>
<li><p>Browser connects to the server</p>
</li>
</ul>
<hr />
<h2 id="heading-what-is-the-dig-command">What Is the <code>dig</code> Command</h2>
<p><code>dig</code> stands for <strong>Domain Information Groper</strong>.</p>
<p>It is a <strong>diagnostic tool</strong> used to:</p>
<ul>
<li><p>Inspect DNS resolution</p>
</li>
<li><p>See which name servers are involved</p>
</li>
<li><p>Debug DNS issues</p>
</li>
<li><p>Understand how name resolution works step by step</p>
</li>
</ul>
<p>Simple idea:</p>
<blockquote>
<p><code>dig</code> lets you ask DNS questions directly from the terminal.</p>
</blockquote>
<hr />
<h2 id="heading-where-dig-fits-in-the-big-picture">Where <code>dig</code> Fits in the Big Picture</h2>
<p><img src="https://miro.medium.com/1%2A-kCFoSB3-pMwajK6LTJY6Q.jpeg" alt="Image" /></p>
<p><img src="https://substackcdn.com/image/fetch/%24s_%21piIO%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1adddd56-9fb5-4dc4-ad1a-0faea938acf0_2284x2054.png" alt="Image" /></p>
<p><img src="https://www.inetdaemon.com/img/dns-hierarchy.gif" alt="Image" /></p>
<p>Browsers do DNS automatically.<br /><code>dig</code> lets <strong>you see it manually</strong>.</p>
<hr />
<h2 id="heading-dns-resolution-happens-in-layers">DNS Resolution Happens in Layers</h2>
<p>DNS is not one server.<br />It is a <strong>hierarchy</strong>.</p>
<p>Order:</p>
<ol>
<li><p>Root name servers</p>
</li>
<li><p>TLD name servers (<code>.com</code>, <code>.org</code>, etc.)</p>
</li>
<li><p>Authoritative name servers (for the domain)</p>
</li>
</ol>
<p>This layered design keeps DNS:</p>
<ul>
<li><p>Scalable</p>
</li>
<li><p>Fast</p>
</li>
<li><p>Reliable</p>
</li>
</ul>
<hr />
<h2 id="heading-dns-hierarchy-mental-model">DNS Hierarchy (Mental Model)</h2>
<p><img src="https://substackcdn.com/image/fetch/%24s_%21P_Ol%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0a1bb2c-a1bc-40ce-abde-6fb9d2a66ce8_1600x570.png" alt="Image" /></p>
<p><img src="https://cdn.shortpixel.ai/spai/q_lossy%2Bret_img%2Bto_webp/wp-public-fs.s3.ap-south-1.amazonaws.com/tasks/165d58952b1e9854faee9d165e220fad987e31ad63557b/images/602c130c2edd0f001a8d5ed9-65df147eb8c35.jpg" alt="Image" /></p>
<p><img src="https://images.openai.com/static-rsc-3/v7iHjuBYNqVRIO8sGA2khay3jxWvJ-wQK_-u_3UTtvcztya5Ve846LVrhaOfj4drOYlXNwySKiKw87vsxVi99mTSoj1OXp8hdBEHhqgasME?purpose=fullsize" alt="Image" /></p>
<p>Each layer answers <strong>only what it knows</strong> and points to the next.</p>
<hr />
<h2 id="heading-understanding-dig-ns-root-name-servers">Understanding <code>dig . NS</code> (Root Name Servers)</h2>
<p>Command:</p>
<pre><code class="lang-bash">dig . NS
</code></pre>
<p>What this asks:</p>
<blockquote>
<p>“Who are the name servers for the root (<code>.</code>) of DNS?”</p>
</blockquote>
<p>What you learn:</p>
<ul>
<li><p>These are the <strong>top-level servers</strong></p>
</li>
<li><p>They don’t know IPs for websites</p>
</li>
<li><p>They only know <strong>where TLD servers are</strong></p>
</li>
</ul>
<p>Key idea:</p>
<blockquote>
<p>Root servers are the starting point of DNS, not the end.</p>
</blockquote>
<hr />
<h2 id="heading-understanding-dig-com-ns-tld-name-servers">Understanding <code>dig com NS</code> (TLD Name Servers)</h2>
<p>Command:</p>
<pre><code class="lang-bash">dig com NS
</code></pre>
<p>What this asks:</p>
<blockquote>
<p>“Who manages the <code>.com</code> domain?”</p>
</blockquote>
<p>What you learn:</p>
<ul>
<li><p>These servers manage <strong>all</strong> <code>.com</code> domains</p>
</li>
<li><p>They don’t know <a target="_blank" href="http://google.com"><code>google.com</code></a>’s IP</p>
</li>
<li><p>They know <strong>which servers are responsible for it</strong></p>
</li>
</ul>
<p>Key idea:</p>
<blockquote>
<p>TLD servers narrow the search.</p>
</blockquote>
<hr />
<h2 id="heading-understanding-dig-googlecomhttpgooglecom-ns-authoritative-servers">Understanding <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code> (Authoritative Servers)</h2>
<p>Command:</p>
<pre><code class="lang-bash">dig google.com NS
</code></pre>
<p>What this asks:</p>
<blockquote>
<p>“Which servers are authoritative for <a target="_blank" href="http://google.com"><code>google.com</code></a>?”</p>
</blockquote>
<p>These name servers:</p>
<ul>
<li><p>Belong to <strong>Google</strong></p>
</li>
<li><p>Contain the <strong>actual DNS records</strong></p>
</li>
<li><p>Know the real IP addresses</p>
</li>
</ul>
<p>Key idea:</p>
<blockquote>
<p>Authoritative servers give <strong>final answers</strong>.</p>
</blockquote>
<hr />
<h2 id="heading-what-ns-records-represent-important">What NS Records Represent (Important)</h2>
<p>NS (Name Server) records say:</p>
<blockquote>
<p>“These servers are responsible for this domain.”</p>
</blockquote>
<p>Why NS records matter:</p>
<ul>
<li><p>They define <strong>authority</strong></p>
</li>
<li><p>They enable delegation</p>
</li>
<li><p>They make DNS distributed</p>
</li>
</ul>
<p>Without NS records, DNS cannot scale globally.</p>
<hr />
<h2 id="heading-understanding-dig-googlecomhttpgooglecom-full-dns-resolution">Understanding <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> (Full DNS Resolution)</h2>
<p>Command:</p>
<pre><code class="lang-bash">dig google.com
</code></pre>
<p>What happens behind the scenes:</p>
<ol>
<li><p>Resolver asks root servers</p>
</li>
<li><p>Root points to <code>.com</code> servers</p>
</li>
<li><p><code>.com</code> points to Google’s authoritative servers</p>
</li>
<li><p>Authoritative server returns the IP address</p>
</li>
</ol>
<p><img src="https://miro.medium.com/1%2AgoSb1oow5UBNF3KkzvOX8A.png" alt="Image" /></p>
<p><img src="https://assets.bytebytego.com/diagrams/0176-dns-look-up.png" alt="Image" /></p>
<p><img src="https://www.researchgate.net/publication/330006223/figure/fig1/AS%3A709642057445377%401546203259697/Domain-resolution-process-with-a-recursive-resolver.ppm" alt="Image" /></p>
<p><code>dig</code> shows you the <strong>final answer</strong>, but the resolver already did the full journey.</p>
<hr />
<h2 id="heading-recursive-resolver-the-hidden-worker">Recursive Resolver (The Hidden Worker)</h2>
<p>Your system uses a <strong>recursive resolver</strong> (ISP, router, or public DNS).</p>
<p>Its job:</p>
<ul>
<li><p>Perform all DNS steps for you</p>
</li>
<li><p>Cache results</p>
</li>
<li><p>Return the IP quickly</p>
</li>
</ul>
<p>You rarely see it, but it does most of the work.</p>
<hr />
<h2 id="heading-mapping-dig-commands-to-dns-lookup-stages">Mapping <code>dig</code> Commands to DNS Lookup Stages</h2>
<p><img src="https://miro.medium.com/v2/resize%3Afit%3A1268/1%2AXqr7YdkgKF-MGr0jKGTpMg.jpeg" alt="Image" /></p>
<p><img src="https://miro.medium.com/0%2AZsNeyyEN9O6-ZKC4" alt="Image" /></p>
<p><img src="https://miro.medium.com/1%2A-kCFoSB3-pMwajK6LTJY6Q.jpeg" alt="Image" /></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>DNS Layer</td></tr>
</thead>
<tbody>
<tr>
<td><code>dig . NS</code></td><td>Root servers</td></tr>
<tr>
<td><code>dig com NS</code></td><td>TLD servers</td></tr>
<tr>
<td><code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code></td><td>Authoritative servers</td></tr>
<tr>
<td><code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a></td><td>Final resolution</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-connecting-this-to-browser-requests">Connecting This to Browser Requests</h2>
<p>When you type <a target="_blank" href="https://google.com"><code>https://google.com</code></a>:</p>
<ol>
<li><p>Browser asks the OS for IP</p>
</li>
<li><p>OS asks recursive resolver</p>
</li>
<li><p>DNS resolution happens</p>
</li>
<li><p>Browser connects to the IP</p>
</li>
<li><p>HTTP request starts</p>
</li>
</ol>
<p>DNS <strong>always comes before HTTP</strong>.</p>
<hr />
<h2 id="heading-practical-takeaways">Practical Takeaways</h2>
<ul>
<li><p>DNS is a <strong>distributed lookup system</strong></p>
</li>
<li><p>Resolution happens in <strong>layers</strong></p>
</li>
<li><p><code>dig</code> helps you see each layer clearly</p>
</li>
<li><p>NS records define <strong>who is responsible</strong></p>
</li>
<li><p>Browsers hide this complexity, but it still happens</p>
</li>
</ul>
<hr />
<h2 id="heading-final-reassurance">Final Reassurance</h2>
<p>You do <strong>not</strong> need to remember:</p>
<ul>
<li><p>Server names</p>
</li>
<li><p>Output formats</p>
</li>
<li><p>All record types</p>
</li>
</ul>
<p>If you understand:</p>
<blockquote>
<p><strong>Root → TLD → Authoritative → IP</strong></p>
</blockquote>
<p>You already understand DNS better than most beginners.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Getting Started with cURL]]></title><description><![CDATA[Start With the Basics: What Is a Server?
A server is just a computer on the internet that:

Stores data

Runs applications

Responds when someone asks for something


When you open a website, your browser talks to a server and asks:

“Give me this pa...]]></description><link>https://blog.jainviral.com/curl-basic</link><guid isPermaLink="true">https://blog.jainviral.com/curl-basic</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Viral Jain]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:50:19 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-start-with-the-basics-what-is-a-server">Start With the Basics: What Is a Server?</h2>
<p>A <strong>server</strong> is just a computer on the internet that:</p>
<ul>
<li><p>Stores data</p>
</li>
<li><p>Runs applications</p>
</li>
<li><p>Responds when someone asks for something</p>
</li>
</ul>
<p>When you open a website, <strong>your browser talks to a server</strong> and asks:</p>
<blockquote>
<p>“Give me this page”</p>
</blockquote>
<p>The server replies with data.</p>
<p>This “talking” happens using <strong>HTTP requests and responses</strong>.</p>
<hr />
<h2 id="heading-what-is-curl-very-simple">What Is cURL? (Very Simple)</h2>
<p><strong>cURL is a tool that lets you talk to a server from the terminal.</strong></p>
<p>Instead of using a browser:</p>
<ul>
<li><p>You type a command</p>
</li>
<li><p>cURL sends a request to a server</p>
</li>
<li><p>The server sends a response</p>
</li>
<li><p>cURL shows you the result</p>
</li>
</ul>
<p>In one line:</p>
<blockquote>
<p><strong>cURL = a way to send HTTP requests without a browser</strong></p>
</blockquote>
<hr />
<h2 id="heading-why-programmers-need-curl">Why Programmers Need cURL</h2>
<p>Programmers use cURL to:</p>
<ul>
<li><p>Test APIs</p>
</li>
<li><p>Check if a server is working</p>
</li>
<li><p>Send requests without opening a browser</p>
</li>
<li><p>Debug backend issues</p>
</li>
<li><p>Learn how HTTP really works</p>
</li>
</ul>
<p>cURL is especially useful in:</p>
<ul>
<li><p>Backend development</p>
</li>
<li><p>API testing</p>
</li>
<li><p>DevOps and server work</p>
</li>
</ul>
<hr />
<h2 id="heading-where-curl-fits-big-picture">Where cURL Fits (Big Picture)</h2>
<p><img src="https://media2.dev.to/dynamic/image/width%3D800%2Cheight%3D%2Cfit%3Dscale-down%2Cgravity%3Dauto%2Cformat%3Dauto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm4061u6jlu03xspsnnmh.png" alt="Image" /></p>
<p><img src="https://www.twilio.com/content/dam/twilio-com/global/en/blog/legacy/2022/http-methods-requests-curl/HTTP_Request_Flow_1.png" alt="Image" /></p>
<p><img src="https://everything.curl.dev/internals/slide-libcurl-backends.jpg" alt="Image" /></p>
<p>Browser and cURL both:</p>
<ul>
<li><p>Send requests</p>
</li>
<li><p>Receive responses</p>
</li>
</ul>
<p>Difference:</p>
<ul>
<li><p>Browser shows a webpage</p>
</li>
<li><p>cURL shows <strong>raw data</strong></p>
</li>
</ul>
<hr />
<h2 id="heading-making-your-first-curl-request">Making Your First cURL Request</h2>
<p>Let’s start with the simplest possible example.</p>
<h3 id="heading-command">Command</h3>
<pre><code class="lang-bash">curl https://example.com
</code></pre>
<p>What happens:</p>
<ul>
<li><p>cURL sends a <strong>GET request</strong></p>
</li>
<li><p>Server sends back HTML</p>
</li>
<li><p>cURL prints it in the terminal</p>
</li>
</ul>
<p>You just fetched a webpage <strong>without a browser</strong>.</p>
<hr />
<h2 id="heading-what-is-actually-happening-here">What Is Actually Happening Here?</h2>
<p>Behind the scenes:</p>
<ol>
<li><p>cURL → “Hey server, give me this page”</p>
</li>
<li><p>Server → “Here is the data”</p>
</li>
<li><p>cURL → Displays the response</p>
</li>
</ol>
<p>This is the core idea of cURL.</p>
<hr />
<h2 id="heading-understanding-request-and-response">Understanding Request and Response</h2>
<h3 id="heading-request-what-you-send">Request (What You Send)</h3>
<p>Includes:</p>
<ul>
<li><p>Method (GET, POST)</p>
</li>
<li><p>URL</p>
</li>
<li><p>Optional data</p>
</li>
</ul>
<p>Example:</p>
<blockquote>
<p>“GET /users”</p>
</blockquote>
<h3 id="heading-response-what-you-get-back">Response (What You Get Back)</h3>
<p>Includes:</p>
<ul>
<li><p>Status code (200, 404, etc.)</p>
</li>
<li><p>Data (HTML, JSON, text)</p>
</li>
</ul>
<hr />
<h2 id="heading-basic-http-request-amp-response-structure">Basic HTTP Request &amp; Response Structure</h2>
<p><img src="https://mdn.github.io/shared-assets/images/diagrams/http/messages/http-2-connection.png" alt="Image" /></p>
<p><img src="https://personal.ntu.edu.sg/ehchua/programming/webprogramming/images/HTTP_ResponseMessageExample.png" alt="Image" /></p>
<p><img src="https://www.researchgate.net/publication/369358390/figure/fig1/AS%3A11431281127810255%401679180216268/HTTP-request-and-response-flow.png" alt="Image" /></p>
<p>You don’t need to memorize this yet. Just know:</p>
<ul>
<li><p>Request → ask</p>
</li>
<li><p>Response → answer</p>
</li>
</ul>
<hr />
<h2 id="heading-using-curl-to-talk-to-apis">Using cURL to Talk to APIs</h2>
<p>APIs usually return <strong>JSON</strong>, not HTML.</p>
<p>Example:</p>
<pre><code class="lang-bash">curl https://api.example.com/users
</code></pre>
<p>Possible response:</p>
<pre><code class="lang-json">[
  { <span class="hljs-attr">"id"</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">"name"</span>: <span class="hljs-string">"John"</span> },
  { <span class="hljs-attr">"id"</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Jane"</span> }
]
</code></pre>
<p>This is how developers <strong>talk to APIs directly</strong>.</p>
<hr />
<h2 id="heading-get-and-post-only-the-basics">GET and POST (Only the Basics)</h2>
<h3 id="heading-get-asking-for-data">GET – Asking for Data</h3>
<pre><code class="lang-bash">curl https://api.example.com/users
</code></pre>
<p>Use GET when:</p>
<ul>
<li><p>You want to <strong>fetch data</strong></p>
</li>
<li><p>You are not changing anything</p>
</li>
</ul>
<hr />
<h3 id="heading-post-sending-data">POST – Sending Data</h3>
<pre><code class="lang-bash">curl -X POST https://api.example.com/users
</code></pre>
<p>Use POST when:</p>
<ul>
<li><p>You want to <strong>send data</strong></p>
</li>
<li><p>You want to <strong>create something</strong></p>
</li>
</ul>
<p>Details can come later. For now:</p>
<ul>
<li><p>GET = get</p>
</li>
<li><p>POST = send</p>
</li>
</ul>
<hr />
<h2 id="heading-browser-request-vs-curl-request-conceptual">Browser Request vs cURL Request (Conceptual)</h2>
<p><img src="https://miro.medium.com/v2/resize%3Afit%3A1400/1%2ASgkHt0DBnVFkazz3_eLRDw.png" alt="Image" /></p>
<p><img src="https://i.sstatic.net/9wKRX.png" alt="Image" /></p>
<p><img src="https://crawlbase.com/blog/how-to-send-get-requests-with-curl/curl-get-request-options.jpg" alt="Image" /></p>
<ul>
<li><p>Browser: automatic, visual</p>
</li>
<li><p>cURL: manual, raw, honest</p>
</li>
</ul>
<p>cURL shows what the server <strong>really sends</strong>.</p>
<hr />
<h2 id="heading-common-mistakes-beginners-make">Common Mistakes Beginners Make</h2>
<ol>
<li><p>Expecting cURL to look like a webpage</p>
</li>
<li><p>Getting scared by raw JSON or HTML</p>
</li>
<li><p>Using too many flags too early</p>
</li>
<li><p>Confusing GET and POST</p>
</li>
<li><p>Thinking errors mean failure (they mean learning)</p>
</li>
</ol>
<p>Errors are normal with cURL.</p>
<hr />
<h2 id="heading-key-reassurance">Key Reassurance</h2>
<ul>
<li><p>You don’t need to remember commands</p>
</li>
<li><p>You don’t need to master flags</p>
</li>
<li><p>Understanding the <strong>idea</strong> is enough for now</p>
</li>
</ul>
<p>Once the idea is clear, commands become easy.</p>
<hr />
<h2 id="heading-final-takeaway">Final Takeaway</h2>
<p>cURL is not complicated.</p>
<p>It is simply:</p>
<blockquote>
<p><strong>A way to send messages to a server and read the reply</strong></p>
</blockquote>
<p>If you understand that, you are already on the right path.</p>
<hr />
]]></content:encoded></item></channel></rss>