<?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[buildwith_vibs]]></title><description><![CDATA[I would share all my learning of web development.]]></description><link>https://vibhavaribellutagi.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 21 Jun 2026 09:54:47 GMT</lastBuildDate><atom:link href="https://vibhavaribellutagi.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The magic of call(), apply(), bind()]]></title><description><![CDATA[If you ever worked with javascript, you would have encountered with a famous yet confusing keyword "this". In this blog, we will explore how "this" works, and more about call(), apply() and bind() met]]></description><link>https://vibhavaribellutagi.hashnode.dev/the-magic-of-call-apply-bind</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/the-magic-of-call-apply-bind</guid><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Sat, 18 Apr 2026 11:15:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/639c7096052fc36d4a8f3780/2a416f7b-0cca-49d2-977d-5be8e3bde99d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you ever worked with javascript, you would have encountered with a famous yet confusing keyword "this". In this blog, we will explore how "this" works, and more about call(), apply() and bind() methods</p>
<h3>What <code>this</code> means in JavaScript</h3>
<p><code>this</code> keyword refers the context where a piece of code runs, might be in function's body or a object. The golden rule that explains everything about <code>this</code> depends on how a function is called, not where its defined but how its invoked.</p>
<p>When a regular function is invoked as a method of an object, <code>this</code> points to that object. When invoked as a standalone function (not attached to an object: <code>func()</code>), <code>this</code> typically refers to the global object (in non-strict mode) or <code>undefined</code> (in strict mode).</p>
<h3><code>this</code> inside a regular function</h3>
<pre><code class="language-javascript">function showThis() {
  console.log(this);
}

showThis();
</code></pre>
<h4>How it’s invoked</h4>
<ul>
<li>Called as a <strong>plain function</strong>: <code>showThis()</code></li>
</ul>
<h4>What <code>this</code> is</h4>
<ul>
<li><p>In <strong>non-strict mode (browser)</strong> → <code>this</code> = <code>window</code></p>
</li>
<li><p>In <strong>strict mode</strong> → <code>this</code> = <code>undefined</code></p>
</li>
<li><p>In <strong>Node.js</strong> → <code>this</code> = <code>global</code> (or <code>undefined</code> in strict mode)</p>
</li>
</ul>
<p>👉 Key point: <code>this</code> depends on <strong>how the function is called</strong>, not where it’s defined.</p>
<hr />
<h3><code>this</code> inside an object method</h3>
<pre><code class="language-javascript">const user = {
  name: "Alice",
  greet: function () {
    console.log(this.name);
  }
};

user.greet();
</code></pre>
<h4>How it’s invoked</h4>
<ul>
<li>Called as a <strong>method of the object</strong>: <code>user.greet()</code></li>
</ul>
<h4>What <code>this</code> is</h4>
<ul>
<li><p><code>this</code> = the object before the dot → <code>user</code></p>
</li>
<li><p>So <code>this.name</code> → <code>"Alice"</code></p>
</li>
</ul>
<p>👉 Key point: When a function is called as a <strong>method</strong>, <code>this</code> refers to the <strong>owning object</strong>.</p>
<h3><code>call</code>, <code>apply</code>, and <code>bind</code> in JavaScript</h3>
<p>All three do the same core thing: <strong>let you borrow a function and control what</strong> <code>this</code> <strong>refers to inside it.</strong> The difference is <em>how</em> and <em>when</em> the function runs.</p>
<hr />
<h4>The Setup — why do we need them?</h4>
<pre><code class="language-js">const person = { name: "Alice" };

function greet(greeting, punctuation) {
  console.log(`\({greeting}, \){this.name}${punctuation}`);
}
</code></pre>
<p><code>greet</code> uses <code>this.name</code>, but <code>this</code> isn't set. These three methods let us <em>inject</em> <code>person</code> as <code>this</code>.</p>
<hr />
<h4>1. <code>call</code> — borrow &amp; run immediately, args comma-separated</h4>
<pre><code class="language-js">greet.call(person, "Hello", "!");
// → "Hello, Alice!"
</code></pre>
<p><strong>Syntax:</strong> <code>fn.call(thisArg, arg1, arg2, ...)</code></p>
<p>🧠 <strong>Mental model:</strong> Think of it as a <strong>phone call</strong> — you dial (call) someone right now, and you pass each thing you want to say one at a time.</p>
<hr />
<h4>2. <code>apply</code> — borrow &amp; run immediately, args as an array</h4>
<pre><code class="language-js">greet.apply(person, ["Hey", "?"]);
// → "Hey, Alice?"
</code></pre>
<p><strong>Syntax:</strong> <code>fn.apply(thisArg, [arg1, arg2, ...])</code></p>
<p>🧠 <strong>Mental model:</strong> Same as <code>call</code>, but you <strong>apply</strong> a whole list of arguments at once — like handing someone a <em>sheet of paper</em> with everything on it, instead of saying each thing one by one.</p>
<hr />
<h4>3. <code>bind</code> — borrow &amp; get back a <em>new</em> function (doesn't run yet)</h4>
<pre><code class="language-js">const greetAlice = greet.bind(person, "Hi");

// ... later ...
greetAlice("!!");
// → "Hi, Alice!!"
</code></pre>
<p><strong>Syntax:</strong> <code>const newFn = fn.bind(thisArg, arg1, ...)</code></p>
<p><code>bind</code> lets you <strong>pre-fill</strong> some arguments too (called <em>partial application</em>).</p>
<p>🧠 <strong>Mental model:</strong> Think of <code>bind</code> as a <strong>sticky note</strong> — you write down who <code>this</code> is and pre-fill some args, then stick it on the function. The function doesn't run until <em>you</em> decide to call it later.</p>
<h4>Side-by-side comparison</h4>
<table>
<thead>
<tr>
<th></th>
<th><code>call</code></th>
<th><code>apply</code></th>
<th><code>bind</code></th>
</tr>
</thead>
<tbody><tr>
<td>Runs immediately?</td>
<td>✅ Yes</td>
<td>✅ Yes</td>
<td>❌ No — returns new fn</td>
</tr>
<tr>
<td>How args are passed</td>
<td>One by one</td>
<td>As an array</td>
<td>One by one (pre-filled)</td>
</tr>
<tr>
<td>Returns</td>
<td>Result of fn</td>
<td>Result of fn</td>
<td>A new function</td>
</tr>
</tbody></table>
<h3>The one-line summary for each</h3>
<ul>
<li><p><code>call</code> → <em>"Run this function NOW, with this</em> <code>this</code><em>, passing args separately"</em></p>
</li>
<li><p><code>apply</code> → <em>"Run this function NOW, with this</em> <code>this</code><em>, passing args as an array"</em></p>
</li>
<li><p><code>bind</code> → <em>"Give me a new function with</em> <code>this</code> <em>(and maybe some args) locked in — I'll call it later"</em></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Control Flow in JavaScript: If, Else, and Switch Explained]]></title><description><![CDATA[Every program you've ever used makes decisions. Your music app skips explicit songs when parental controls are on. Your bank app blocks a transaction if your balance is too low. Your favorite game say]]></description><link>https://vibhavaribellutagi.hashnode.dev/control-flow-in-javascript-if-else-and-switch-explained</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/control-flow-in-javascript-if-else-and-switch-explained</guid><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Sat, 18 Apr 2026 10:07:51 GMT</pubDate><content:encoded><![CDATA[<blockquote>
<p>Every program you've ever used makes decisions. Your music app skips explicit songs when parental controls are on. Your bank app blocks a transaction if your balance is too low. Your favorite game says "Game Over" when your health hits zero. All of this happens because of <strong>control flow</strong> — and in this post, you'll learn exactly how it works in JavaScript.</p>
</blockquote>
<hr />
<h2>1. What Is Control Flow?</h2>
<p>Imagine you're getting ready in the morning. You don't just blindly follow the same routine every day — you <em>make decisions</em>:</p>
<ul>
<li><p><strong>If</strong> it's raining, grab an umbrella.</p>
</li>
<li><p><strong>Otherwise</strong>, leave it at home.</p>
</li>
<li><p><strong>If</strong> you're running late, skip breakfast.</p>
</li>
</ul>
<p>This is exactly what control flow means in programming. By default, JavaScript reads and executes your code <strong>line by line, top to bottom</strong>. But with control flow statements, you can tell JavaScript:</p>
<blockquote>
<p><em>"Don't just run everything blindly — check a condition first, then decide what to do."</em></p>
</blockquote>
<p>Control flow lets your program <strong>branch</strong> into different paths based on conditions. The three main tools for this in JavaScript are:</p>
<ul>
<li><p><code>if</code> statements</p>
</li>
<li><p><code>if-else</code> and <code>else if</code> ladders</p>
</li>
<li><p><code>switch</code> statements</p>
</li>
</ul>
<p>Let's explore each one.</p>
<hr />
<h2>2. The <code>if</code> Statement</h2>
<p>The <code>if</code> statement is the simplest form of decision-making. It says: <strong>"Only run this block of code IF the condition is true."</strong></p>
<h3>Syntax</h3>
<p>js</p>
<pre><code class="language-js">if (condition) {
  // code to run if condition is true
}
</code></pre>
<p>If the condition is <code>false</code>, JavaScript simply skips the block entirely and moves on.</p>
<h3>Real-Life Example: Checking Age for Voting</h3>
<pre><code class="language-javascript">let age = 20;

if (age &gt;= 18) {
  console.log("You are eligible to vote.");
}

// Output: You are eligible to vote.
</code></pre>
<p><strong>Step-by-step walkthrough:</strong></p>
<ol>
<li><p>JavaScript reads <code>age &gt;= 18</code></p>
</li>
<li><p>It checks: is <code>20 &gt;= 18</code>? → <strong>Yes, true</strong></p>
</li>
<li><p>So it enters the block and prints the message</p>
</li>
</ol>
<p>Now try with a different value:</p>
<pre><code class="language-javascript">let age = 15;

if (age &gt;= 18) {
  console.log("You are eligible to vote.");
}

// No output — the block is skipped
</code></pre>
<p>Since <code>15 &gt;= 18</code> is <code>false</code>, JavaScript quietly skips the entire <code>if</code> block. Nothing happens.</p>
<h3>Key Takeaway</h3>
<blockquote>
<p>Use <code>if</code> when you only care about what happens <strong>when the condition is true</strong>, and want to do nothing otherwise.</p>
</blockquote>
<hr />
<h2>3. The <code>if-else</code> Statement</h2>
<p>What if you want to handle <strong>both</strong> cases — when the condition is true <em>and</em> when it's false? That's where <code>else</code> comes in.</p>
<h3>Syntax</h3>
<p>js</p>
<pre><code class="language-js">if (condition) {
  // runs if condition is true
} else {
  // runs if condition is false
}
</code></pre>
<h3>Real-Life Example: Pass or Fail</h3>
<p>js</p>
<pre><code class="language-js">let marks = 45;

if (marks &gt;= 50) {
  console.log("Result: Pass ✅");
} else {
  console.log("Result: Fail ❌");
}

// Output: Result: Fail ❌
</code></pre>
<p><strong>Step-by-step walkthrough:</strong></p>
<ol>
<li><p>JavaScript checks: is <code>45 &gt;= 50</code>? → <strong>No, false</strong></p>
</li>
<li><p>It skips the <code>if</code> block</p>
</li>
<li><p>It falls into the <code>else</code> block and prints <code>"Result: Fail ❌"</code></p>
</li>
</ol>
<p>Only <strong>one</strong> of the two blocks will ever run — never both.</p>
<h3>Another Example: Even or Odd</h3>
<p>js</p>
<pre><code class="language-js">let number = 7;

if (number % 2 === 0) {
  console.log(number + " is Even");
} else {
  console.log(number + " is Odd");
}

// Output: 7 is Odd
</code></pre>
<p>The <code>%</code> operator gives the <strong>remainder</strong> after division. <code>7 % 2</code> gives <code>1</code>, which is not <code>0</code>, so the <code>else</code> block runs.</p>
<h3>Key Takeaway</h3>
<blockquote>
<p>Use <code>if-else</code> when there are exactly <strong>two possible outcomes</strong> — the condition is either true or false.</p>
</blockquote>
<hr />
<h2>4. The <code>else if</code> Ladder</h2>
<p>Real life rarely gives us just two choices. What if you need to check <strong>multiple conditions</strong> in sequence? That's where <code>else if</code> comes in — it lets you build a <strong>ladder</strong> of conditions.</p>
<h3>Syntax</h3>
<p>js</p>
<pre><code class="language-js">if (condition1) {
  // runs if condition1 is true
} else if (condition2) {
  // runs if condition2 is true
} else if (condition3) {
  // runs if condition3 is true
} else {
  // runs if none of the above are true
}
</code></pre>
<p>JavaScript checks each condition <strong>from top to bottom</strong> and stops as soon as it finds one that's true.</p>
<h3>Real-Life Example: Grade Calculator</h3>
<p>js</p>
<pre><code class="language-js">let marks = 72;

if (marks &gt;= 90) {
  console.log("Grade: A");
} else if (marks &gt;= 75) {
  console.log("Grade: B");
} else if (marks &gt;= 60) {
  console.log("Grade: C");
} else if (marks &gt;= 40) {
  console.log("Grade: D");
} else {
  console.log("Grade: F — Please retake the exam");
}

// Output: Grade: C
</code></pre>
<p><strong>Step-by-step walkthrough:</strong></p>
<ol>
<li><p>Is <code>72 &gt;= 90</code>? → No. Move on.</p>
</li>
<li><p>Is <code>72 &gt;= 75</code>? → No. Move on.</p>
</li>
<li><p>Is <code>72 &gt;= 60</code>? → <strong>Yes!</strong> → Print <code>"Grade: C"</code> and <strong>stop</strong>.</p>
</li>
</ol>
<p>JavaScript never even checks the <code>&gt;= 40</code> condition because it already found a match.</p>
<h3>Real-Life Example: Time of Day Greeting</h3>
<p>js</p>
<pre><code class="language-js">let hour = 14; // 2 PM in 24-hour format

if (hour &lt; 12) {
  console.log("Good Morning! ☀️");
} else if (hour &lt; 17) {
  console.log("Good Afternoon! 🌤️");
} else if (hour &lt; 21) {
  console.log("Good Evening! 🌆");
} else {
  console.log("Good Night! 🌙");
}

// Output: Good Afternoon! 🌤️
</code></pre>
<h3>Key Takeaway</h3>
<blockquote>
<p>Use <code>else if</code> when you have <strong>3 or more possible outcomes</strong> that depend on a single variable being checked against different ranges or values.</p>
</blockquote>
<hr />
<h2>5. The <code>switch</code> Statement</h2>
<p>The <code>switch</code> statement is a cleaner alternative when you're comparing <strong>one variable against many specific values</strong>. Instead of writing a long chain of <code>else if</code>, <code>switch</code> lays all the options out neatly.</p>
<h3>Syntax</h3>
<p>js</p>
<pre><code class="language-js">switch (expression) {
  case value1:
    // code for value1
    break;
  case value2:
    // code for value2
    break;
  case value3:
    // code for value3
    break;
  default:
    // code if no case matches
}
</code></pre>
<h3>Real-Life Example: Day of the Week</h3>
<p>js</p>
<pre><code class="language-js">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;
  case 6:
    console.log("Saturday");
    break;
  case 7:
    console.log("Sunday");
    break;
  default:
    console.log("Invalid day number");
}

// Output: Wednesday
</code></pre>
<p><strong>Step-by-step walkthrough:</strong></p>
<ol>
<li><p>JavaScript evaluates <code>day</code> → it's <code>3</code></p>
</li>
<li><p>It checks <code>case 1</code> → not a match</p>
</li>
<li><p>It checks <code>case 2</code> → not a match</p>
</li>
<li><p>It checks <code>case 3</code> → <strong>match!</strong> → prints <code>"Wednesday"</code></p>
</li>
<li><p>It hits <code>break</code> → exits the switch block immediately</p>
</li>
</ol>
<h3>🔴 Understanding <code>break</code> — This Is Critical</h3>
<p>The <code>break</code> keyword tells JavaScript: <strong>"You're done. Exit the switch now."</strong></p>
<p>What happens if you forget it? JavaScript will <strong>fall through</strong> — it keeps running every case below the matched one, even if they don't match. This is called <strong>fallthrough behavior</strong> and is a common source of bugs.</p>
<pre><code class="language-javascript">let day = 3;

switch (day) {
  case 3:
    console.log("Wednesday");
    // ⚠️ No break here!
  case 4:
    console.log("Thursday");
    // ⚠️ No break here!
  case 5:
    console.log("Friday");
    break;
}

// Output:
// Wednesday
// Thursday
// Friday
</code></pre>
<p>Even though <code>day</code> is <code>3</code>, all three cases ran because there was no <code>break</code> to stop the flow. <strong>Always add</strong> <code>break</code> unless you deliberately want fallthrough.</p>
<h3>Using Fallthrough Intentionally</h3>
<p>Sometimes fallthrough is actually useful — when multiple cases should share the same outcome:</p>
<p>js</p>
<pre><code class="language-js">let day = "Saturday";

switch (day) {
  case "Saturday":
  case "Sunday":
    console.log("It's the weekend! 🎉");
    break;
  case "Monday":
  case "Tuesday":
  case "Wednesday":
  case "Thursday":
  case "Friday":
    console.log("It's a weekday. 💼");
    break;
  default:
    console.log("Unknown day");
}

// Output: It's the weekend! 🎉
</code></pre>
<p>Here, both <code>"Saturday"</code> and <code>"Sunday"</code> fall through to the same <code>console.log</code> — this is clean, intentional, and readable.</p>
<h3>The <code>default</code> Case</h3>
<p><code>default</code> is like the <code>else</code> in an <code>if-else</code> — it runs when <strong>no case matches</strong>. It's optional, but always a good idea to include it.</p>
<p>js</p>
<pre><code class="language-js">let trafficLight = "purple";

switch (trafficLight) {
  case "red":
    console.log("Stop 🔴");
    break;
  case "yellow":
    console.log("Slow down 🟡");
    break;
  case "green":
    console.log("Go! 🟢");
    break;
  default:
    console.log("Unknown signal — proceed with caution");
}

// Output: Unknown signal — proceed with caution
</code></pre>
<h3>Key Takeaway</h3>
<blockquote>
<p>Use <code>switch</code> when you're matching <strong>one variable</strong> against <strong>multiple exact values</strong>, and each case has a distinct action. Always use <code>break</code> unless you intentionally want fallthrough.</p>
</blockquote>
<hr />
<h2>6. When to Use <code>switch</code> vs <code>if-else</code></h2>
<p>This is one of the most common questions beginners ask. Here's a clear breakdown:</p>
<table>
<thead>
<tr>
<th>Scenario</th>
<th>Best Choice</th>
</tr>
</thead>
<tbody><tr>
<td>Checking a range of values (<code>&gt;= 60</code>, <code>&lt; 100</code>)</td>
<td><code>if-else</code></td>
</tr>
<tr>
<td>Checking complex conditions (<code>age &gt; 18 &amp;&amp; hasID</code>)</td>
<td><code>if-else</code></td>
</tr>
<tr>
<td>Matching one variable to many exact values</td>
<td><code>switch</code></td>
</tr>
<tr>
<td>Two possible outcomes</td>
<td><code>if-else</code></td>
</tr>
<tr>
<td>Many named cases (days, months, menu options)</td>
<td><code>switch</code></td>
</tr>
<tr>
<td>Conditions involve different variables</td>
<td><code>if-else</code></td>
</tr>
</tbody></table>
<h3>Side-by-Side Comparison</h3>
<p>Here's the same logic written both ways — you decide which is cleaner:</p>
<p><strong>Using</strong> <code>if-else</code><strong>:</strong></p>
<p>js</p>
<pre><code class="language-js">let fruit = "mango";

if (fruit === "apple") {
  console.log("🍎 Apple selected");
} else if (fruit === "banana") {
  console.log("🍌 Banana selected");
} else if (fruit === "mango") {
  console.log("🥭 Mango selected");
} else {
  console.log("Unknown fruit");
}
</code></pre>
<p><strong>Using</strong> <code>switch</code><strong>:</strong></p>
<p>js</p>
<pre><code class="language-js">let fruit = "mango";

switch (fruit) {
  case "apple":
    console.log("🍎 Apple selected");
    break;
  case "banana":
    console.log("🍌 Banana selected");
    break;
  case "mango":
    console.log("🥭 Mango selected");
    break;
  default:
    console.log("Unknown fruit");
}
</code></pre>
<p>Both produce the same output. But when you have 10+ specific values to check, <code>switch</code> wins on readability every time.</p>
<h3>The Golden Rule</h3>
<ul>
<li><p>If your conditions involve <strong>ranges, inequalities, or multiple variables</strong> → use <code>if-else</code></p>
</li>
<li><p>If you're matching <strong>one thing to a list of exact values</strong> → use <code>switch</code></p>
</li>
</ul>
<hr />
<h2>Putting It All Together</h2>
<p>Here's a mini program that uses everything you've learned:</p>
<p>js</p>
<pre><code class="language-js">let studentMarks = 68;
let studentAge = 17;

// Check eligibility
if (studentAge &lt; 5) {
  console.log("Too young for school.");
} else if (studentAge &lt; 18) {
  console.log("School-going student.");
} else {
  console.log("Adult learner.");
}

// Assign grade using switch
let grade;

if (studentMarks &gt;= 90) {
  grade = "A";
} else if (studentMarks &gt;= 75) {
  grade = "B";
} else if (studentMarks &gt;= 60) {
  grade = "C";
} else {
  grade = "F";
}

switch (grade) {
  case "A":
    console.log("Outstanding performance! 🌟");
    break;
  case "B":
    console.log("Great job! Keep it up. 👍");
    break;
  case "C":
    console.log("Good effort. Room to improve. 📈");
    break;
  default:
    console.log("Needs significant improvement. 📚");
}

// Output:
// School-going student.
// Good effort. Room to improve. 📈
</code></pre>
<hr />
<h2>Summary</h2>
<p>Here's everything you covered in one quick reference:</p>
<table>
<thead>
<tr>
<th>Statement</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td><code>if</code></td>
<td>Run code only when condition is true</td>
</tr>
<tr>
<td><code>if-else</code></td>
<td>Handle true/false — two outcomes</td>
</tr>
<tr>
<td><code>else if</code></td>
<td>Handle multiple conditions in order</td>
</tr>
<tr>
<td><code>switch</code></td>
<td>Match one value against many exact cases</td>
</tr>
<tr>
<td><code>break</code></td>
<td>Exit the switch block after a match</td>
</tr>
<tr>
<td><code>default</code></td>
<td>Fallback if no case matches</td>
</tr>
</tbody></table>
]]></content:encoded></item><item><title><![CDATA[Global vs GlobalThis]]></title><description><![CDATA[TL;DR
Every JavaScript environment has a global object, but it has different names:

window in browsers

global in Node.js,

and self in Web Workers.


This forced developers to write messy environmen]]></description><link>https://vibhavaribellutagi.hashnode.dev/global-vs-globalthis</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/global-vs-globalthis</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[globalobjects]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Sun, 08 Mar 2026 13:12:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/639c7096052fc36d4a8f3780/80a92164-2279-4cea-9089-b72f2eb1f099.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>TL;DR</strong></p>
<p>Every JavaScript environment has a global object, but it has different names:</p>
<ol>
<li><p><code>window</code> in browsers</p>
</li>
<li><p><code>global</code> in Node.js,</p>
</li>
<li><p>and <code>self</code> in Web Workers.</p>
</li>
</ol>
<p>This forced developers to write messy environment-detection code just to access it reliably. <code>globalThis</code>, introduced in ES2020, solves this by providing one universal name that works everywhere. Use it when you need cross-environment compatibility - but use it sparingly, as polluting the global scope leads to bugs and messy code.</p>
<h2>What is scope?</h2>
<p>Almost every modern programming language has the concept of scope, and JavaScript is no exception. At its core, scope answers simple question:</p>
<div>
<div>❔</div>
<div>Where in your code can this variable be seen and used?</div>
</div>

<p>Think of a code which has 10000 lines, if a variable defined once, is accessible throughout the huge code, is it a good practice?<br />The scope here sets the boundary of the variables - when you create a variable, it's not always everywhere, scope defines the boundaries of where that variable lives and who can access it.</p>
<h4>Global &amp; Function Scope</h4>
<pre><code class="language-javascript">let globalVar = 'This is global variable';

function localScope() {
  let localVar = 'This is local variable';

  console.log('Inside function: ', localVar);  // ✅ This is local variable
  console.log('Inside function: ', globalVar); // ✅ This is global variable
}

localScope();

console.log('Outside function: ', globalVar); // ✅ This is global variable
console.log('Outside function: ', localVar);  // ❌ ReferenceError: localVar is not defined
</code></pre>
<p>Global Scope - visible <em>everywhere</em> in your code<br />Function Scope - visible only inside that function</p>
<h4>Block Scope</h4>
<p>Block Scope - visible only <em>inside that block</em> <code>{ }</code></p>
<pre><code class="language-javascript">let localFlag = true;

if (localFlag) {
  let blockVar = 'This is in if block';
  console.log('Inside block: ', blockVar); // ✅ This is in if block
}

console.log('Outside block: ', blockVar); // ❌ ReferenceError: blockVar is not defined
</code></pre>
<h2>What is the Global Object?</h2>
<p>We just saw that variables declared outside any function are accessible everywhere. But have you ever wondered what 'everywhere' actually means in JavaScript? There's a container that holds all of these global variables, and it's called the global object.</p>
<p>In each JavaScript environment, there's always a global object defined. The context of global's interface depends on the execution context in which the script is running -</p>
<table>
<thead>
<tr>
<th>Enviornment</th>
<th>Global Object</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>Browser</td>
<td>Window</td>
<td></td>
</tr>
<tr>
<td>Node.js</td>
<td>global</td>
<td></td>
</tr>
<tr>
<td>Web Workers</td>
<td>self</td>
<td>browser background threads</td>
</tr>
</tbody></table>
<h2>The Problem: global, window, self</h2>
<p>The real problem is this: the global object means the same thing in every JavaScript environment, but it goes by a different name in each one. To write code that worked everywhere, developers either required to write environment specific code or had to manually check which environment they were in:</p>
<pre><code class="language-javascript">function getGlobalObject() {
  if (typeof window !== 'undefined') return window;   // Browser
  if (typeof global !== 'undefined') return global;   // Node.js
  if (typeof self !== 'undefined') return self;       // Web Workers
  throw new Error('Unable to locate global object');  // Unknown environment
}

const globalObj = getGlobalObject();
</code></pre>
<p>This approach was error-prone. In strict mode, <code>this</code> is <code>undefined</code> instead of the global object, silently breaking the fallback. It was too much boilerplate just to do one simple thing , access the global object.</p>
<h2>What is globalThis and what problem does it solve?</h2>
<p>Remember that function we just wrote to detect the environment? <code>globalThis</code> makes it completely unnecessary. Introduced in ES2020, it gives JavaScript a single standardised way to access the global object, no environment checks, no fragile fallbacks. It just works, everywhere.</p>
<p><strong>Benefits of</strong> <code>globalThis</code><strong>:</strong></p>
<ol>
<li><p><strong>Easy Access</strong> - Available out of the box in every JavaScript environment. No imports, no setup, no configuration needed.</p>
</li>
<li><p><strong>Simplified Code</strong> - Replaces lengthy environment detection code with a single, consistent reference. What used to take 5 lines now takes one.</p>
</li>
<li><p><strong>Maintainable Code</strong> - Any developer, regardless of their background, immediately understands what <code>globalThis</code> refers to. No guessing, no environment-specific surprises.</p>
</li>
</ol>
<h2>How to Use globalThis?</h2>
<p><strong>Setting a global variable</strong></p>
<pre><code class="language-javascript">globalThis.myVar = 'Hello World';
console.log(globalThis.myVar); // Hello World
</code></pre>
<p><strong>Sharing data across modules</strong></p>
<pre><code class="language-javascript">// module-a.js
globalThis.config = { debug: true, version: '1.0.0' };

// module-b.js
console.log(globalThis.config.version); // 1.0.0
</code></pre>
<p><strong>Checking if a feature exists</strong></p>
<pre><code class="language-javascript">if (typeof globalThis.fetch !== 'undefined') {
  console.log('fetch is supported');
} else {
  console.log('fetch is not supported');
}
</code></pre>
<h4>Comparing with global</h4>
<pre><code class="language-javascript">// ❌ Before — complicated environment detection
function getGlobalObject() {
  if (typeof window !== 'undefined') return window;   // Browser
  if (typeof global !== 'undefined') return global;   // Node.js
  if (typeof self !== 'undefined') return self;       // Web Workers
  throw new Error('Unable to locate global object');  // Unknown environment
}

const globalObj = getGlobalObject();
globalObj.myVar = 42;
console.log(globalObj.myVar); // 42


// ✅ After — simple and universal
globalThis.myVar = 42;
console.log(globalThis.myVar); // 42
</code></pre>
<h2>When should you use it? (+ avoid polluting globals)</h2>
<p><code>globalThis</code> is powerful, but that doesn't mean you should reach for it often. Here's a simple rule:</p>
<blockquote>
<p>Use <code>globalThis</code> only when you genuinely need something to be accessible across your entire application and across different environments.</p>
</blockquote>
<p><strong>Good use cases:</strong></p>
<ul>
<li><p>Writing a library or utility that runs in both browser and Node.js</p>
</li>
<li><p>Feature detection across environments</p>
</li>
<li><p>Polyfilling missing features</p>
</li>
<li><p>Sharing configuration across modules</p>
</li>
</ul>
<p><strong>Avoid it when:</strong></p>
<ul>
<li><p>A regular variable or module export would do the job</p>
</li>
<li><p>You're tempted to use it just to avoid passing data around properly</p>
</li>
</ul>
<hr />
<h3>⚠️ Don't Pollute the Global Scope</h3>
<p>Every property you add to <code>globalThis</code> is available everywhere in your entire program. This sounds convenient but causes real problems:</p>
<p>javascript</p>
<pre><code class="language-javascript">// ❌ Bad — polluting the global scope
globalThis.username = 'Alice';
globalThis.fetchData = function() { ... };
globalThis.config = { debug: true };

// ✅ Good — keep things scoped with modules
export const username = 'Alice';
export function fetchData() { ... }
export const config = { debug: true };
</code></pre>
<p>Polluting globals leads to:</p>
<ul>
<li><p><strong>Name collisions</strong> : two files accidentally overwrite each other's variables</p>
</li>
<li><p><strong>Harder debugging</strong> : variables change from unexpected places</p>
</li>
<li><p><strong>Messy codebase</strong> : nothing is predictable</p>
</li>
</ul>
<h2>global vs globalThis</h2>
<table>
<thead>
<tr>
<th></th>
<th><code>global</code></th>
<th><code>globalThis</code></th>
</tr>
</thead>
<tbody><tr>
<td>Introduced</td>
<td>Node.js (early)</td>
<td>ES2020</td>
</tr>
<tr>
<td>Works in Browser</td>
<td>❌</td>
<td>✅</td>
</tr>
<tr>
<td>Works in Node.js</td>
<td>✅</td>
<td>✅</td>
</tr>
<tr>
<td>Works in Web Workers</td>
<td>❌</td>
<td>✅</td>
</tr>
<tr>
<td>Standardised</td>
<td>❌ Node-specific</td>
<td>✅ Official JS standard</td>
</tr>
<tr>
<td>Recommended</td>
<td>Only for Node.js specific code</td>
<td>Always preferred</td>
</tr>
</tbody></table>
<h3>Wrap up</h3>
<p>If you learnt something new about the global and globalThis concept in Javascript, share it with your friends and teammates :) Follow me for more content</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Operators: The Basics You Need to Know]]></title><description><![CDATA[Think about the last time you used a calculator. You typed in a number, hit a button: +, -, ×, ÷ - typed another number, and got a result. Simple as that.
JavaScript operators work exactly the same wa]]></description><link>https://vibhavaribellutagi.hashnode.dev/javascript-operators-the-basics-you-need-to-know</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/javascript-operators-the-basics-you-need-to-know</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Sun, 01 Mar 2026 17:20:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/639c7096052fc36d4a8f3780/3d8b6324-0c3c-4f15-8ed7-872b221b2f65.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Think about the last time you used a calculator. You typed in a number, hit a button: +, -, ×, ÷ - typed another number, and got a result. Simple as that.</p>
<p>JavaScript operators work exactly the same way. They sit between two values, do something with them, and give you back a result. The only difference? JavaScript's calculator is a lot smarter. It doesn't just do math - it compares things, makes decisions, and remembers values.</p>
<p>In this post, we'll use a calculator as our mental model to understand every type of operator in JavaScript. By the end, none of this will feel foreign, because it isn't.</p>
<hr />
<h2>What Are Operators?</h2>
<p>Pick up a basic calculator. It has two things: numbers and buttons. The numbers are your raw data. The buttons — +, -, =, % — are your <strong>operators</strong>.</p>
<p>An operator is a symbol that tells JavaScript to perform a specific action on one or more values. Those values are called <strong>operands</strong>. Press <code>5 + 3</code> on a calculator and you get <code>8</code>. In JavaScript, it's exactly the same:</p>
<pre><code class="language-javascript">let result = 5 + 3;
console.log(result); // 8
</code></pre>
<blockquote>
<p>🧮 <strong>Calculator Analogy:</strong> The numbers on the screen are your values. The buttons you press are your operators. Without the buttons, the numbers just sit there doing nothing.</p>
</blockquote>
<hr />
<h2>Arithmetic Operators (+, -, *, /, %)</h2>
<p>This is your calculator in its most basic form, standard mode. You have your four classic operations and one sneaky one that trips beginners up every time.</p>
<pre><code class="language-javascript">let a = 10;
let b = 3;

console.log(a + b);  // 13 → addition
console.log(a - b);  // 7  → subtraction
console.log(a * b);  // 30 → multiplication
console.log(a / b);  // 3.33 → division
console.log(a % b);  // 1  → remainder
</code></pre>
<p>The first four are obvious. But <code>%</code>? Most calculators have this button and most people never touch it. Here's the secret, it doesn't give you a percentage. It gives you the leftover remainder after a division.</p>
<blockquote>
<p>🧮 <strong>Calculator Analogy:</strong> Imagine dividing 10 sweets equally among 3 friends. Each gets 3 sweets. But you have <strong>1 left over</strong>. That leftover is exactly what <code>%</code> returns. <code>10 % 3 = 1</code>.</p>
</blockquote>
<p>Modulo is surprisingly useful in real code, checking if a number is even or odd, cycling through a list, building a clock that resets to zero, and much more.</p>
<hr />
<h2>Comparison Operators (==, ===, !=, &gt;, &lt;)</h2>
<p>Now imagine your calculator has a <strong>compare mode</strong>. Instead of calculating a result, it looks at two values and answers one question: true or false?</p>
<p>Is 10 greater than 5? <strong>True.</strong> Is 3 equal to 7? <strong>False.</strong> That's exactly what comparison operators do , they always return either <code>true</code> or <code>false</code>, nothing else.</p>
<pre><code class="language-js">console.log(10 &gt; 5);   // true
console.log(3 &lt; 1);    // false
console.log(5 != 3);   // true (they are NOT equal)
</code></pre>
<p>Now here's the part that confuses almost every beginner, <code>==</code> versus <code>===</code>. Two equal signs vs three.</p>
<blockquote>
<p>🧮 <strong>Calculator Analogy:</strong> Imagine you type <code>"5"</code> (as text) and <code>5</code> (as a number) into two calculators. They display the same thing on screen. <code>==</code> looks at the screen and says "same!" But <code>===</code> peeks inside the machine and says "one is text, one is a number , they're NOT the same."</p>
</blockquote>
<pre><code class="language-javascript">console.log("5" == 5);   // true  ← dangerous!
console.log("5" === 5);  // false ← correct and safe
</code></pre>
<p>As a rule of thumb, always use <code>===</code> in your code. It checks both the value and the type, making your comparisons reliable and bug-free.</p>
<hr />
<h2>Logical Operators (&amp;&amp;, ||, !)</h2>
<p>Your calculator can now compare. But what if you need to check <strong>two conditions at the same time</strong>? What if one condition being true is enough? What if you want to flip a result?</p>
<p>That's logic mode. Logical operators combine true/false values to make bigger decisions.</p>
<blockquote>
<p>🧮 <strong>Calculator Analogy:</strong> Think of a calculator that only turns on if you enter the right PIN <strong>AND</strong> it has battery. Both must be true. But a low-battery warning fires if the battery is low <strong>OR</strong> the charger is unplugged — either one triggers it. And <code>!</code> is the on/off toggle. It flips whatever state you're in.</p>
</blockquote>
<pre><code class="language-javascript">let hasBattery = true;
let isCharged  = false;

console.log(hasBattery &amp;&amp; isCharged);  // false → both must be true
console.log(hasBattery || isCharged);  // true  → at least one is true
console.log(!hasBattery);              // false → flips true to false
</code></pre>
<p>A simple way to remember them:</p>
<ul>
<li><p><code>&amp;&amp;</code> — strict bouncer. <strong>Everyone</strong> in the group must qualify.</p>
</li>
<li><p><code>||</code> — easy bouncer. <strong>Anyone</strong> qualifies, the whole group gets in.</p>
</li>
<li><p><code>!</code> — the invert button. Flips true to false, and false to true.</p>
</li>
</ul>
<hr />
<h2>Assignment Operators (=, +=, -=)</h2>
<p>Every calculator has a <strong>memory button</strong> , M+ to add to memory, MR to recall it. Assignment operators are JavaScript's memory system. They store values into variables and update them over time.</p>
<pre><code class="language-javascript">let score = 0;     // store 0 in memory

score += 10;       // same as: score = score + 10 → 10
score += 5;        // same as: score = score + 5  → 15
score -= 3;        // same as: score = score - 3  → 12

console.log(score); // 12
</code></pre>
<blockquote>
<p>🧮 <strong>Calculator Analogy:</strong> When you hit M+ on a calculator, you're not replacing what's in memory, you're <strong>adding to it</strong>. That running total in memory is exactly what <code>+=</code> does to a variable.</p>
</blockquote>
<p>The shorthand operators aren't just lazy shortcuts — they make your code more readable and less error-prone. <code>score += 10</code> says exactly what you mean in half the characters.</p>
<hr />
<h2>Putting It All Together</h2>
<p>Let's write a tiny score tracker that uses every operator we've covered, just like a real calculator uses all its modes together.</p>
<pre><code class="language-javascript">// Assignment: store starting values
let playerScore = 0;
let targetScore = 50;
let lives = 3;

// Arithmetic: calculate points for this round
let pointsEarned = 20 + 15;         // 35
let bonus = pointsEarned % 10;      // 5 (remainder)

// Assignment shorthand: update the score
playerScore += pointsEarned + bonus; // 0 + 40 = 40

// Comparison: has the player won?
let hasWon = playerScore &gt;= targetScore; // false (40 &lt; 50)

// Logical: game continues if not won AND has lives left
let gameContinues = !hasWon &amp;&amp; lives &gt; 0; // true

console.log("Score:", playerScore);      // 40
console.log("Won?", hasWon);             // false
console.log("Continue?", gameContinues); // true
</code></pre>
<hr />
<h2>Wrapping Up</h2>
<p>You've been using operators your whole life, in school, on your phone, in your head. JavaScript just gives you a more powerful set of buttons. Arithmetic crunches the numbers. Comparison checks the results. Logic makes the decision. Assignment remembers it all.</p>
<p>The calculator analogy holds all the way through. Once you internalise it, operators won't feel like syntax anymore, they'll feel like tools you already know how to use.</p>
]]></content:encoded></item><item><title><![CDATA[TCP Working: 3-Way Handshake & Reliable Communication]]></title><description><![CDATA[What is TCP and why it is needed
TCP (Transmission Control Protocol) is one of the core protocols of the Internet Protocol Suite. It operates at the Transport Layer (Layer 4) and provides a reliable, ordered, and error-checked delivery of data betwee...]]></description><link>https://vibhavaribellutagi.hashnode.dev/tcp-3-way-handshake</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/tcp-3-way-handshake</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[tcp/ip-model]]></category><category><![CDATA[TCP Handshake]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Fri, 30 Jan 2026 08:31:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769761679343/a3bd4b8a-9e4b-46ee-8784-cf4e3eef3c10.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-tcp-and-why-it-is-needed">What is TCP and why it is needed</h3>
<p><strong>TCP (Transmission Control Protocol)</strong> is one of the core protocols of the Internet Protocol Suite. It operates at the Transport Layer (Layer 4) and provides a reliable, ordered, and error-checked delivery of data between applications running on networked devices.</p>
<p>Think of TCP as a postal service with tracking and confirmation. When you send a package, you want to know:</p>
<ul>
<li><p>Did it arrive?</p>
</li>
<li><p>Did it arrive intact?</p>
</li>
<li><p>Did it arrive in the right order (if you sent multiple packages)?</p>
</li>
</ul>
<p>TCP provides these guarantees for data packets traveling across the internet. Without TCP, applications like web browsers, email clients, file transfers, and SSH connections wouldn't work reliably.</p>
<p><strong>Why TCP is needed:</strong></p>
<ul>
<li><p>The underlying Internet Protocol (IP) is <strong>unreliable</strong> - packets can be lost, duplicated, delayed, or arrive out of order</p>
</li>
<li><p>Applications need a <strong>reliable communication channel</strong> without worrying about the chaos of the underlying network</p>
</li>
<li><p>Developers need a <strong>simple interface</strong> - they can write data to a stream and trust it will arrive correctly</p>
</li>
</ul>
<hr />
<h3 id="heading-problems-tcp-is-designed-to-solve">Problems TCP is Designed to Solve</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Problem</strong></td><td><strong>Description</strong></td><td><strong>TCP's Solution</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Packet Loss</strong></td><td>Networks are unreliable. Packets can be dropped due to network congestion, router failures, or buffer overflows.</td><td>Acknowledgments (ACKs) and retransmissions. The sender retransmits data if it doesn't receive an acknowledgment within a timeout period.</td></tr>
<tr>
<td><strong>Out-of-Order Delivery</strong></td><td>Packets can take different routes through the network and arrive in a different order than they were sent.</td><td>Sequence numbers. Each byte of data is numbered, allowing the receiver to reorder packets correctly.</td></tr>
<tr>
<td><strong>Data Corruption</strong></td><td>Bits can be flipped during transmission due to electrical interference or hardware issues.</td><td>Checksums. TCP includes a checksum in every segment to detect corrupted data.</td></tr>
<tr>
<td><strong>Duplicate Packets</strong></td><td>Network devices might accidentally send the same packet multiple times.</td><td>Sequence numbers help identify and discard duplicate packets.</td></tr>
<tr>
<td><strong>Flow Control</strong></td><td>A fast sender can overwhelm a slow receiver.</td><td>Sliding window mechanism that allows the receiver to tell the sender how much data it can handle.</td></tr>
<tr>
<td><strong>Congestion Control</strong></td><td>Too many senders can overwhelm the network itself.</td><td>Congestion control algorithms (like Slow Start, Congestion Avoidance) that detect network congestion and reduce sending rates.</td></tr>
</tbody>
</table>
</div><h3 id="heading-step-by-step-working-of-syn-syn-ack-and-ack">Step-by-step working of SYN, SYN-ACK and ACK</h3>
<p>Imagine you're trying to start a phone conversation with a friend:</p>
<p><strong>You:</strong> "Hey, can you hear me?" (This is the <strong>SYN</strong> - you're initiating contact)<br /><strong>Friend:</strong> "Yes, I can hear you! Can you hear me?" (This is the <strong>SYN-ACK</strong> - they acknowledge hearing you AND check if you can hear them)<br /><strong>You:</strong> "Yep, I hear you too!" (This is the <strong>ACK</strong> - you confirm you received their response)</p>
<p>Now you both know the line is working in both directions, and you can start your actual conversation.</p>
<p>If we translate this into technical -</p>
<p><strong>Step 1: SYN (Synchronize)</strong></p>
<ul>
<li><p>Client sends a TCP segment with the <strong>SYN flag</strong> set</p>
</li>
<li><p>Includes an <strong>initial sequence number (ISN)</strong> - let's say <code>seq=1000</code></p>
</li>
<li><p>This says: "I want to establish a connection, and my starting sequence number is 1000"</p>
</li>
</ul>
<p><strong>Step 2: SYN-ACK (Synchronize-Acknowledge)</strong></p>
<ul>
<li><p>Server receives the SYN</p>
</li>
<li><p>Server responds with <strong>both SYN and ACK flags</strong> set</p>
</li>
<li><p>Sends its own initial sequence number - say <code>seq=5000</code></p>
</li>
<li><p>Acknowledges the client's sequence number: <code>ack=1001</code> (client's seq + 1)</p>
</li>
<li><p>This says: "I received your request, my starting sequence number is 5000, and I'm expecting your next byte to be 1001"</p>
</li>
</ul>
<p><strong>Step 3: ACK (Acknowledge)</strong></p>
<ul>
<li><p>Client sends an ACK back to the server</p>
</li>
<li><p><code>seq=1001</code> (as expected by the server)</p>
</li>
<li><p><code>ack=5001</code> (server's seq + 1)</p>
</li>
<li><p>This says: "I received your response, and I'm expecting your next byte to be 5001"</p>
</li>
</ul>
<p><strong>Connection is now ESTABLISHED!</strong> Both sides have synchronized their sequence numbers and are ready to exchange data.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769703784898/d90110d5-0aae-4e94-b902-828ad58309f4.png" alt /></p>
<h4 id="heading-data-transfer-in-tcp">Data Transfer in TCP</h4>
<p>TCP breaks data into <strong>segments</strong>, each with a sequence number. The sender transmits segments, and the receiver acknowledges them.</p>
<p><strong>Example:</strong> You send "Hello World" (11 bytes)</p>
<ul>
<li><p>TCP breaks it into segments: <code>[SEQ=1, "Hello"]</code> and <code>[SEQ=6, " World"]</code></p>
</li>
<li><p>Receiver gets segment 1 → sends <code>ACK=6</code> (expecting byte 6 next)</p>
</li>
<li><p>Receiver gets segment 2 → sends <code>ACK=12</code></p>
</li>
</ul>
<h3 id="heading-how-tcp-ensures-reliability-order-amp-correctness">How TCP Ensures Reliability, Order &amp; Correctness</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Mechanism</td><td>How It Works</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Sequence Numbers</strong></td><td>Each byte gets a number. Receiver reorders out-of-order packets.</td></tr>
<tr>
<td><strong>Acknowledgments (ACKs)</strong></td><td>Receiver confirms receipt. Missing ACK triggers retransmission.</td></tr>
<tr>
<td><strong>Checksum</strong></td><td>Detects corrupted data. Bad packets are discarded and resent.</td></tr>
<tr>
<td><strong>Retransmission Timer</strong></td><td>If no ACK arrives in time, sender resends the segment.</td></tr>
<tr>
<td><strong>Flow Control</strong></td><td>Receiver advertises window size to prevent overwhelming it.</td></tr>
</tbody>
</table>
</div><h3 id="heading-tcp-connection-termination">TCP Connection Termination</h3>
<p>Either side can initiate closing. It uses <strong>FIN</strong> (finish) flags.</p>
<pre><code class="lang-powershell">    Client                    Server
       |                         |
       |-------- FIN -----------&gt;|   <span class="hljs-number">1</span>. Client: <span class="hljs-string">"I'm done sending"</span>
       |&lt;------- ACK ------------|   <span class="hljs-number">2</span>. Server: <span class="hljs-string">"Got it"</span>
       |                         |
       |&lt;------- FIN ------------|   <span class="hljs-number">3</span>. Server: <span class="hljs-string">"I'm done too"</span>
       |-------- ACK -----------&gt;|   <span class="hljs-number">4</span>. Client: <span class="hljs-string">"Got it, closing"</span>
       |                         |
    CLOSED                    CLOSED
</code></pre>
<p><strong>Example:</strong> Closing an HTTP connection</p>
<ol>
<li><p>Browser finishes request → sends <strong>FIN</strong></p>
</li>
<li><p>Server acknowledges with <strong>ACK</strong></p>
</li>
<li><p>Server finishes response → sends its <strong>FIN</strong></p>
</li>
<li><p>Browser sends final <strong>ACK</strong> → both sides close</p>
</li>
</ol>
<p>The client then enters a <strong>TIME_WAIT</strong> state (typically 2 minutes) to handle any delayed packets before fully closing.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<ul>
<li><p>TCP (Transmission Control Protocol) is a fundamental protocol of the Internet Protocol Suite that ensures reliable, ordered, and error-checked data delivery between applications on networked devices.</p>
</li>
<li><p>It overcomes issues such as packet loss, out-of-order delivery, data corruption, duplicate packets, and congestion through mechanisms like acknowledgments, sequence numbers, checksums, and congestion control algorithms.</p>
</li>
<li><p>TCP also involves a three-step process (SYN, SYN-ACK, ACK) to establish connections and ensures orderly data transfer with its sequence and acknowledgment features.</p>
</li>
<li><p>Lastly, it provides a structured method for connection termination using FIN and ACK flags.</p>
</li>
</ul>
<p>If you find this blog interesting, feel free to share it across. Follow me on <a target="_blank" href="https://www.linkedin.com/in/vibhavari-bellutagi/">LinkedIn</a></p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with cURL]]></title><description><![CDATA[Have you ever wondered how developers test APIs, download files, or communicate with web servers without opening a browser? The answer is cURL - one of the most powerful and widely-used command-line tools in a programmer's toolkit.
cURL (short for "C...]]></description><link>https://vibhavaribellutagi.hashnode.dev/getting-started-with-curl</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/getting-started-with-curl</guid><category><![CDATA[curl]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Wed, 28 Jan 2026 16:10:39 GMT</pubDate><content:encoded><![CDATA[<p>Have you ever wondered how developers test APIs, download files, or communicate with web servers without opening a browser? The answer is <strong>cURL</strong> - one of the most powerful and widely-used command-line tools in a programmer's toolkit.</p>
<p>cURL (short for "Client URL") is a command-line tool for transferring data using URLs. Whether you're testing REST APIs, downloading files, debugging web services, or automating data transfers, cURL is your go-to solution. It's free, open-source, and comes pre-installed on most Unix-based systems (Linux and macOS) and Windows 10+.</p>
<h3 id="heading-why-programmers-need-curl">Why programmers need cURL</h3>
<p>Before diving into cURL, let's understand the basics of how the internet works.</p>
<p>A <strong>server</strong> is a computer that stores and provides information to other computers over a network. These other computers are called <strong>clients</strong>. When you open a website, your browser (the client) sends a request to a web server, and the server responds with the webpage data.</p>
<p>Normally, this communication happens through a graphical interface like a web browser. But what if you want to:</p>
<ul>
<li><p>Test an API during development?</p>
</li>
<li><p>Automate file downloads?</p>
</li>
<li><p>Debug server responses?</p>
</li>
<li><p>Write scripts that interact with web services?</p>
</li>
</ul>
<p>This is where <strong>cURL</strong> becomes invaluable.</p>
<h3 id="heading-curl-your-command-line-messenger">cURL: Your Command-Line Messenger</h3>
<p>Think of cURL as a messenger that works directly from your terminal. Instead of clicking buttons in a browser, you type commands that:</p>
<ol>
<li><p><strong>Send requests</strong> to a server (asking for data or sending information)</p>
</li>
<li><p><strong>Receive responses</strong> from the server (getting the data you requested)</p>
</li>
<li><p><strong>Display results</strong> right in your terminal (or save them to files)</p>
</li>
</ol>
<h3 id="heading-making-your-first-request-using-curl">Making your first request using cURL</h3>
<pre><code class="lang-bash">curl https://api.github.com
</code></pre>
<p>This fetches data from GitHub's API and displays it in your terminal.</p>
<h3 id="heading-common-curl-commands-to-try">Common curl commands to try:</h3>
<p><strong>Save output to a file:</strong></p>
<pre><code class="lang-bash">curl https://api.github.com -o output.json
</code></pre>
<p><strong>Make a GET request with headers:</strong></p>
<pre><code class="lang-bash">curl -H <span class="hljs-string">"Accept: application/json"</span> https://api.github.com
</code></pre>
<p><strong>Make a POST request with data:</strong></p>
<pre><code class="lang-bash">curl -X POST https://httpbin.org/post \
  -H <span class="hljs-string">"Content-Type: application/json"</span> \
  -d <span class="hljs-string">'{"name": "John", "age": 30}'</span>
</code></pre>
<p><strong>See response headers:</strong></p>
<pre><code class="lang-bash">curl -i https://api.github.com
</code></pre>
<h3 id="heading-understanding-request-and-response">Understanding request and response</h3>
<p>The Request (what you send) →</p>
<p>When you use curl, you're sending an HTTP request to a server. A request has several parts:</p>
<ol>
<li><p>Method (GET, POST, PUT, DELETE, etc.)</p>
</li>
<li><p>URL (where you're sending the request)</p>
</li>
<li><p>Headers (metadata about your request)</p>
</li>
<li><p>Body (optional data you're sending)</p>
</li>
</ol>
<p>The Response (what you get back) →</p>
<p>The server sends back an HTTP response with:</p>
<ol>
<li><p>Status code (200 = success, 404 = not found, etc.)</p>
</li>
<li><p>Headers (metadata about the response)</p>
</li>
<li><p>Body (the actual data/content)</p>
</li>
</ol>
<p>Try this command to see <strong>both</strong> the request and response:</p>
<pre><code class="lang-bash">curl -v https://httpbin.org/get
</code></pre>
<p>The <code>-v</code> (verbose) flag shows you everything. Let me explain what you'll see:</p>
<pre><code class="lang-plaintext">&gt; GET /get HTTP/1.1              ← REQUEST METHOD
&gt; Host: httpbin.org               ← REQUEST HEADER
&gt; User-Agent: curl/7.x            ← REQUEST HEADER
&gt; Accept: */*                     ← REQUEST HEADER

&lt; HTTP/1.1 200 OK                 ← RESPONSE STATUS
&lt; Content-Type: application/json  ← RESPONSE HEADER
&lt; Content-Length: 315             ← RESPONSE HEADER

{                                 ← RESPONSE BODY
  "args": {},
  "headers": {...},
  "url": "https://httpbin.org/get"
}
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><code>&gt;</code> → request (what you sent) and <code>&lt;</code> → response (what you got back)</div>
</div>

<h3 id="heading-get-and-post-methods">GET and POST Methods</h3>
<h4 id="heading-get-i-want-to-read-something-it-is-like-asking-a-question-or-looking-something-up-youre-just-requesting-information-without-changing-anything">GET - "I want to read something" - It is like asking a question or looking something up. You're just requesting information without changing anything.</h4>
<ul>
<li><p>Opening a website in your browser</p>
</li>
<li><p>Searching Google</p>
</li>
<li><p>Checking the weather</p>
</li>
<li><p>Looking at your bank balance</p>
</li>
</ul>
<p><strong>Curl example:</strong></p>
<p>bash</p>
<pre><code class="lang-bash">curl https://api.github.com/users/octocat
</code></pre>
<p>This asks: "Hey GitHub, can I see octocat's profile?"</p>
<h4 id="heading-post-i-want-to-sendcreate-something-it-is-like-filling-out-a-form-and-submitting-it-youre-sending-data-to-create-or-update-something">POST - "I want to send/create something", it is like filling out a form and submitting it. You're sending data to create or update something.</h4>
<ul>
<li><p>Submitting a contact form</p>
</li>
<li><p>Creating a new social media post</p>
</li>
<li><p>Logging into a website</p>
</li>
<li><p>Uploading a file</p>
</li>
</ul>
<p><strong>Curl example:</strong></p>
<p>bash</p>
<pre><code class="lang-bash">curl -X POST https://httpbin.org/post \
  -d <span class="hljs-string">"username=john&amp;password=secret123"</span>
</code></pre>
<p>This says: "Hey server, here's some data I want to send you."</p>
<p>I hope you have enough knowledge on the cURL. If you like the blog, please share it with others. Follow me on <a target="_blank" href="https://www.linkedin.com/in/vibhavari-bellutagi/"><strong>linkedin</strong></a></p>
<div class="hn-embed-widget" id="buymecoffee"></div>]]></content:encoded></item><item><title><![CDATA[Networking Basics: Comparing TCP and UDP Protocols]]></title><description><![CDATA[Introduction
Every time you stream a video, send an email, or load a webpage, there's an invisible conversation happening between your device and servers across the internet. But how do these machines know how to talk to each other? The answer lies i...]]></description><link>https://vibhavaribellutagi.hashnode.dev/tcp-and-udp</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/tcp-and-udp</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[TCP/UDP]]></category><category><![CDATA[TCP]]></category><category><![CDATA[UDP]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Wed, 28 Jan 2026 16:08:37 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-introduction">Introduction</h3>
<p>Every time you stream a video, send an email, or load a webpage, there's an invisible conversation happening between your device and servers across the internet. But how do these machines know how to talk to each other? The answer lies in protocols, the rules that govern network communication.</p>
<p>Two of the most fundamental protocols powering the internet are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). While they both move data from point A to point B, they take remarkably different approaches. In this blog, we'll pull back the curtain on how these protocols work, when to use each one, and why understanding the difference matters for anyone working with networked applications.</p>
<h3 id="heading-what-is-tcp">What is TCP</h3>
<p>TCP is the reliable workhorse of the internet. Think of it like sending a registered letter, you know it will arrive, you'll get confirmation, and the pages will be in the right order.</p>
<p>When you use TCP, your computer breaks data into small packets and sends them across the network. The receiving computer sends back acknowledgments saying "Got packet 1," "Got packet 2," and so on. If a packet goes missing, TCP notices and resends it. Before any data is sent, TCP establishes a connection through a "three-way handshake", essentially, the two computers introduce themselves and agree to communicate.</p>
<p>This reliability comes at a cost: TCP is slower because of all this checking and confirming. But for most internet activities, loading websites, sending emails, downloading files, you want that reliability.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769614668523/921491f5-e7b1-485a-856a-b1af95813d8d.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-what-is-udp">What is UDP?</h3>
<p>→ UDP is more like shouting across a crowded room, fast and efficient, but with no guarantee anyone heard you. It is the speed demon of networking.</p>
<p>With UDP, data packets are simply fired off to their destination with no handshake, no acknowledgments, and no guarantees. There's no connection established beforehand. Packets might arrive out of order, get lost entirely, or even arrive duplicated, and UDP doesn't care. It just keeps sending.</p>
<p>This might sound terrible, but for certain applications, speed matters more than perfection. A few dropped packets in a video call or online game won't ruin the experience, but lag and delays absolutely will.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769614683756/f88c6eb5-909e-4e19-b281-2b73f42da9b5.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-key-differences-between-tcp-and-udp">Key differences between TCP and UDP</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>TCP</td><td>UDP</td></tr>
</thead>
<tbody>
<tr>
<td>Requires a connection (handshake)</td><td>No connection needed</td></tr>
<tr>
<td>Guarantees delivery</td><td>No guarantee</td></tr>
<tr>
<td>Packets arrive in order</td><td>Packets may arrive out of order</td></tr>
<tr>
<td>Slower ( due to handshake )</td><td>Faster ( minimal overhead )</td></tr>
<tr>
<td>Extensive error checking</td><td>Basic error checking</td></tr>
<tr>
<td>When accuracy matters</td><td>when speed matters</td></tr>
</tbody>
</table>
</div><h3 id="heading-when-to-use-what-tcp-vs-udp">When to use what - TCP vs UDP?</h3>
<p>Use TCP when:</p>
<ul>
<li><p>Accuracy is critical – File transfers, emails, web browsing</p>
</li>
<li><p>Order matters – Loading a webpage, downloading software</p>
</li>
<li><p>You can't afford lost data – Bank transactions, text messages</p>
</li>
</ul>
<p><strong>Examples:</strong> HTTP/HTTPS (websites), FTP (file transfer), SMTP (email), SSH (remote access)</p>
<p>Use UDP when:</p>
<ul>
<li><p>Speed is more important than perfection – Live streaming, gaming</p>
</li>
<li><p>Small amounts of data are lost – VoIP calls, video conferencing</p>
</li>
<li><p>Real-time communication matters – DNS lookups, online multiplayer games</p>
</li>
</ul>
<p><strong>Examples:</strong> Video streaming (Netflix, YouTube), online gaming, voice/video calls (Zoom, Discord), DNS queries</p>
<p>Think of it this way: If you're watching a live sports stream and a few frames drop, you barely notice. But if those frames arrived late because the protocol waited to resend them, you'd see frustrating buffering and lag.</p>
<h3 id="heading-what-is-http-and-relationship-between-tcp-and-http">What is HTTP and relationship between TCP and HTTP</h3>
<p>HTTP (Hypertext Transfer Protocol) is the language of the web, it's how your browser asks for a webpage and how the server sends it back. But here's the key: HTTP doesn't work alone. It relies on TCP to actually deliver the data.</p>
<p>Think of it like this:</p>
<ul>
<li><p><strong>HTTP</strong> is the <em>language</em> being spoken ("Please send me the homepage")</p>
</li>
<li><p><strong>TCP</strong> is the <em>delivery service</em> that makes sure the message gets there reliably</p>
</li>
</ul>
<p>When you type a URL in your browser:</p>
<ol>
<li><p>Your browser uses HTTP to format the request</p>
</li>
<li><p>TCP breaks that request into packets and sends them</p>
</li>
<li><p>TCP makes sure all packets arrive at the server</p>
</li>
<li><p>The server uses HTTP to format its response</p>
</li>
<li><p>TCP delivers that response back to you, in order and complete</p>
</li>
</ol>
<p>This is why HTTP is called an "application layer" protocol, it sits on top of TCP (the "transport layer"). HTTP handles <em>what</em> you're communicating, while TCP handles <em>how</em> it gets there.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Modern websites use HTTPS (HTTP Secure), which adds encryption for security, but it still relies on TCP underneath for reliable delivery.</div>
</div>

<p>If you like the blog, please share it with others. Follow me on <a target="_blank" href="https://www.linkedin.com/in/vibhavari-bellutagi/"><strong>linkedin</strong></a></p>
<div class="hn-embed-widget" id="buymecoffee"></div>]]></content:encoded></item><item><title><![CDATA[DNS Record Types Explained]]></title><description><![CDATA[Have you ever wondered how your browser knows where to find website? There are billions of websites on the internet, each one stored on a server somewhere in the world. So when you type amazon.com, how does your browser know exactly where to go?
Ever...]]></description><link>https://vibhavaribellutagi.hashnode.dev/dns-record-types</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/dns-record-types</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[#dnsrecords]]></category><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Mon, 26 Jan 2026 16:54:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769446286233/0c8a3c8c-f184-41f7-8bb2-fc70b7ca32f7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever wondered how your browser knows where to find website? There are billions of websites on the internet, each one stored on a server somewhere in the world. So when you type <a target="_blank" href="http://amazon.com"><code>amazon.com</code></a>, how does your browser know exactly where to go?</p>
<p>Every website has an IP address (like <code>192.0.2.1</code>), but nobody wants to memorise numbers. DNS (Domain Name System) is the internet's phonebook, it translates human-friendly names into machine-readable addresses. When you type a domain, your browser asks a DNS server: "What's the address for this name?" The server looks it up and responds. Your browser then connects to that IP address. All of this happens in milliseconds, invisibly.</p>
<h2 id="heading-why-records-exists">Why records exists?</h2>
<p>Think about a contact in your phone. You don't just store one piece of information, you save their mobile number, work number, email, maybe even their home address. Each serves a different purpose, but they all belong to the same person.</p>
<p>DNS records work the same way. A domain name isn't just one thing, it's an identity that needs to handle multiple jobs. Your website needs to load. Emails need to arrive. Subdomains need to work. Security needs to be verified. A single IP address can't communicate all of that.</p>
<p>That's why DNS uses <strong>records</strong>, different types of entries that tell the internet how to handle different requests for your domain.</p>
<h2 id="heading-types-of-dns-records">Types of DNS records</h2>
<h3 id="heading-a-record">A Record</h3>
<p>A → “Address”, the most fundamental type of DNS record type. It contains the IP address of a given domain. When a <a target="_blank" href="https://vibhavaribellutagi.hashnode.dev/how-dns-resolution-works">DNS resolver</a> queries for a domain name, the A record returns the 32-bit IPV4 address attached to it.</p>
<pre><code class="lang-plaintext">example.com.    3600    IN    A           93.184.216.34
</code></pre>
<ul>
<li><p>TTL (Time To Live): 3600 seconds</p>
</li>
<li><p>Class: IN (Internet)</p>
</li>
<li><p>Type: A</p>
</li>
<li><p>Value: IPv4 address</p>
</li>
</ul>
<p>Majority of websites will have only one A record, however some high profile websites might have several different A records as a part of technique called round robin load balancing.</p>
<p>Imagine you're looking up "Krishna's Kapi Shop" in a city directory. The A Record is like finding the entry that says "Krishna's Kapi Shop → 742 Evergreen Terrace." When you want to visit (send a request), you now know exactly which building (server) to go to. Without this address, you know the name but can't find the actual location.</p>
<h4 id="heading-when-and-why-used">When and Why Used</h4>
<ul>
<li><p><strong>Primary use</strong>: Pointing your domain to your web server</p>
</li>
<li><p><strong>When</strong>: Every website needs at least one A Record for the root domain</p>
</li>
<li><p><strong>Why</strong>: Without it, browsers can't find your website - they need the IP address to establish a connection</p>
</li>
<li><p><strong>Example scenario</strong>: You host your website on a server at IP 203.0.113.50. You create an A Record so <a target="_blank" href="http://mysite.com"><code>mysite.com</code></a> points to that IP</p>
</li>
</ul>
<h3 id="heading-aaaa-record">AAAA Record</h3>
<p>An AAAA Record maps a domain name to a 128-bit IPv6 address. It's functionally identical to an A Record but uses the newer IPv6 addressing scheme. The "AAAA" name comes from IPv6 addresses being four times larger than IPv4 (128 bits vs 32 bits).</p>
<pre><code class="lang-plaintext">example.com. 3600 IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334
</code></pre>
<p>Think of international phone numbers. The old system had 7-digit local numbers (IPv4), but we ran out. Now we have longer international format numbers with country codes and more digits (IPv6): +1-555-0123-4567-8901. Both get you to the same place, just different numbering systems.</p>
<h3 id="heading-when-and-why-used-1">When and Why Used</h3>
<ul>
<li><p><strong>Primary use</strong>: Enabling IPv6 connectivity to your services</p>
</li>
<li><p><strong>When</strong>: Increasingly necessary as IPv4 addresses are exhausted; major sites have both A and AAAA records</p>
</li>
<li><p><strong>Why</strong>: Future-proofing your infrastructure; some networks are IPv6-only; better performance in IPv6 networks</p>
</li>
<li><p><strong>Example scenario</strong>: Your hosting provider gives you an IPv6 address. You add an AAAA Record so visitors on IPv6 networks can reach you directly without IPv4 translation</p>
</li>
</ul>
<h3 id="heading-cname-record"><strong>CNAME Record</strong></h3>
<p>The GitHub Pages -</p>
<p><strong>Default Setup -</strong> When I create a GitHub Pages site, GitHub automatically hosts it at:</p>
<ul>
<li><p>Personal site: <code>username.github.io</code></p>
</li>
<li><p>Project site: <code>username.github.io/repository-name</code></p>
</li>
</ul>
<p><strong>Example</strong>: Lets say my GitHub username is <code>vibhavari</code>, so your site lives at <code>vibhavari.github.io</code></p>
<p><strong>The Problem?</strong></p>
<p>You want your professional blog at <code>www.vibhavari.com</code> instead of <code>vibhavari.github.io</code> because:</p>
<ul>
<li><p>Custom domain looks more professional</p>
</li>
<li><p>Easier to remember</p>
</li>
<li><p>You control the branding</p>
</li>
<li><p>You can migrate away from GitHub Pages later without breaking links</p>
</li>
</ul>
<hr />
<h4 id="heading-how-cname-solves-this">How CNAME Solves This</h4>
<p>GitHub's Infrastructure GitHub Pages hosts your content on their servers with a generic address:</p>
<ul>
<li><p>Your content actually lives at: <code>vibhavari.github.io</code></p>
</li>
<li><p>GitHub's servers are at specific IP addresses they control</p>
</li>
</ul>
<p>In your DNS provider (Cloudflare, GoDaddy, Route53, etc.), you create:</p>
<pre><code class="lang-plaintext">www.vibhavari.com.  3600  IN  CNAME  vibhavari.github.io.
</code></pre>
<p>this means:</p>
<ul>
<li><p>"When someone visits <code>www.vibhavari.com</code>, go look up <code>vibhavari.github.io</code> instead"</p>
</li>
<li><p>The DNS resolver follows the chain: <code>www.vibhavari.com</code> → <code>vibhavari.github.io</code> → (GitHub's A records) → IP address</p>
</li>
</ul>
<p>In your GitHub repository settings, you tell GitHub:</p>
<ul>
<li><p>"Accept traffic for <code>www.vibhavari.com</code>"</p>
</li>
<li><p>GitHub creates a <code>CNAME</code> file in your repository root containing: <code>www.vibhavari.com</code></p>
</li>
</ul>
<p>So what does CNAME record do? A CNAME Record creates an alias by mapping one domain name to another domain name (the canonical name). When a DNS resolver encounters a CNAME, it performs another lookup for the target domain. CNAMEs cannot coexist with other record types at the same name level (this is a critical DNS protocol requirement).</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">You CANNOT have a CNAME at the root domain (<a target="_self" href="http://example.com">example.com</a>) - only subdomains (<a target="_self" href="http://www.example.com">www.example.com, </a><a target="_self" href="http://blog.example.com">blog.example.com</a>, etc.)</div>
</div>

<h3 id="heading-ns-record">NS Record</h3>
<p>An NS Record delegates a DNS zone to a specific <code>authoritative name server.</code> It tells DNS resolvers which server(s) are authoritative for answering queries about a particular domain. Every domain must have at least two NS records (for redundancy) pointing to name servers that host the domain's DNS information.</p>
<pre><code class="lang-plaintext">example.com. 86400 IN NS ns1.nameserver.com.
</code></pre>
<p>Think of a <strong>corporate directory</strong>: The main receptionist doesn't know everyone's extension. When you call asking for the Marketing department, they say: "Marketing is handled by Extension 5000, transfer there." The NS Record is that transfer.</p>
<h3 id="heading-when-and-why-used-2">When and Why Used</h3>
<ul>
<li><p><strong>Primary use</strong>: Delegating DNS authority for a domain or subdomain</p>
</li>
<li><p><strong>When</strong>: Setting up a domain, delegating subdomains to different DNS providers, using a CDN</p>
</li>
<li><p><strong>Why</strong>: Enables distributed DNS management; allows different teams/services to control their own subdomains</p>
</li>
<li><p><strong>Example scenario 1</strong>: You register <a target="_blank" href="http://example.com"><code>example.com</code></a> at a registrar. You must point NS records to your DNS hosting provider (like Cloudflare, Route53, etc.)</p>
</li>
</ul>
<h3 id="heading-mx-record"><strong>MX Record</strong></h3>
<p>An MX Record specifies the mail servers responsible for accepting email on behalf of a domain. It includes a priority value (lower numbers = higher priority) to enable fallback mail servers. When someone sends email to <a target="_blank" href="mailto:user@example.com"><code>user@example.com</code></a>, their mail server queries the MX records to find where to deliver the message.</p>
<pre><code class="lang-plaintext">example.com. 3600 IN MX 10 mail1.example.com.
</code></pre>
<ul>
<li><p>Priority: 10 (lower is preferred)</p>
</li>
<li><p>Mail server: <a target="_blank" href="http://mail1.example.com">mail1.example.com</a></p>
</li>
</ul>
<p>Think of a <strong>corporate mail room hierarchy</strong>. Your company receives physical mail, but there's a priority system:</p>
<ul>
<li><p><strong>Priority 10</strong>: Main mail room (handles 95% of mail) - <a target="_blank" href="http://mail1.example.com"><code>mail1.example.com</code></a></p>
</li>
<li><p><strong>Priority 20</strong>: Backup mail room (if main is full/closed) - <a target="_blank" href="http://mail2.example.com"><code>mail2.example.com</code></a></p>
</li>
<li><p><strong>Priority 30</strong>: Emergency off-site facility - <a target="_blank" href="http://mail3.example.com"><code>mail3.example.com</code></a></p>
</li>
</ul>
<p>The postal service tries the Priority 10 location first. If it's unavailable, they try Priority 20, and so on.</p>
<h3 id="heading-when-and-why-used-3">When and Why Used</h3>
<ul>
<li><p><strong>Primary use</strong>: Directing email to the correct mail servers</p>
</li>
<li><p><strong>When</strong>: Setting up email for your domain; using email services like Google Workspace, Microsoft 365</p>
</li>
<li><p><strong>Why</strong>: Separates email infrastructure from web hosting; enables redundancy and load balancing for email</p>
</li>
<li><p>You use Google Workspace for email. You create MX records:</p>
</li>
</ul>
<pre><code class="lang-plaintext">  example.com. IN MX 1 aspmx.l.google.com.
  example.com. IN MX 5 alt1.aspmx.l.google.com.
  example.com. IN MX 5 alt2.aspmx.l.google.com.
</code></pre>
<p>If the primary server is down, email automatically routes to backups.</p>
<h3 id="heading-txt-record"><strong>TXT Record</strong></h3>
<p>A TXT Record stores arbitrary text data associated with a domain. Though originally intended for human-readable notes, TXT records are now primarily used for machine-readable data like domain verification, email security policies (SPF, DKIM, DMARC), and site ownership verification. The data is stored as a string (up to 255 characters per string, but multiple strings can be concatenated).</p>
<pre><code class="lang-plaintext">example.com. 3600 IN TXT "v=spf1 include:_spf.google.com ~all"
</code></pre>
<p>Think of a bulletin board outside your house with various notices:</p>
<ul>
<li><p>"This is indeed the Johnson residence" (domain verification)</p>
</li>
<li><p>"We only accept mail from USPS and FedEx" (SPF)</p>
</li>
<li><p>"Packages should be left with neighbor at #125" (special instructions)</p>
</li>
</ul>
<h3 id="heading-when-and-why-used-4">When and Why Used</h3>
<ul>
<li><p><strong>Primary use</strong>: Domain verification, email authentication, security policies</p>
</li>
<li><p><strong>When</strong>: Proving domain ownership, preventing email spoofing, setting up third-party services</p>
</li>
<li><p><strong>Why</strong>: Provides a flexible mechanism for adding metadata to domains without creating new DNS record types</p>
</li>
</ul>
<p><strong>Common Use Cases:</strong></p>
<p><strong>1. Domain Verification</strong></p>
<ul>
<li><p><strong>When</strong>: Setting up Google Workspace, Microsoft 365, or any service that needs to verify you own the domain</p>
</li>
<li><p><strong>Example</strong>: <a target="_blank" href="http://example.com"><code>example.com</code></a><code>. IN TXT "google-site-verification=abc123xyz"</code></p>
</li>
<li><p><strong>Why</strong>: Proves you control the domain before the service activates</p>
</li>
</ul>
<p><strong>2. SPF (Sender Policy Framework)</strong></p>
<ul>
<li><p><strong>When</strong>: Configuring email to prevent spoofing</p>
</li>
<li><p><strong>Example</strong>: <a target="_blank" href="http://example.com"><code>example.com</code></a><code>. IN TXT "v=spf1 ip4:192.0.2.1 include:_</code><a target="_blank" href="http://spf.google.com"><code>spf.google.com</code></a> <code>~all"</code></p>
</li>
<li><p><strong>Why</strong>: Lists which servers are allowed to send email from your domain; reduces spam/phishing</p>
</li>
<li><p><strong>Translation</strong>: "Only these mail servers can send email claiming to be from @<a target="_blank" href="http://example.com">example.com</a>"</p>
</li>
</ul>
<p>So in summary, if you think of it as a city:</p>
<ul>
<li><p><strong>NS Records</strong> → City charter (who governs)</p>
</li>
<li><p><strong>A/AAAA Records</strong> → Building addresses (where things are)</p>
</li>
<li><p><strong>CNAME Records</strong> → Street signs &amp; aliases (how to find things)</p>
</li>
<li><p><strong>MX Records</strong> → Post office system (mail delivery)</p>
</li>
<li><p><strong>TXT Records</strong> → Business licenses &amp; permits (verification &amp; security)</p>
</li>
</ul>
<p>If you like the blog, please share it with others. Follow me on <a target="_blank" href="https://www.linkedin.com/in/vibhavari-bellutagi/"><strong>linkedin</strong></a></p>
]]></content:encoded></item><item><title><![CDATA[How DNS Resolution Works]]></title><description><![CDATA[Lets say we need to connect to google.com, but assume we don’t have the domain names but its all IP address - a numerical label like 192.0.2.1 which is assigned to each device connected on internet for communication. It feels difficult to remember th...]]></description><link>https://vibhavaribellutagi.hashnode.dev/how-dns-resolution-works</link><guid isPermaLink="true">https://vibhavaribellutagi.hashnode.dev/how-dns-resolution-works</guid><dc:creator><![CDATA[Vibhavari Bellutagi]]></dc:creator><pubDate>Fri, 23 Jan 2026 16:54:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769016908737/a8d73439-2b26-4f80-b609-605ef5f383f9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Lets say we need to connect to google.com, but assume we don’t have the domain names but its all <a target="_blank" href="https://en.wikipedia.org/wiki/IP_address">IP address</a> - a numerical label like <em>192.0.2.1</em> which is assigned to each device connected on internet for communication. It feels difficult to remember the 10 digits phone numbers of everyone we know, remembering IP address of the websites would have been difficult task in itself. To avoid this, we have <mark>Domain Name System</mark>.</p>
<h2 id="heading-what-is-dns">What is DNS?</h2>
<p>Domain Name System ( DNS ) is is a hierarchical and distributed <a target="_blank" href="https://en.wikipedia.org/wiki/Name_service">name service</a> that provides a naming system for computers, services, and other resources on the Internet or other <a target="_blank" href="https://en.wikipedia.org/wiki/Internet_Protocol">Internet Protocol</a> (IP) networks, in layman words - is a process where it helps internet users to search using the host names instead of numeric IP address. DNS is like a phonebook of internet, it transforms human readable host names into numeric IP address for computers to communicate through network.</p>
<p>As we know, each device connected to internet has a unique IP address which other machines can find and communicate to. Name resolution is process in converting hostnames ( simple english string ) to IP address for network communication. Human always understand descriptive names, but machine communication through network using IP address.</p>
<h2 id="heading-what-is-the-dig-command-and-its-uses">What is the dig command and its uses</h2>
<p><code>dig</code> stands for Domain Information Groper, think of it as a tool that lets peek whats happening in DNS. It is a diagnostic tool, it performs interrogation with DNS name servers. It performs DNS lookups and display the answers that returned from the queries name server(s).</p>
<p>When you type <a target="_blank" href="http://google.com"><code>google.com</code></a> in your browser, DNS quietly works in the background to find the IP address. <code>dig</code> lets you manually ask those same DNS questions yourself and see all the details of what happens.</p>
<p>Usually DNS administrators use dig command to troubleshoot DNS problems because of its flexibility, easy to use and provides clear output.</p>
<p>When you run <code>dig google.com</code> you get a detailed report with sections like:</p>
<pre><code class="lang-powershell">**<span class="hljs-number">1</span>. Question Section** - What you asked
```
;; QUESTION SECTION:
;google.com.                    <span class="hljs-keyword">IN</span>      A
```
Translation: <span class="hljs-string">"What is the A record (IP address) for google.com?"</span>

**<span class="hljs-number">2</span>. Answer Section** - The actual answer
```
;; ANSWER SECTION:
google.com.             <span class="hljs-number">300</span>     <span class="hljs-keyword">IN</span>      A       <span class="hljs-number">142.250</span>.<span class="hljs-number">185.46</span>
</code></pre>
<h3 id="heading-the-dns-hierarchy-a-three-tier-architecture">The DNS Hierarchy: A Three-Tier Architecture</h3>
<p>The sequence in which query resolves describes the hierarchial path of a DNS. The sequence is Root → TLD → Authoritative Servers.</p>
<p><strong>Root Servers</strong> →<br />The root of the DNS tree, represented by a dot (.). It is the starting point for all DNS queries. The root servers do not know the IP address of a domain but direct queries to the appropriate TLD server. There are 13 logical root server addresses, with hundreds of actual servers worldwide.</p>
<p><strong>Top-Level Domains(TLD)</strong> →</p>
<p>If a website address is like a street address, the TLD is like the city, state, or country at the end. It tells you the general "location" or category that the website belongs to. Lets say, in the address <a target="_blank" href="http://www.google.com"><strong>www.google.com</strong></a>, the TLD is just the <strong>.com</strong> part.</p>
<p>Why do we need them?</p>
<p>The internet is too big to be one giant list. TLDs help organize websites into different categories so they are easier to manage and understand.</p>
<p>They act like big labels that give you a hint about what a website is for:</p>
<ul>
<li><p><strong>.com</strong> usually means it is a <strong>comm</strong>ercial business (like Amazon or Google).</p>
</li>
<li><p><strong>.in</strong> is for the India.</p>
</li>
<li><p><strong>.edu</strong> means it is an <strong>edu</strong>cational institution (like a university).</p>
</li>
<li><p><strong>.gov</strong> means it is a <strong>gov</strong>ernment agency.</p>
</li>
</ul>
<p><strong>Authoritative Servers</strong> →</p>
<p>Think of authoritative servers as <strong>the official source of truth</strong> for a specific domain, holding the actual DNS records ( A, AAAA, MX, etc ) for a specific domain name. They provide the final IP address to the resolver</p>
<pre><code class="lang-plaintext">                    [ROOT]
                      |
        +-------------+-------------+
        |             |             |
      [.com]        [.org]        [.net]  ← TLD level
        |
    +---+---+
    |       |
 [google] [facebook]  ← Authoritative level
    |
 [IP: 142.250.185.46]
</code></pre>
<h4 id="heading-why-this-layered-system-exists">Why this Layered System Exists?</h4>
<p><strong>Scalability</strong> - If one person tried to memorise every address in the world - is it ever possible? they’d fail. But if you divide the worlds into countries, then cities, then streets - each level only needs to know about their piece. The internet has billions of domain names. No single server could handle all those requests. By splitting it up, each layer handles a manageable portion.</p>
<p>Decentralisation - What if the master directory gets destroyed or hacked? The whole internet breaks. Instead, DNS spreads the responsibility:</p>
<ul>
<li><p>13 root server systems (actually hundreds of physical servers)</p>
</li>
<li><p>Different organisations manage different TLDs (.com, .org, .uk, etc.)</p>
</li>
<li><p>Individual companies manage their own authoritative servers</p>
</li>
</ul>
<p>If one piece fails, the rest keep working.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>command</td><td>what you’re Asking</td><td>what it reveals</td><td>DNS Layer</td><td>when to use</td></tr>
</thead>
<tbody>
<tr>
<td><code>dig . NS</code></td><td>Who runs the root of DNS?</td><td>The 13 root server identifiers (<a target="_blank" href="http://a-m.root-servers.net">a-m.root-servers.net</a>)</td><td><strong>Layer 0: Root</strong></td><td>Learning DNS fundamentals; Understanding the starting point</td></tr>
<tr>
<td><code>dig com NS</code></td><td>Who manages .com domains?</td><td>TLD name servers for .com (<a target="_blank" href="http://a-m.gtld-servers.net">a-m.gtld-servers.net</a>)</td><td>Layer 1: TLD</td><td>Understanding TLD infrastructure; Troubleshooting domain registration issues</td></tr>
<tr>
<td><code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code></td><td>Who are Google's official DNS servers?</td><td>Google's authoritative name servers (<a target="_blank" href="http://ns1-4.google.com">ns1-4.google.com</a>)</td><td>Layer 2: Authoritative</td><td>Finding who hosts a domain's DNS; Verifying DNS configuration; Planning DNS migrations</td></tr>
<tr>
<td><code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a></td><td>What's Google's IP address?</td><td>The actual IP address (142.250.185.46)</td><td>Layer 3: Resolution</td><td>Normal DNS lookups; Troubleshooting connectivity; Verifying DNS changes went live</td></tr>
</tbody>
</table>
</div><h3 id="heading-behind-the-scenes-how-recursive-resolvers-work">Behind the Scenes: How Recursive Resolvers Work</h3>
<p>A recursive DNS server is a key part of DNS hierarchy, which handles the domain lookups. Let’s see how the recursive DNS works behind the scenes:</p>
<ol>
<li><p><code>Request initiated</code> → When you type a website URL (e.g., <code>www.asample.com</code>) into your browser, your device sends a request to a recursive DNS resolver to find the corresponding IP address.</p>
<ol>
<li><strong>Cache Check</strong>: If this URL was recently requested, the resolver checks its cache first and immediately returns the IP address if found.</li>
</ol>
</li>
<li><p><code>Query to the Root Server</code> → If the IP address isn't in cache, the recursive resolver begins searching through the DNS hierarchy starting with root DNS servers.</p>
<ul>
<li>Root servers don't store domain IP addresses, but they direct the resolver to the appropriate Top-Level Domain (TLD) server based on the domain extension.</li>
</ul>
</li>
<li><p><code>Querying the TLD Server</code> → The TLD server manages all domains within a specific extension (<code>.com</code>, <code>.in</code>, etc.) and directs the recursive resolver to the authoritative DNS server responsible for the specific domain.</p>
</li>
<li><p><code>Querying the authoritative DNS server:</code> → The authoritative server holds the official DNS records for the domain, including the IP address. It responds with the exact IP address for the requested domain.</p>
</li>
<li><p><code>Returning the result to your device</code> <strong>→</strong> The recursive DNS resolver returns the IP address to your device, allowing your browser to connect to the website. The resolver also caches this IP address temporarily to speed up future requests for the same domain.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769186361436/dc7d7b55-ac0a-453c-8d64-1edfb2dbfce5.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The DNS resolution process efficiently translates domain names into IP addresses through a hierarchical lookup system. While multiple servers are involved, caching at each level ensures most requests are resolved within milliseconds. This distributed architecture makes DNS both scalable and reliable, serving as the foundational addressing system that keeps the internet accessible and performant for billions of users worldwide.</p>
<p>If you like the blog, please share it with others. Follow me on <a target="_blank" href="https://www.linkedin.com/in/vibhavari-bellutagi/">linkedin</a></p>
<div class="hn-embed-widget" id="buymecoffee"></div>]]></content:encoded></item></channel></rss>