<?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[Gurjeet.dev]]></title><description><![CDATA[Gurjeet.dev]]></description><link>https://blog.gurjeet.tech</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 12:17:58 GMT</lastBuildDate><atom:link href="https://blog.gurjeet.tech/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding Object-Oriented Programming in JavaScript]]></title><description><![CDATA[When we build real applications, our code starts to grow. We have data, we have functions that work on that data, and before long everything is spread across the file with no clear structure. Things g]]></description><link>https://blog.gurjeet.tech/understanding-object-oriented-programming-in-javascript</link><guid isPermaLink="true">https://blog.gurjeet.tech/understanding-object-oriented-programming-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Cohort2026]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:54:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/8371ec88-1efd-4064-b247-4a4455b589fd.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we build real applications, our code starts to grow. We have data, we have functions that work on that data, and before long everything is spread across the file with no clear structure. Things get hard to manage, hard to read, and hard to fix when something breaks.</p>
<p>Object-Oriented Programming, or OOP, is a way of organising code so that related data and behaviour live together in one place. It is not a JavaScript-specific concept. It is a way of thinking about code that exists across many programming languages.</p>
<p>The core idea is simple: instead of having loose variables and functions floating around, we model our program around things, and each thing has its own data and its own actions.</p>
<hr />
<h2>The Blueprint Analogy</h2>
<p>Before we write a single line of code, let's think about how a car factory works.</p>
<p>An architect draws one blueprint for a car. That blueprint defines what every car made from it will look like. It says every car will have a brand, a colour, and a model. It also defines what every car can do, like start, stop, and accelerate.</p>
<p>From that one blueprint, the factory produces hundreds of individual cars. Each car is its own separate thing. One car might be red, another might be blue. But they were all created from the same blueprint.</p>
<p>In JavaScript, a <strong>class</strong> is the blueprint. An <strong>object</strong> is the car that gets created from it. We write the class once, and we can create as many objects from it as we need.</p>
<hr />
<h2>What is a Class?</h2>
<p>A class is a template that defines what an object will look like and what it can do. We use the <code>class</code> keyword to create one.</p>
<pre><code class="language-javascript">class Student {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}
</code></pre>
<p>Let's break this down piece by piece.</p>
<p><code>class Student</code> defines a new class called <code>Student</code>. By convention, class names always start with a capital letter.</p>
<p><code>constructor</code> is a special method that runs automatically every time we create a new object from this class. It is where we set up the initial data for the object.</p>
<p><code>this.name</code> and <code>this.age</code> are properties being attached to the object being created. The <code>this</code> keyword refers to the specific object that is being built at that moment.</p>
<hr />
<h2>Creating Objects from a Class</h2>
<p>Once we have a class, we create objects from it using the <code>new</code> keyword. Each object created from a class is called an instance.</p>
<pre><code class="language-javascript">class Student {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}

let student1 = new Student("Gurjeet", 22);
let student2 = new Student("Priya", 21);
let student3 = new Student("Rahul", 23);

console.log(student1.name); // Gurjeet
console.log(student2.age);  // 21
console.log(student3.name); // Rahul
</code></pre>
<p>We wrote the <code>Student</code> class once. From that single template, we created three completely separate student objects. Each one has its own <code>name</code> and <code>age</code>. Changing one does not affect the others.</p>
<p>This is exactly like the car factory. One blueprint, multiple cars, each one independent.</p>
<hr />
<h2>Adding Methods to a Class</h2>
<p>A class does not just hold data. It can also hold functions that work with that data. Functions inside a class are called methods.</p>
<pre><code class="language-javascript">class Student {
  constructor(name, age, course) {
    this.name = name;
    this.age = age;
    this.course = course;
  }

  introduce() {
    console.log("Hi, my name is " + this.name + " and I am studying " + this.course);
  }

  birthday() {
    this.age += 1;
    console.log(this.name + " is now " + this.age + " years old");
  }
}

let student1 = new Student("Gurjeet", 22, "Web Development");

student1.introduce();
// Hi, my name is Gurjeet and I am studying Web Development

student1.birthday();
// Gurjeet is now 23 years old
</code></pre>
<p>The <code>introduce</code> method uses <code>this.name</code> and <code>this.course</code> to print a message specific to that student. The <code>birthday</code> method updates <code>this.age</code> for that particular object.</p>
<p>Notice that <code>this</code> inside a method always refers to the object the method is being called on. When we call <code>student1.introduce()</code>, <code>this</code> is <code>student1</code>. The method works with that specific student's data.</p>
<hr />
<h2>The Idea of Encapsulation</h2>
<p>One of the core concepts behind OOP is encapsulation. The word sounds complicated but the idea is straightforward.</p>
<p>Encapsulation means keeping an object's data and the functions that work with that data together in one place. The outside world does not need to know how the object works internally. It just needs to know what it can do.</p>
<p>Think of a TV remote. We press the volume button and the volume goes up. We do not know what circuit gets triggered inside. We do not care. We just know that pressing the button does the job.</p>
<p>In code, this looks like:</p>
<pre><code class="language-javascript">class BankAccount {
  constructor(owner, balance) {
    this.owner = owner;
    this.balance = balance;
  }

  deposit(amount) {
    this.balance += amount;
    console.log(this.owner + " deposited " + amount + ". New balance: " + this.balance);
  }

  withdraw(amount) {
    if (amount &gt; this.balance) {
      console.log("Insufficient balance");
    } else {
      this.balance -= amount;
      console.log(this.owner + " withdrew " + amount + ". New balance: " + this.balance);
    }
  }
}

let account = new BankAccount("Gurjeet", 5000);

account.deposit(1000);
// Gurjeet deposited 1000. New balance: 6000

account.withdraw(2000);
// Gurjeet withdrew 2000. New balance: 4000

account.withdraw(10000);
// Insufficient balance
</code></pre>
<p>The logic for how deposits and withdrawals work lives inside the class. Anyone using this class just calls <code>deposit()</code> or <code>withdraw()</code> without needing to know how the balance is being calculated internally. That is encapsulation in action.</p>
<hr />
<h2>Why OOP Matters</h2>
<p>When we are writing small programs, OOP might feel like extra work. But as our programs grow, the benefits become obvious.</p>
<p>Instead of having random variables and functions spread everywhere, everything is organised into classes that represent real things in our program. A <code>User</code>, a <code>Product</code>, an <code>Order</code>, a <code>Cart</code>. Each one has its own data and its own behaviour. When something breaks, we know exactly where to look.</p>
<p>OOP also makes code reusable. We write the <code>Student</code> class once and create as many student objects as we need. Any change to the class automatically applies to all objects created from it.</p>
<p>This is the thinking behind how most real JavaScript applications, especially those built with frameworks like React, are structured. Getting comfortable with classes, constructors, methods, and the concept of encapsulation is a solid step towards writing code that is clean, organised, and built to scale.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Objects in JavaScript]]></title><description><![CDATA[We have all filled out a form at some point. A school admission form, a job application, a signup page. What does it ask for? Your name, your age, your city, your course. Multiple pieces of informatio]]></description><link>https://blog.gurjeet.tech/understanding-objects-in-javascript</link><guid isPermaLink="true">https://blog.gurjeet.tech/understanding-objects-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Cohort2026]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:46:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/6c8203dd-66f4-424a-935f-c4cbc7f8a48e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We have all filled out a form at some point. A school admission form, a job application, a signup page. What does it ask for? Your name, your age, your city, your course. Multiple pieces of information, all describing one single person.</p>
<p>Now imagine trying to store all of that in JavaScript using what we know so far. We could use separate variables:</p>
<pre><code class="language-javascript">let name = "Gurjeet";
let age = 22;
let course = "Web Development";
let city = "Amritsar";
</code></pre>
<p>This works for one person. But the moment we need to handle ten students, or a hundred, this approach falls apart completely. There is no connection between these variables. Nothing groups them together and says "these four things all belong to the same person."</p>
<p>That is exactly the problem objects solve.</p>
<hr />
<h2>What is an Object?</h2>
<p>An object in JavaScript is a way to group related data together under one name. Instead of storing values by position, objects store values by name. Each value gets a label, and that label tells us exactly what the value means.</p>
<p>That label is called a key, and the data it points to is called a value. Together, they form a key-value pair. An object is just a collection of these key-value pairs.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  course: "Web Development",
  city: "Amritsar"
};
</code></pre>
<p>Now every piece of data has a name attached to it. <code>name</code>, <code>age</code>, <code>course</code>, and <code>city</code> are the keys. <code>"Gurjeet"</code>, <code>22</code>, <code>"Web Development"</code>, and <code>"Amritsar"</code> are the values. Each key-value pair is called a property of the object.</p>
<p>Anyone reading this code immediately understands what each value represents. That clarity is what makes objects so useful.</p>
<hr />
<h2>Accessing Properties</h2>
<p>There are two ways to access the properties of an object: dot notation and bracket notation.</p>
<p><strong>Dot notation</strong> is the one we will use most of the time. We write the object name, followed by a dot, followed by the key.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  course: "Web Development"
};

console.log(student.name);   // Gurjeet
console.log(student.age);    // 22
console.log(student.course); // Web Development
</code></pre>
<p><strong>Bracket notation</strong> works the same way, but we pass the key as a string inside square brackets.</p>
<pre><code class="language-javascript">console.log(student["name"]);   // Gurjeet
console.log(student["course"]); // Web Development
</code></pre>
<p>Both give the same result. Dot notation is cleaner and more commonly used. Bracket notation becomes useful when the key is stored in a variable or when the key has spaces in it.</p>
<pre><code class="language-javascript">let key = "age";
console.log(student[key]); // 22
</code></pre>
<p>Here we stored the key name in a variable and used bracket notation to access the property dynamically. This is something we cannot do with dot notation.</p>
<hr />
<h2>Updating Object Properties</h2>
<p>Updating a property works exactly like creating one. We just assign a new value to an existing key.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  course: "Web Development"
};

student.age = 23;
student.course = "Full Stack Development";

console.log(student.age);    // 23
console.log(student.course); // Full Stack Development
</code></pre>
<p>We targeted the key using dot notation and assigned a new value. The rest of the object stays exactly as it was.</p>
<hr />
<h2>Adding and Deleting Properties</h2>
<p>We are not limited to the properties we define when we first create an object. We can add new ones at any time.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22
};

student.city = "Amritsar";
student.isEnrolled = true;

console.log(student);
// { name: "Gurjeet", age: 22, city: "Amritsar", isEnrolled: true }
</code></pre>
<p>We simply assigned a value to a key that did not exist before, and JavaScript added it to the object automatically.</p>
<p>To remove a property, we use the <code>delete</code> keyword.</p>
<pre><code class="language-javascript">delete student.isEnrolled;

console.log(student);
// { name: "Gurjeet", age: 22, city: "Amritsar" }
</code></pre>
<p>The <code>isEnrolled</code> property is gone. The rest of the object remains untouched.</p>
<hr />
<h2>Arrays vs Objects</h2>
<p>A question that comes up naturally at this stage is: when do we use an object and when do we use something else to store data?</p>
<p>The clearest way to think about it is this. When we have a list of similar items where order matters, we use an array. When we are describing a single thing with multiple different characteristics, we use an object.</p>
<p>A list of city names is a collection of similar items. A single person with a name, age, and city is one thing with multiple characteristics.</p>
<pre><code class="language-javascript">// A list of cities — order matters, items are similar
let cities = ["Amritsar", "Delhi", "Mumbai", "Bangalore"];

// A single person — multiple characteristics describing one thing
let person = {
  name: "Gurjeet",
  age: 22,
  city: "Amritsar"
};
</code></pre>
<p>In real programs, these two are often combined. An array of objects is one of the most common patterns in JavaScript.</p>
<pre><code class="language-javascript">let students = [
  { name: "Gurjeet", age: 22 },
  { name: "Priya", age: 21 },
  { name: "Rahul", age: 23 }
];

console.log(students[0].name); // Gurjeet
console.log(students[1].age);  // 21
</code></pre>
<p>We access the array element using its index, then access the object property using dot notation. This pattern shows up constantly in real JavaScript projects, especially when working with data coming from a server or an API.</p>
<hr />
<h2>Looping Through Object Keys</h2>
<p>Sometimes we want to go through all the properties of an object and do something with each one. The <code>for...in</code> loop is built exactly for this purpose.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  course: "Web Development",
  city: "Amritsar"
};

for (let key in student) {
  console.log(key + ": " + student[key]);
}

// Output:
// name: Gurjeet
// age: 22
// course: Web Development
// city: Amritsar
</code></pre>
<p>On each iteration, <code>key</code> holds the name of the current property. We use bracket notation with <code>student[key]</code> to get its value because the key is stored in a variable, and dot notation does not work with variables.</p>
<p>This becomes very practical whenever we want to display all the details of an object, check what properties exist, or process each value one by one without hardcoding every key manually.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[The Magic of this, call(), apply(), and bind() in JavaScript]]></title><description><![CDATA[There is a keyword in JavaScript that confuses almost every beginner the first time they run into it. That keyword is this. It shows up everywhere, it behaves differently depending on where it is used]]></description><link>https://blog.gurjeet.tech/the-magic-of-this-call-apply-and-bind-in-javascript</link><guid isPermaLink="true">https://blog.gurjeet.tech/the-magic-of-this-call-apply-and-bind-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Cohort2026]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:44:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/07c9fe2d-c9f9-4742-8fc6-5b5cd1a1f15b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There is a keyword in JavaScript that confuses almost every beginner the first time they run into it. That keyword is <code>this</code>. It shows up everywhere, it behaves differently depending on where it is used, and the error messages it produces when something goes wrong are not always the most helpful.</p>
<p>Once we understand <code>this</code> properly though, and once we see how <code>call()</code>, <code>apply()</code>, and <code>bind()</code> work alongside it, a lot of JavaScript code that previously looked confusing starts to make complete sense.</p>
<hr />
<h2>What Does <code>this</code> Mean?</h2>
<p>The simplest way to think about <code>this</code> is this: it refers to whoever is calling the function at that moment.</p>
<p>It is not fixed. It does not always point to the same thing. It changes based on the context in which a function is called. That is what makes it tricky at first, but also what makes it powerful once we get the hang of it.</p>
<p>Let's start with the most common place we see <code>this</code>, inside an object.</p>
<hr />
<h2><code>this</code> Inside an Object</h2>
<p>When a function is defined inside an object and called on that object, <code>this</code> refers to that object.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  introduce: function() {
    console.log("My name is " + this.name + " and I am " + this.age + " years old");
  }
};

student.introduce();
// My name is Gurjeet and I am 22 years old
</code></pre>
<p>When we call <code>student.introduce()</code>, JavaScript sets <code>this</code> to <code>student</code> because <code>student</code> is the one calling the function. So <code>this.name</code>becomes <code>student.name</code>, which is <code>"Gurjeet"</code>.</p>
<p>Now let's create another object and see what happens:</p>
<pre><code class="language-javascript">let teacher = {
  name: "Mr. Singh",
  age: 35,
  introduce: function() {
    console.log("My name is " + this.name + " and I am " + this.age + " years old");
  }
};

teacher.introduce();
// My name is Mr. Singh and I am 35 years old
</code></pre>
<p>Same function structure, different object, different result. <code>this</code> adapts to whoever is calling it. That is the core behaviour to understand.</p>
<hr />
<h2>The Problem <code>this</code> Creates</h2>
<p>Here is where things get interesting. What if we have a function on one object but we want to use it on a different object that does not have that function?</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  age: 22,
  introduce: function() {
    console.log("My name is " + this.name + " and I am " + this.age);
  }
};

let anotherStudent = {
  name: "Priya",
  age: 21
};
</code></pre>
<p><code>anotherStudent</code> does not have an <code>introduce</code> method. We could copy the function over, but that is repetitive and messy. This is exactly the problem that <code>call()</code>, <code>apply()</code>, and <code>bind()</code> solve.</p>
<hr />
<h2>call()</h2>
<p><code>call()</code> lets us borrow a function from one object and use it on another. We call the function and explicitly tell JavaScript what <code>this</code> should be.</p>
<pre><code class="language-javascript">student.introduce.call(anotherStudent);
// My name is Priya and I am 21
</code></pre>
<p>We took the <code>introduce</code> function from <code>student</code> and called it with <code>anotherStudent</code> as the context. JavaScript set <code>this</code> to <code>anotherStudent</code>for that call, so <code>this.name</code> became <code>"Priya"</code> and <code>this.age</code> became <code>21</code>.</p>
<p>We can also pass additional arguments after the object:</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  greet: function(city, course) {
    console.log("Hi, I am " + this.name + " from " + city + ", studying " + course);
  }
};

let anotherStudent = { name: "Priya" };

student.greet.call(anotherStudent, "Delhi", "Design");
// Hi, I am Priya from Delhi, studying Design
</code></pre>
<p>The first argument to <code>call()</code> is always the object we want <code>this</code> to be. Everything after that gets passed as regular arguments to the function.</p>
<hr />
<h2>apply()</h2>
<p><code>apply()</code> works exactly like <code>call()</code>. The only difference is how we pass the arguments. With <code>call()</code> we pass them one by one. With <code>apply()</code> we pass them as an array.</p>
<pre><code class="language-javascript">student.greet.apply(anotherStudent, ["Delhi", "Design"]);
// Hi, I am Priya from Delhi, studying Design
</code></pre>
<p>Same result as before. The difference is purely in the syntax. <code>call()</code> takes individual arguments separated by commas. <code>apply()</code>takes a single array containing all the arguments.</p>
<p>A practical way to remember this: <strong>c</strong>all uses <strong>c</strong>ommas, <strong>a</strong>pply uses an <strong>a</strong>rray.</p>
<p>When would we actually use <code>apply()</code> over <code>call()</code>? When our arguments are already sitting in an array and we do not want to unpack them manually.</p>
<pre><code class="language-javascript">let args = ["Mumbai", "Full Stack Development"];

student.greet.apply(anotherStudent, args);
// Hi, I am Priya from Mumbai, studying Full Stack Development
</code></pre>
<hr />
<h2>bind()</h2>
<p><code>bind()</code> is a little different from <code>call()</code> and <code>apply()</code>. Instead of calling the function immediately, <code>bind()</code> returns a new function with <code>this</code> permanently set to whatever we specify. We can then call that new function whenever we want.</p>
<pre><code class="language-javascript">let student = {
  name: "Gurjeet",
  introduce: function() {
    console.log("My name is " + this.name);
  }
};

let anotherStudent = { name: "Priya" };

let priyanIntroduce = student.introduce.bind(anotherStudent);

priyanIntroduce();
// My name is Priya
</code></pre>
<p>We used <code>bind()</code> to create a new function called <code>priyanIntroduce</code> where <code>this</code> is permanently set to <code>anotherStudent</code>. Now we can call <code>priyanIntroduce()</code> anywhere in our code and it will always use <code>anotherStudent</code> as the context.</p>
<p>This is useful when we want to pass a function around, store it for later use, or use it as a callback, but we need to make sure it always runs with the right <code>this</code>.</p>
<hr />
<h2>call vs apply vs bind</h2>
<p>All three let us control what <code>this</code> is inside a function. The difference is in how and when they execute:</p>
<p><code>call()</code> runs the function immediately and accepts arguments one by one.</p>
<p><code>apply()</code> runs the function immediately and accepts arguments as an array.</p>
<p><code>bind()</code> does not run the function immediately. It returns a new function with <code>this</code> locked in, ready to be called later.</p>
<pre><code class="language-javascript">let person = {
  name: "Gurjeet",
  sayHello: function(greeting, punctuation) {
    console.log(greeting + ", I am " + this.name + punctuation);
  }
};

let anotherPerson = { name: "Priya" };

// call — runs immediately, arguments one by one
person.sayHello.call(anotherPerson, "Hello", "!");
// Hello, I am Priya!

// apply — runs immediately, arguments as array
person.sayHello.apply(anotherPerson, ["Hey", "."]);
// Hey, I am Priya.

// bind — returns new function, call it later
let boundFn = person.sayHello.bind(anotherPerson, "Hi", "...");
boundFn();
// Hi, I am Priya...
</code></pre>
<hr />
<h2>Why This Actually Matters</h2>
<p>At first glance, <code>call()</code>, <code>apply()</code>, and <code>bind()</code> might feel like edge case tools. But they show up regularly in real JavaScript development. Borrowing methods between objects, setting the correct context for event handlers, working with callbacks, all of these situations involve controlling what <code>this</code> points to.</p>
<p>Understanding <code>this</code> and having these three tools in our toolkit means we are no longer guessing why a function is returning <code>undefined</code> for a property that clearly exists. We know exactly what <code>this</code> is, and we know how to change it when we need to.</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Arrays 101]]></title><description><![CDATA[Let's say we want to store the names of five students in our program. Without arrays, we would do something like this:
let student1 = "Gurjeet";
let student2 = "Priya";
let student3 = "Rahul";
let stu]]></description><link>https://blog.gurjeet.tech/javascript-arrays-101</link><guid isPermaLink="true">https://blog.gurjeet.tech/javascript-arrays-101</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Cohort2026]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:38:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/5c109fc7-d3d9-4ef0-a6e4-8244a356fed5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let's say we want to store the names of five students in our program. Without arrays, we would do something like this:</p>
<pre><code class="language-javascript">let student1 = "Gurjeet";
let student2 = "Priya";
let student3 = "Rahul";
let student4 = "Sneha";
let student5 = "Arjun";
</code></pre>
<p>That works for five students. But what about fifty? Or five hundred? We cannot create a separate variable for every single value. That is where arrays come in.</p>
<p>An array is a way to store multiple values in a single variable, in a specific order. Instead of five separate variables, we get one clean list.</p>
<pre><code class="language-javascript">let students = ["Gurjeet", "Priya", "Rahul", "Sneha", "Arjun"];
</code></pre>
<p>One variable, five values, all organised in order. That is the core idea behind arrays.</p>
<hr />
<h2>How to Create an Array</h2>
<p>Creating an array in JavaScript is straightforward. We use square brackets and separate each value with a comma.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

let marks = [85, 92, 76, 88];

let mixed = ["Gurjeet", 22, true]; // arrays can hold different data types too
</code></pre>
<p>An array can hold strings, numbers, booleans, or even a mix of all of them. Each value inside an array is called an element.</p>
<hr />
<h2>Accessing Elements Using Index</h2>
<p>Every element in an array has a position, and that position is called an index. The important thing to know here is that arrays in JavaScript are zero-indexed. That means the counting starts from 0, not 1.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

//               0         1        2
</code></pre>
<p>So if we want to access the first element, we use index 0. The second element is at index 1, and so on.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

console.log(fruits[0]); // apple
console.log(fruits[1]); // banana
console.log(fruits[2]); // mango
</code></pre>
<p>This trips up almost every beginner at least once. We naturally think of the first item as number 1, but in JavaScript it is always number 0. The sooner that becomes second nature, the better.</p>
<p>What happens if we try to access an index that does not exist?</p>
<pre><code class="language-javascript">console.log(fruits[5]); // undefined
</code></pre>
<p>JavaScript does not throw an error. It simply returns <code>undefined</code> because there is nothing at that position.</p>
<hr />
<h2>Updating Elements</h2>
<p>Accessing an element and updating it follow the same logic. We use the index to target the position and assign a new value.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

fruits[1] = "grapes"; // replacing "banana" with "grapes"

console.log(fruits); // ["apple", "grapes", "mango"]
</code></pre>
<p>We targeted index 1, which was <code>"banana"</code>, and replaced it with <code>"grapes"</code>. The rest of the array stays exactly as it was.</p>
<hr />
<h2>The length Property</h2>
<p>Every array has a built-in property called <code>length</code> that tells us how many elements are in it.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

console.log(fruits.length); // 3
</code></pre>
<p>This is more useful than it sounds. We use <code>length</code> constantly when looping through arrays, checking if an array is empty, or finding the last element.</p>
<p>Speaking of the last element, here is a neat trick. Since the last index is always one less than the total length, we can always access it like this:</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

console.log(fruits[fruits.length - 1]); // mango
</code></pre>
<p>This works no matter how many elements are in the array. Whether there are 3 items or 300, <code>fruits.length - 1</code> will always point to the last one.</p>
<hr />
<h2>Looping Over an Array</h2>
<p>Most of the time, we do not just want to access one element. We want to go through the entire array and do something with each item. That is where loops come in.</p>
<p>The most basic way is a <code>for</code> loop:</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

for (let i = 0; i &lt; fruits.length; i++) {
  console.log(fruits[i]);
}

// Output:
// apple
// banana
// mango
</code></pre>
<p>Let's break down what is happening here. We start <code>i</code> at 0 because that is the first index. We keep going as long as <code>i</code> is less than <code>fruits.length</code>, which is 3. Each time the loop runs, we access <code>fruits[i]</code> and print it, then increase <code>i</code> by 1.</p>
<p>So the loop runs three times, once for index 0, once for index 1, and once for index 2, printing each fruit along the way.</p>
<p>A cleaner and more modern way to loop over an array is <code>for...of</code>:</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

for (let fruit of fruits) {
  console.log(fruit);
}

// Output:
// apple
// banana
// mango
</code></pre>
<p>The <code>for...of</code> loop handles all the index tracking behind the scenes. We just get each element directly, one at a time. When we do not need the index number and just want to work with the values, <code>for...of</code> is the cleaner choice.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Function Declaration vs Function Expression: What's the Difference?]]></title><description><![CDATA[At some point while learning JavaScript, we all write our first function and feel pretty good about it. But then we start seeing functions written in a completely different way in tutorials, open sour]]></description><link>https://blog.gurjeet.tech/function-declaration-vs-function-expression-what-s-the-difference</link><guid isPermaLink="true">https://blog.gurjeet.tech/function-declaration-vs-function-expression-what-s-the-difference</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Cohort2026]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:34:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/2fad182e-adc4-4489-8238-ec10b9c3977a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>At some point while learning JavaScript, we all write our first function and feel pretty good about it. But then we start seeing functions written in a completely different way in tutorials, open source code, or someone else's project. Same concept, different syntax, and suddenly we are confused about which one to use and why.</p>
<p>That is exactly what this post is about. Let's clear it up once and for all.</p>
<hr />
<h2>What is a Function and Why Do We Need It?</h2>
<p>Before we get into the two types, let's make sure we are on the same page about what a function actually is.</p>
<p>A function is a reusable block of code that does a specific job. Instead of writing the same logic five times in different places, we write it once inside a function and call it whenever we need it.</p>
<p>Think of it like a recipe. We write the recipe once. Every time we want to make that dish, we just follow the same recipe. We do not rewrite it from scratch each time.</p>
<pre><code class="language-javascript">function greet(name) {
  console.log("Hello, " + name);
}

greet("Gurjeet"); // Hello, Gurjeet
greet("Priya");   // Hello, Priya
</code></pre>
<p>Same function, called twice, different results each time. That is the whole point.</p>
<hr />
<h2>Function Declaration</h2>
<p>A function declaration is the most straightforward way to define a function. We use the <code>function</code> keyword, give it a name, and write the body.</p>
<pre><code class="language-javascript">function multiply(a, b) {
  return a * b;
}

console.log(multiply(3, 4)); // 12
</code></pre>
<p>That is it. This is called a function declaration because we are declaring a function with a name right from the start.</p>
<hr />
<h2>Function Expression</h2>
<p>A function expression is when we create a function and assign it to a variable. The function itself has no name of its own. It lives inside the variable.</p>
<pre><code class="language-javascript">const multiply = function(a, b) {
  return a * b;
};

console.log(multiply(3, 4)); // 12
</code></pre>
<p>The result is exactly the same. The difference is just in how we wrote it. Here the function is treated as a value, just like a number or a string, and stored inside a variable called <code>multiply</code>.</p>
<p>Let's put both side by side:</p>
<pre><code class="language-javascript">// Function Declaration
function add(a, b) {
  return a + b;
}

// Function Expression
const add = function(a, b) {
  return a + b;
};
</code></pre>
<p>Both do the same job. The syntax is just different.</p>
<hr />
<h2>The Key Difference: Hoisting</h2>
<p>This is where things get interesting, and also where the real practical difference between the two lies.</p>
<p>JavaScript does something called hoisting before it runs our code. In simple terms, it reads through the entire file first and moves certain things to the top in memory before executing anything.</p>
<p>Function declarations get hoisted. This means we can actually call a function declaration before we have even written it in our code, and it will work fine.</p>
<pre><code class="language-javascript">console.log(greet("Gurjeet")); // Hello, Gurjeet

function greet(name) {
  return "Hello, " + name;
}
</code></pre>
<p>JavaScript already knew about <code>greet</code> before reaching that line because the declaration got hoisted to the top.</p>
<p>Function expressions do not get hoisted the same way. If we try to call a function expression before we define it, we get an error.</p>
<pre><code class="language-javascript">console.log(greet("Gurjeet")); // Error: Cannot access 'greet' before initialization

const greet = function(name) {
  return "Hello, " + name;
};
</code></pre>
<p>The variable <code>greet</code> exists in memory, but the function has not been assigned to it yet at that point. So JavaScript does not know what we are trying to call.</p>
<p>For now, the simple takeaway is this: with function declarations, the order does not matter as much. With function expressions, we must define them before we use them.</p>
<hr />
<h2>When to Use Which One</h2>
<p>Both are valid and both have their place. Here is a practical way to think about it.</p>
<p>Function declarations work well for the main, named functions in our program. Things like <code>calculateTotal</code>, <code>getUserData</code>, or <code>sendEmail</code>. Functions that are central to what our code does and might be called from multiple places.</p>
<pre><code class="language-javascript">function calculateTotal(price, tax) {
  return price + (price * tax);
}
</code></pre>
<p>Function expressions are great when we want to assign a function to a variable, pass it to another function, or define it as part of an object. They treat the function as a value, which makes them very flexible.</p>
<pre><code class="language-javascript">const calculateTotal = function(price, tax) {
  return price + (price * tax);
};
</code></pre>
<p>In modern JavaScript, function expressions are often written as arrow functions, which we covered in the last post:</p>
<pre><code class="language-javascript">const calculateTotal = (price, tax) =&gt; price + (price * tax);
</code></pre>
<p>Same idea, shorter syntax.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Arrow Functions in JavaScript: A Simpler Way to Write Functions]]></title><description><![CDATA[When we first learn functions in JavaScript, we write them the traditional way. It works perfectly fine. But as we start reading more modern JavaScript code, we keep seeing this shorter, cleaner synta]]></description><link>https://blog.gurjeet.tech/arrow-functions-in-javascript-a-simpler-way-to-write-functions</link><guid isPermaLink="true">https://blog.gurjeet.tech/arrow-functions-in-javascript-a-simpler-way-to-write-functions</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Cohort2026]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:30:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/af3a5bad-dd3c-41b1-913b-5d7ef36c7bdf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we first learn functions in JavaScript, we write them the traditional way. It works perfectly fine. But as we start reading more modern JavaScript code, we keep seeing this shorter, cleaner syntax everywhere. That is the arrow function, and once we understand it, we will wonder how we ever lived without it.</p>
<hr />
<h2>The Normal Function</h2>
<p>Before we get into arrow functions, let's look at how we write a regular function so we have something to compare against.</p>
<pre><code class="language-javascript">function greet(name) {
  return "Hello, " + name;
}

console.log(greet("Gurjeet")); // Hello, Gurjeet
</code></pre>
<p>This works perfectly. But arrow functions let us write the same thing with much less code.</p>
<hr />
<h2>Basic Arrow Function Syntax</h2>
<p>Here is the same <code>greet</code> function written as an arrow function:</p>
<pre><code class="language-javascript">const greet = (name) =&gt; {
  return "Hello, " + name;
};

console.log(greet("Gurjeet")); // Hello, Gurjeet
</code></pre>
<p>The <code>function</code> keyword is gone. Instead, we have the parameters in parentheses, followed by <code>=&gt;</code> which is the arrow, and then the function body inside curly braces. That <code>=&gt;</code> is why these are called arrow functions.</p>
<p>Let's put both side by side so the difference is easy to see:</p>
<pre><code class="language-javascript">// Normal function
function add(a, b) {
  return a + b;
}

// Arrow function
const add = (a, b) =&gt; {
  return a + b;
};
</code></pre>
<p>Same result, just written differently. The arrow function version is shorter and in modern JavaScript codebases, this is the style we will see most often.</p>
<hr />
<h2>Arrow Function with One Parameter</h2>
<p>When our arrow function has only one parameter, we can remove the parentheses around it. This makes it even shorter.</p>
<pre><code class="language-javascript">// With parentheses — works fine
const double = (num) =&gt; {
  return num * 2;
};

// Without parentheses — also fine when there's only one parameter
const double = num =&gt; {
  return num * 2;
};

console.log(double(5)); // 10
</code></pre>
<p>Both versions work. It is just a matter of preference, though most developers skip the parentheses when there is only one parameter.</p>
<hr />
<h2>Arrow Function with Multiple Parameters</h2>
<p>When there are two or more parameters, the parentheses are required.</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; {
  return a * b;
};

console.log(multiply(4, 3)); // 12
</code></pre>
<p>No shortcut here. Multiple parameters always need the parentheses.</p>
<hr />
<h2>Implicit Return</h2>
<p>This is where arrow functions get really interesting. When our function body has just a single return statement, we can remove the curly braces and the <code>return</code> keyword entirely. JavaScript will return the value automatically. This is called an implicit return.</p>
<pre><code class="language-javascript">// With explicit return
const square = (num) =&gt; {
  return num * num;
};

// With implicit return — same result, much shorter
const square = num =&gt; num * num;

console.log(square(4)); // 16
</code></pre>
<p>The moment we remove the curly braces, JavaScript assumes we want to return whatever is on that line. No need to type <code>return</code> at all.</p>
<p>Here is another example to make it clear:</p>
<pre><code class="language-javascript">const greet = name =&gt; "Hello, " + name;

console.log(greet("Gurjeet")); // Hello, Gurjeet
</code></pre>
<p>One line. Clean and readable. This is the style we will see constantly in real JavaScript projects.</p>
<hr />
<h2>Normal Function vs Arrow Function</h2>
<p>Here is a side by side comparison showing how the same function evolves from a normal function all the way to a clean arrow function with implicit return:</p>
<pre><code class="language-javascript">// Step 1: Normal function
function square(num) {
  return num * num;
}

// Step 2: Arrow function with explicit return
const square = (num) =&gt; {
  return num * num;
};

// Step 3: Arrow function with implicit return
const square = num =&gt; num * num;

console.log(square(6)); // 36
</code></pre>
<p>All three do exactly the same thing. As we get more comfortable with JavaScript, we will naturally move towards the shorter versions.</p>
<hr />
<h2>Arrow Functions Inside map()</h2>
<p>One place where arrow functions really shine is inside array methods like <code>map()</code> and <code>filter()</code>. Remember from the last post how we wrote <code>map()</code> with a regular function?</p>
<pre><code class="language-javascript">// With normal function
let numbers = [1, 2, 3, 4, 5];

let doubled = numbers.map(function(num) {
  return num * 2;
});
</code></pre>
<p>With an arrow function, the same thing becomes:</p>
<pre><code class="language-javascript">// With arrow function
let numbers = [1, 2, 3, 4, 5];

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

console.log(doubled); // [2, 4, 6, 8, 10]
</code></pre>
<p>One line. Same result. This is why arrow functions are so popular in modern JavaScript, they pair beautifully with array methods and make our code much easier to read.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Array Methods You Must Know]]></title><description><![CDATA[Imagine we have a list of students in a classroom. Sometimes we want to add a new student to the list. Sometimes we want to remove someone. Sometimes we want to go through the entire list and do somet]]></description><link>https://blog.gurjeet.tech/array-methods-you-must-know</link><guid isPermaLink="true">https://blog.gurjeet.tech/array-methods-you-must-know</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Cohort2026]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:10:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/661b4046-f53d-4b2a-8549-119893ed9be5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine we have a list of students in a classroom. Sometimes we want to add a new student to the list. Sometimes we want to remove someone. Sometimes we want to go through the entire list and do something with each name. We do all of this manually in real life, and JavaScript gives us built-in tools to do the same thing with arrays. These tools are called array methods.</p>
<p>Let's go through the ones we will use most often.</p>
<hr />
<h2>push() and pop()</h2>
<p>These two methods work on the end of an array.</p>
<p><code>push()</code> adds one or more items to the end of an array.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana"];

fruits.push("mango");

console.log(fruits); // ["apple", "banana", "mango"]
</code></pre>
<p><code>pop()</code> removes the last item from an array and returns it.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

let removed = fruits.pop();

console.log(removed); // "mango"
console.log(fruits);  // ["apple", "banana"]
</code></pre>
<p>Think of it like a stack of plates. We add a plate on top with <code>push()</code> and take the top plate off with <code>pop()</code>.</p>
<hr />
<h2>shift() and unshift()</h2>
<p>These two do the same thing as <code>push()</code> and <code>pop()</code>, but they work on the beginning of the array instead of the end.</p>
<p><code>unshift()</code> adds one or more items to the front of an array.</p>
<pre><code class="language-javascript">let fruits = ["banana", "mango"];

fruits.unshift("apple");

console.log(fruits); // ["apple", "banana", "mango"]
</code></pre>
<p><code>shift()</code> removes the first item from an array and returns it.</p>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

let first = fruits.shift();

console.log(first);  // "apple"
console.log(fruits); // ["banana", "mango"]
</code></pre>
<p>A simple way to remember this: <code>push</code> and <code>pop</code> touch the end. <code>unshift</code> and <code>shift</code> touch the beginning.</p>
<hr />
<h2>forEach()</h2>
<p><code>forEach()</code> goes through every item in an array and runs a function on each one. It is the cleaner alternative to writing a traditional <code>for</code> loop when we just want to do something with each item.</p>
<p>With a regular for loop, it looks like this:</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4, 5];

for (let i = 0; i &lt; numbers.length; i++) {
  console.log(numbers[i]);
}
</code></pre>
<p>With <code>forEach()</code>, the same thing looks like this:</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4, 5];

numbers.forEach(function(num) {
  console.log(num);
});

// Output: 1, 2, 3, 4, 5
</code></pre>
<p>Both do the same job. <code>forEach()</code> is just easier to read and write once we get comfortable with it.</p>
<hr />
<h2>map()</h2>
<p><code>map()</code> is one of the most useful array methods we will come across. It goes through every item in an array, does something to each one, and returns a brand new array with the updated values. The original array stays untouched.</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4, 5];

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

console.log(doubled);  // [2, 4, 6, 8, 10]
console.log(numbers);  // [1, 2, 3, 4, 5] — original unchanged
</code></pre>
<p>Think of it like a machine on a production line. Items go in one side, get transformed, and come out the other side as something new. The raw materials do not disappear, we just get a new output.</p>
<p>The key difference between <code>forEach()</code> and <code>map()</code> is this: <code>forEach()</code> just loops and does something. <code>map()</code> loops, transforms, and gives us back a new array.</p>
<hr />
<h2>filter()</h2>
<p><code>filter()</code> goes through an array and returns a new array containing only the items that pass a condition we define. Everything that does not pass the condition gets left out.</p>
<pre><code class="language-javascript">let numbers = [3, 7, 12, 5, 18, 2];

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

console.log(greaterThanTen); // [12, 18]
</code></pre>
<p>The original array stays as it is. We just get a new filtered version back.</p>
<p>A real world way to picture it: imagine we have a list of job applicants and we only want to keep those with more than 2 years of experience. We run the list through a filter, and get back only the ones that qualify.</p>
<pre><code class="language-javascript">let applicants = [
  { name: "Arjun", experience: 1 },
  { name: "Priya", experience: 3 },
  { name: "Rahul", experience: 5 },
  { name: "Sneha", experience: 2 },
];

let qualified = applicants.filter(function(person) {
  return person.experience &gt; 2;
});

console.log(qualified);
// [{ name: "Priya", experience: 3 }, { name: "Rahul", experience: 5 }]
</code></pre>
<hr />
<h2>reduce()</h2>
<p><code>reduce()</code> is a bit different from the others. Instead of returning a new array, it reduces the entire array down to a single value. The most common use case is calculating a total.</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4, 5];

let total = numbers.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0);

console.log(total); // 15
</code></pre>
<p>Here is what is happening step by step. We start with <code>0</code> as the initial value, which is the <code>accumulator</code>. Then for each item in the array, we add the current item to the accumulator and carry the result forward. By the end, the accumulator holds the final total.</p>
<p>For now, just focus on the pattern: <code>reduce()</code> takes all the items in an array and combines them into one single result. We will use it most often for summing up numbers.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[JavaScript Operators: The Basics You Need to Know]]></title><description><![CDATA[We do math every day without thinking about it. We split a bill, calculate how much change we should get, or figure out if we have enough balance before making a purchase. All of that involves operato]]></description><link>https://blog.gurjeet.tech/javascript-operators-the-basics-you-need-to-know</link><guid isPermaLink="true">https://blog.gurjeet.tech/javascript-operators-the-basics-you-need-to-know</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:05:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/196c7d89-897b-459c-be9a-fc471a912192.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We do math every day without thinking about it. We split a bill, calculate how much change we should get, or figure out if we have enough balance before making a purchase. All of that involves operators, and JavaScript works the same way.</p>
<p>Operators are symbols that let us perform operations on values and variables. That is really all they are. Let's go through each type one by one.</p>
<hr />
<h2>Arithmetic Operators</h2>
<p>These are the ones we are most familiar with. They do basic math.</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 (modulus)
</code></pre>
<p>The <code>%</code> operator is the one that confuses beginners the most. It does not give us the result of division. It gives us the remainder. So <code>10 % 3</code> is <code>1</code> because 3 goes into 10 three times, and 1 is left over. This operator is surprisingly useful once we start writing real programs.</p>
<hr />
<h2>Assignment Operators</h2>
<p>We have already been using the most basic assignment operator without thinking about it. The <code>=</code> sign does not mean "is equal to" in JavaScript. It means "assign this value to this variable."</p>
<pre><code class="language-javascript">let score = 0; // assign 0 to score
</code></pre>
<p>But there are shorter ways to update a variable's value:</p>
<pre><code class="language-javascript">let score = 10;

score += 5;  // same as: score = score + 5 → 15
score -= 3;  // same as: score = score - 3 → 12
score *= 2;  // same as: score = score * 2 → 24
score /= 4;  // same as: score = score / 4 → 6
</code></pre>
<p>These are just shortcuts. Instead of writing <code>score = score + 5</code>, we write <code>score += 5</code>. Both do the exact same thing. Once we get used to them, they feel very natural.</p>
<hr />
<h2>Comparison Operators</h2>
<p>Comparison operators compare two values and always return either <code>true</code> or <code>false</code>. We use them constantly when writing conditions.</p>
<pre><code class="language-javascript">let age = 20;

console.log(age &gt; 18);  // true
console.log(age &lt; 18);  // false
console.log(age &gt;= 20); // true
console.log(age &lt;= 19); // false
</code></pre>
<p>Now the two that every beginner needs to understand properly: <code>==</code> and <code>===</code>.</p>
<pre><code class="language-javascript">console.log(5 == "5");  // true
console.log(5 === "5"); // false
</code></pre>
<p>Both are checking for equality, but they do it differently.</p>
<p><code>==</code> checks only the value. It does not care about the type, so it converts <code>"5"</code> (a string) to <code>5</code> (a number) behind the scenes before comparing. This is called type coercion, and it can lead to unexpected results.</p>
<p><code>===</code> checks both the value and the type. The number <code>5</code> and the string <code>"5"</code> are not the same type, so it returns <code>false</code>.</p>
<p>As a rule, always use <code>===</code> in our code. It is stricter and much more predictable.</p>
<pre><code class="language-javascript">console.log(5 != "5");  // false — loose inequality
console.log(5 !== "5"); // true  — strict inequality
</code></pre>
<p>Same idea applies for not-equal. Prefer <code>!==</code> over <code>!=</code> for the same reasons.</p>
<hr />
<h2>Logical Operators</h2>
<p>Logical operators let us combine multiple conditions together. There are three of them.</p>
<p><code>&amp;&amp;</code> means AND. Both conditions must be true for the result to be true.</p>
<pre><code class="language-javascript">let age = 22;
let hasID = true;

console.log(age &gt;= 18 &amp;&amp; hasID); // true
// both conditions are true, so the result is true
</code></pre>
<p><code>||</code> means OR. At least one condition needs to be true.</p>
<pre><code class="language-javascript">let isWeekend = false;
let isHoliday = true;

console.log(isWeekend || isHoliday); // true
// one of them is true, so the result is true
</code></pre>
<p><code>!</code> means NOT. It flips the value. <code>true</code> becomes <code>false</code> and <code>false</code> becomes <code>true</code>.</p>
<pre><code class="language-javascript">let isLoggedIn = false;

console.log(!isLoggedIn); // true
// we flipped false to true
</code></pre>
<p>We will use logical operators constantly once we start writing conditions and making decisions in our programs.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Control Flow in JavaScript: If, Else, and Switch Explained]]></title><description><![CDATA[Every single day, we make decisions. If it's raining, we carry an umbrella. If the chai is too hot, we wait. If it's a holiday, we sleep in. We are constantly checking conditions and choosing what to ]]></description><link>https://blog.gurjeet.tech/control-flow-in-javascript-if-else-and-switch-explained</link><guid isPermaLink="true">https://blog.gurjeet.tech/control-flow-in-javascript-if-else-and-switch-explained</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:01:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/cff8ec2d-cc2b-401f-a5bd-dfe8acc08bf6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Every single day, we make decisions. If it's raining, we carry an umbrella. If the chai is too hot, we wait. If it's a holiday, we sleep in. We are constantly checking conditions and choosing what to do based on the result.</p>
<p>Our code works the same way. Control flow is just the order in which our program makes decisions and executes code. And the tools JavaScript gives us for that are <code>if</code>, <code>else</code>, and <code>switch</code>.</p>
<hr />
<h2>The if Statement</h2>
<p>The <code>if</code> statement is the simplest form of decision making in JavaScript. It says: if this condition is true, run this block of code.</p>
<pre><code class="language-javascript">let marks = 75;

if (marks &gt;= 50) {
  console.log("Passed!");
}
// Output: Passed!
</code></pre>
<p>JavaScript checks the condition inside the parentheses. If it evaluates to <code>true</code>, the code inside the curly braces runs. If it is <code>false</code>, JavaScript skips that block entirely and moves on.</p>
<hr />
<h2>The if-else Statement</h2>
<p>What if we want something to happen when the condition is false as well? That is where <code>else</code> comes in.</p>
<pre><code class="language-javascript">let marks = 35;

if (marks &gt;= 50) {
  console.log("Passed!");
} else {
  console.log("Failed. Try again.");
}
// Output: Failed. Try again.
</code></pre>
<p>Think of it like this. We are at a gate. If we have a ticket, we get in. If we do not have a ticket, we are turned away. One condition, two possible outcomes.</p>
<hr />
<h2>The else if Ladder</h2>
<p>Sometimes two options are not enough. What if we want to check multiple conditions one after another? We use <code>else if</code> to build a ladder.</p>
<pre><code class="language-javascript">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 {
  console.log("Grade: F");
}
// Output: Grade: C
</code></pre>
<p>JavaScript goes through each condition from top to bottom. The moment it finds one that is true, it runs that block and skips everything else. If none of the conditions match, the final <code>else</code> acts as the fallback.</p>
<hr />
<h2>The switch Statement</h2>
<p>Now imagine we have one variable and we want to check it against many specific values. We could write a long <code>else if</code>ladder, but there is a cleaner way for situations like this.</p>
<pre><code class="language-javascript">let day = 3;

switch (day) {
  case 1:
    console.log("Monday");
    break;
  case 2:
    console.log("Tuesday");
    break;
  case 3:
    console.log("Wednesday");
    break;
  case 4:
    console.log("Thursday");
    break;
  default:
    console.log("Another day");
}
// Output: Wednesday
</code></pre>
<p>The <code>switch</code> statement takes a value and compares it against each <code>case</code>. When it finds a match, it runs that block of code.</p>
<p>Now notice the <code>break</code> keyword after each case. That is important. Without <code>break</code>, JavaScript does not stop after finding a match. It keeps running every case below it until it hits the end of the switch block. That behaviour is called fall-through and it causes bugs if we are not careful.</p>
<p>The <code>default</code> at the bottom is like the <code>else</code> in an if-else chain. It runs when none of the cases match.</p>
<hr />
<h2>When to Use switch vs if-else</h2>
<p>Both do the job of decision making, but they suit different situations.</p>
<p><code>if-else</code> is more flexible. We can check ranges, compare two different variables, or write any kind of condition inside it. When the logic is complex or the conditions are not simple equality checks, <code>if-else</code> is the right pick.</p>
<pre><code class="language-javascript">let age = 20;
let hasID = true;

if (age &gt;= 18 &amp;&amp; hasID) {
  console.log("Entry allowed");
} else {
  console.log("Entry not allowed");
}
</code></pre>
<p><code>switch</code> works best when we are comparing one variable against a list of fixed, specific values. It reads more cleanly in those situations and is easier to scan through.</p>
<pre><code class="language-javascript">let plan = "pro";

switch (plan) {
  case "free":
    console.log("You have 5GB storage");
    break;
  case "basic":
    console.log("You have 20GB storage");
    break;
  case "pro":
    console.log("You have 100GB storage");
    break;
  default:
    console.log("Unknown plan");
}
// Output: You have 100GB storage
</code></pre>
<p>A simple way to decide: if the condition is about checking a range or combining multiple variables, go with <code>if-else</code>. If we are checking one variable against a bunch of specific values, <code>switch</code> keeps things neat.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[When we meet someone new, what's the first thing we remember about them ? Their name. Maybe their age. Whether they're a student or working somewhere. We're storing information in our brain without ev]]></description><link>https://blog.gurjeet.tech/understanding-variables-and-data-types-in-javascript</link><guid isPermaLink="true">https://blog.gurjeet.tech/understanding-variables-and-data-types-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Sun, 15 Mar 2026 13:54:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/695230fdecc3e9c2374e19a7/f4143987-a64a-4f30-9ddf-bf55745cea3b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we meet someone new, what's the first thing we remember about them ? Their name. Maybe their age. Whether they're a student or working somewhere. We're storing information in our brain without even thinking about it.</p>
<p>That's exactly what variables do in JavaScript. They store information so our program can remember and use it later.</p>
<hr />
<h2>What is a Variable, and Why Do We Need It?</h2>
<p>Think of a variable like a labelled box. We write a name on the outside of the box, and put a value inside it. Whenever we need that value, we just refer to the box by its name.</p>
<p>Without variables, a program would have no memory at all. We couldn't save a user's name, track a score in a game, or remember whether someone is logged in. Variables are what make code actually useful.</p>
<pre><code class="language-javascript">let playerName = "Gurjeet";
// The box called "playerName" now holds "Gurjeet"

console.log(playerName); // Output: Gurjeet
</code></pre>
<hr />
<h2>How to Declare Variables: var, let, and const</h2>
<p>JavaScript gives us three keywords to create a variable. Think of them as three different types of boxes. Each one has slightly different rules.</p>
<h3>var — the old way</h3>
<p><code>var</code> was the original way to declare variables in JavaScript. It still works, but it has some quirky behaviour that can lead to confusing bugs in bigger codebases. Most modern JavaScript code avoids it.</p>
<pre><code class="language-javascript">var city = "Amritsar";
city = "Delhi"; // works fine, value gets updated
</code></pre>
<h3>let — for values that change</h3>
<p><code>let</code> is what we reach for when the value might need to change later. A score that updates as the game goes on, or a user's current status, that kind of thing.</p>
<pre><code class="language-javascript">let score = 0;
score = 10; // updated after the player earns points
</code></pre>
<h3>const — for values that stay fixed</h3>
<p><code>const</code> is short for constant. Once we assign a value to it, we cannot replace it. The app's name, a base URL, a tax rate, anything that is not supposed to change during the program.</p>
<pre><code class="language-javascript">const appName = "MyApp";
appName = "OtherApp"; // Error! Cannot reassign a const
</code></pre>
<p>A good rule to follow: default to <code>const</code>. If we know the value will need to change at some point, switch to <code>let</code>. And for now, just leave <code>var</code> alone.</p>
<hr />
<h2>Primitive Data Types</h2>
<p>Every value we store in a variable has a type. JavaScript has five basic types that we will work with constantly, and they are called primitive data types.</p>
<p><strong>String</strong> is for text. Any time we are dealing with words, names, or sentences, we wrap the value in quotes and it becomes a string.</p>
<pre><code class="language-javascript">let name = "Gurjeet"; // String
</code></pre>
<p><strong>Number</strong> covers any numeric value, whether it is a whole number or a decimal.</p>
<pre><code class="language-javascript">let age = 22;      // whole number
let price = 3.99;  // decimal
</code></pre>
<p><strong>Boolean</strong> can only ever be <code>true</code> or <code>false</code>. Think of it as a yes/no switch.</p>
<pre><code class="language-javascript">let isStudent = true;
let hasSubscription = false;
</code></pre>
<p><strong>Null</strong> means the box is intentionally empty. We are the ones who put nothing there on purpose.</p>
<pre><code class="language-javascript">let phoneNumber = null; // we know it's empty
</code></pre>
<p><strong>Undefined</strong> means the box exists but nobody told it what to hold yet.</p>
<pre><code class="language-javascript">let address; // no value assigned, so it's undefined
</code></pre>
<p>The difference between <code>null</code> and <code>undefined</code> trips almost everyone up at first. Here is the simplest way to think about it: <code>null</code>means "I know this is empty." <code>undefined</code> means "nobody even got around to filling this in yet." Small difference, but it matters once we start debugging real code.</p>
<pre><code class="language-javascript">let name = "Gurjeet";  // String
let age = 22;          // Number
let isStudent = true;  // Boolean
let phone = null;      // Null, intentionally empty
let address;           // Undefined, not assigned yet
</code></pre>
<hr />
<h2>var vs let vs const</h2>
<p>The biggest practical difference comes down to two things: can the value be changed, and where in the code can the variable be accessed.</p>
<p><code>var</code> can be reassigned and even re-declared, which sounds flexible but is actually what causes the bugs. <code>let</code> can be reassigned but not re-declared. <code>const</code> cannot be reassigned or re-declared at all.</p>
<p>The other difference is scope, which we are about to get into.</p>
<hr />
<h2>What is Scope?</h2>
<p>Scope answers one question: where in our code can a particular variable be accessed?</p>
<p>Here is a simple way to picture it. Think of our house. Whatever is inside our bedroom, like a personal diary, stays in our bedroom. Someone in the kitchen cannot just reach in and grab it. But something in the living room, like the television, is accessible to everyone in the house.</p>
<p>Variables work the same way. A variable declared inside a block of code, anything wrapped in <code>{ }</code>, can only be accessed within that block. That is called block scope, and it is the rule that both <code>let</code> and <code>const</code> follow.</p>
<pre><code class="language-javascript">let outsideVar = "I am outside";

{
  let insideVar = "I am inside the block";
  console.log(outsideVar); // works fine
  console.log(insideVar);  // works fine
}

console.log(outsideVar); // works fine
console.log(insideVar);  // Error, insideVar doesn't exist out here
</code></pre>
<p>This is exactly why <code>var</code> causes confusion. It does not respect block scope the same way. It leaks out of blocks, which means it can be accessed from places we never intended. That is a bug waiting to happen.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Getting Started with cURL]]></title><description><![CDATA[When we build software, websites, or APIs, one thing happens again and again:
our code needs to talk to a server.
A browser does this all the time without us noticing. But as developers, we also need ]]></description><link>https://blog.gurjeet.tech/getting-started-with-curl</link><guid isPermaLink="true">https://blog.gurjeet.tech/getting-started-with-curl</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Fri, 30 Jan 2026 06:03:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769752925622/cb2c4eee-a407-4cb3-873d-6e84f855949e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we build software, websites, or APIs, one thing happens again and again:</p>
<p>our code needs to talk to a server.</p>
<p>A browser does this all the time without us noticing. But as developers, we also need a direct way to send messages to servers and see their responses clearly. This is where cURL comes in.</p>
<p>In this blog, we will understand cURL from first principles. We will not rush into complex flags or advanced usage. We will first build the mental model, then slowly connect the dots.</p>
<hr />
<h2><strong>What Is a Server (and Why We Need to Talk to It)</strong></h2>
<p>Before understanding cURL, we need to understand what a server is.</p>
<p>A server is just another computer connected to the internet. Its job is to receive requests and send responses. When we open a website, submit a form, or load data in an app, we are talking to a server.</p>
<p>The server may send:</p>
<ul>
<li><p>A webpage (HTML)</p>
</li>
<li><p>Data (JSON)</p>
</li>
<li><p>Images</p>
</li>
<li><p>Or just a simple message like “OK” or “Error”</p>
</li>
</ul>
<p>As developers, we constantly need to:</p>
<ul>
<li><p>Check what a server is returning</p>
</li>
<li><p>Test APIs</p>
</li>
<li><p>Debug errors</p>
</li>
<li><p>Verify data</p>
</li>
</ul>
<p>For this, relying only on the browser is not enough.</p>
<hr />
<h2><strong>What Is cURL (in Very Simple Terms)</strong></h2>
<p>cURL is a tool that lets us send messages to a server from the terminal.</p>
<p>That’s it.</p>
<p>It does not have buttons.</p>
<p>It does not have a UI.</p>
<p>It does not hide anything.</p>
<p>It shows us:</p>
<ul>
<li><p>What request we send</p>
</li>
<li><p>What response we get back</p>
</li>
</ul>
<p>Think of cURL as a direct phone call to a server, instead of using a fancy app.</p>
<hr />
<h2><strong>Why Programmers Need cURL</strong></h2>
<p>Browsers do many things automatically:</p>
<ul>
<li><p>They add headers</p>
</li>
<li><p>They follow redirects</p>
</li>
<li><p>They cache responses</p>
</li>
<li><p>They hide raw data</p>
</li>
</ul>
<p>This is good for users, but not always good for learning or debugging.</p>
<p>With cURL, we:</p>
<ul>
<li><p>Talk directly to the server</p>
</li>
<li><p>See raw responses</p>
</li>
<li><p>Test APIs without writing code</p>
</li>
<li><p>Understand how HTTP really works</p>
</li>
</ul>
<p>This makes cURL extremely important for backend developers, frontend developers, and even DevOps engineers.</p>
<hr />
<h2><strong>Making Our First Request Using cURL</strong></h2>
<p>The simplest thing we can do with cURL is fetch a webpage.</p>
<p>When we run a basic cURL command, we are doing the same thing a browser does at a very basic level:</p>
<ul>
<li><p>Send a request</p>
</li>
<li><p>Receive a response</p>
</li>
<li><p>Print it on the screen</p>
</li>
</ul>
<p>There is no magic here. cURL sends a request to the server, and the server sends something back.</p>
<p>Seeing this response directly helps us understand what is really happening behind the scenes.</p>
<hr />
<h2><strong>Understanding Request and Response</strong></h2>
<p>Every communication with a server follows the same idea:</p>
<ol>
<li><p>A request is sent</p>
</li>
<li><p>A response is returned</p>
</li>
</ol>
<p>A request usually contains:</p>
<ul>
<li><p>Where we want to go (URL)</p>
</li>
<li><p>What we want to do (method like GET or POST)</p>
</li>
</ul>
<p>A response usually contains:</p>
<ul>
<li><p>A status (success or error)</p>
</li>
<li><p>Data (HTML, JSON, text, etc.)</p>
</li>
</ul>
<p>cURL lets us see this response clearly, without browser interference. This is one of its biggest learning advantages.</p>
<hr />
<h2><strong>Introducing GET and POST (Only the Basics)</strong></h2>
<p>To keep things simple, we only focus on two methods.</p>
<p>GET means:</p>
<ul>
<li><p>“We want to read data”</p>
</li>
<li><p>No changes on the server</p>
</li>
</ul>
<p>POST means:</p>
<ul>
<li><p>“We want to send data”</p>
</li>
<li><p>Something may be created or updated on the server</p>
</li>
</ul>
<p>Most APIs in the beginning can be understood using just these two methods. There is no need to overload ourselves early.</p>
<hr />
<h2><strong>Using cURL to Talk to APIs</strong></h2>
<p>An API is just a server endpoint that returns data instead of a full webpage.</p>
<p>When we use cURL with APIs, we:</p>
<ul>
<li><p>Send a request</p>
</li>
<li><p>Get back structured data (often JSON)</p>
</li>
<li><p>Check if the server behaves correctly</p>
</li>
</ul>
<p>This is extremely useful when:</p>
<ul>
<li><p>Frontend is not ready</p>
</li>
<li><p>Backend is under development</p>
</li>
<li><p>We want to test quickly without writing code</p>
</li>
</ul>
<p>cURL becomes a bridge between our terminal and the backend logic.</p>
<hr />
<h2><strong>Common Mistakes Beginners Make with cURL</strong></h2>
<p>One common mistake is trying to learn all flags at once. cURL has many options, but beginners don’t need most of them early.</p>
<p>Another mistake is copying commands without understanding what they do. This creates confusion instead of clarity.</p>
<p>Some also expect cURL to behave like a browser. But cURL is not a browser, it is a network tool.</p>
<p>The goal in the beginning is not mastery. The goal is confidence.</p>
<hr />
<h2><strong>Browser Request vs cURL Request (Conceptually)</strong></h2>
<p>A browser:</p>
<ul>
<li><p>Sends many automatic headers</p>
</li>
<li><p>Loads CSS, JS, images</p>
</li>
<li><p>Executes JavaScript</p>
</li>
</ul>
<p>cURL:</p>
<ul>
<li><p>Sends exactly what we tell it</p>
</li>
<li><p>Shows raw responses</p>
</li>
<li><p>Does one job at a time</p>
</li>
</ul>
<p>Both talk to servers, but cURL gives us transparency.</p>
<hr />
<h2><strong>Where cURL Fits in Backend Development</strong></h2>
<p>In backend development, cURL is used to:</p>
<ul>
<li><p>Test APIs</p>
</li>
<li><p>Debug production issues</p>
</li>
<li><p>Verify server responses</p>
</li>
<li><p>Learn HTTP deeply</p>
</li>
</ul>
<p>It often becomes the first tool we reach for when something breaks.</p>
<p>cURL is not about commands.</p>
<p>It is about understanding communication between our system and a server.</p>
<p>Once we understand this flow, everything else, APIs, frameworks, tools starts making more sense.</p>
<p>We don’t rush.</p>
<p>We build clarity first.</p>
<p>Depth comes later.</p>
]]></content:encoded></item><item><title><![CDATA[TCP Working: 3 Way Handshake & Reliable Communication]]></title><description><![CDATA[When we build websites or web apps, we constantly send data from one computer to another. A browser talks to a server, a server replies back, and data keeps moving across the internet.
But this data d]]></description><link>https://blog.gurjeet.tech/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://blog.gurjeet.tech/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[TCP Handshake]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Fri, 30 Jan 2026 05:55:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769752494057/c7ddb90a-985b-40fc-bc26-10e2b0bb423c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we build websites or web apps, we constantly send data from one computer to another. A browser talks to a server, a server replies back, and data keeps moving across the internet.</p>
<p>But this data does not magically travel in a safe and correct way. There must be rules that decide how data is sent, received, ordered, and verified.</p>
<p>This is where TCP comes in.</p>
<p>In this article, we will slowly understand what TCP is, why it exists, what problems it solves, and how the famous 3 way handshake works. We will keep everything simple and focus on ideas instead of technical overload.</p>
<p>Before understanding TCP, we need to imagine what happens without it.</p>
<p>Suppose we send a long message from one computer to another over the internet. The message is broken into small pieces and travels through different paths. Some pieces may arrive late, some may arrive early, and some may not arrive at all.</p>
<p>Without rules:</p>
<ul>
<li><p>Data can arrive in the wrong order</p>
</li>
<li><p>Some parts of data can be lost</p>
</li>
<li><p>The receiver may not know whether the data is complete</p>
</li>
<li><p>The sender may not know if the data was received</p>
</li>
</ul>
<p>This would make websites unreliable. A page may load half content, images may break, or data may become corrupted.</p>
<p>So clearly, we need a system that controls data transfer properly.</p>
<hr />
<h2><strong>What is TCP and why it is needed</strong></h2>
<p>TCP stands for Transmission Control Protocol.</p>
<p>TCP is a communication protocol that ensures reliable data transfer between two computers on a network. It does not send data blindly. Instead, it first creates a connection, then sends data carefully, and finally closes the connection properly.</p>
<p>We use TCP because:</p>
<ul>
<li><p>We want data to arrive correctly</p>
</li>
<li><p>We want data in the correct order</p>
</li>
<li><p>We want to know if something goes wrong</p>
</li>
<li><p>We want both sides to agree before talking</p>
</li>
</ul>
<p>Most important internet services like HTTP, HTTPS, email, and file transfer rely on TCP.</p>
<hr />
<h2><strong>Problems TCP is designed to solve</strong></h2>
<p>TCP was designed to handle real world network problems.</p>
<p>First, TCP handles packet loss. If some data is lost during transfer, TCP detects it and sends the data again.</p>
<p>Second, TCP handles out of order delivery. Data packets may arrive in the wrong order, but TCP rearranges them correctly before giving them to the application.</p>
<p>Third, TCP handles duplication. If the same packet arrives twice, TCP can detect and ignore the duplicate.</p>
<p>Fourth, TCP handles flow control, which means it does not overwhelm the receiver with too much data at once.</p>
<p>Without TCP, reliable communication on the internet would not be possible.</p>
<hr />
<h2><strong>What is the TCP 3 Way Handshake</strong></h2>
<p>Before sending actual data, TCP first creates a connection between the client and the server.</p>
<p>This connection setup process is called the 3 way handshake.</p>
<p>The purpose of the handshake is simple:</p>
<ul>
<li><p>Both sides confirm they are ready to communicate</p>
</li>
<li><p>Both sides agree on starting sequence numbers</p>
</li>
<li><p>A reliable connection is established</p>
</li>
</ul>
<p>This happens in three steps, which is why it is called a 3 way handshake.</p>
<hr />
<h2><strong>Understanding the handshake using a simple conversation</strong></h2>
<p>We can think of the handshake like a phone call.</p>
<p>First, one person says, “Hello, can we talk?”</p>
<p>Second, the other person replies, “Yes, I can hear you.”</p>
<p>Third, the first person says, “Great, let’s talk.”</p>
<p>Only after this confirmation does the real conversation begin.</p>
<p>TCP works in a very similar way.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769751104785/a888ef7f-2edb-495c-91e6-06bfb16c294a.png" alt="" />

<hr />
<h2><strong>Step by step working of SYN, SYN-ACK, and ACK</strong></h2>
<p>In the first step, the client sends a SYN message to the server.</p>
<p>SYN means “synchronize”. This message says:</p>
<p>“We want to start a connection and here is my starting number.”</p>
<p>In the second step, the server replies with SYN-ACK.</p>
<p>This means:</p>
<p>“I received your request, I am ready, and here is my starting number.”</p>
<p>In the third step, the client sends an ACK message.</p>
<p>This message confirms:</p>
<p>“I received your response and the connection is now established.”</p>
<p>After this third step, both sides fully trust that the connection exists.</p>
<hr />
<h2><strong>How data transfer works in TCP</strong></h2>
<p>Once the connection is established, real data transfer begins.</p>
<p>TCP does not send data as one big chunk. It breaks data into smaller pieces called segments. Each segment has a sequence number, which helps track the order.</p>
<p>When the receiver gets data, it sends back an acknowledgment (ACK). This acknowledgment tells the sender which data has been received successfully.</p>
<p>If the sender does not receive an acknowledgment within a certain time, it assumes the data was lost and sends it again.</p>
<p>This constant back and forth ensures safe delivery.</p>
<hr />
<h2><strong>Sequence numbers and acknowledgements (high level idea)</strong></h2>
<p>Sequence numbers help TCP keep data in order.</p>
<p>Each piece of data has a number attached to it. The receiver uses these numbers to arrange data correctly, even if packets arrive out of order.</p>
<p>Acknowledgements tell the sender, “We have received data up to this point.”</p>
<p>This allows the sender to know exactly what was delivered and what needs retransmission.</p>
<p>We do not need to understand the math behind it at the beginning. The idea is enough.</p>
<hr />
<h2><strong>How TCP handles packet loss and retransmission</strong></h2>
<p>Packet loss is normal on the internet. Networks are not perfect.</p>
<p>TCP constantly monitors acknowledgements. If an acknowledgment is missing, TCP assumes packet loss.</p>
<p>When this happens:</p>
<ul>
<li><p>TCP resends the missing data</p>
</li>
<li><p>The receiver ignores duplicates</p>
</li>
<li><p>Data is reconstructed correctly</p>
</li>
</ul>
<p>This happens automatically without the application knowing anything about it.</p>
<p>That is why TCP is called reliable.</p>
<hr />
<h2><strong>How TCP ensures reliability, order, and correctness</strong></h2>
<p>TCP ensures reliability by using acknowledgements and retransmissions.</p>
<p>TCP ensures order by using sequence numbers.</p>
<p>TCP ensures correctness by verifying that data is complete and properly received before passing it to applications.</p>
<p>Because of this, applications like browsers and servers can focus on logic instead of worrying about broken data.</p>
<hr />
<h2><strong>How a TCP connection is closed</strong></h2>
<p>Just like a connection must be created properly, it must also be closed properly.</p>
<p>TCP uses FIN and ACK messages to close a connection.</p>
<p>One side sends a FIN message saying, “I am done sending data.”</p>
<p>The other side acknowledges it.</p>
<p>Then the second side sends its own FIN.</p>
<p>Finally, the first side acknowledges that too.</p>
<p>This ensures both sides finish communication cleanly without data loss.</p>
<h2><strong>TCP connection lifecycle</strong></h2>
<p>A TCP connection goes through three main phases.</p>
<p>First, connection establishment using the 3 way handshake.</p>
<p>Second, data transfer using sequence numbers and acknowledgements.</p>
<p>Third, connection termination using FIN and ACK messages.</p>
<p>This full lifecycle makes TCP predictable and safe.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[TCP vs UDP: When to Use What, and How TCP Relates to HTTP]]></title><description><![CDATA[When we open a website, watch a video, send a message, or make a video call, data moves from one computer to another. This data does not magically travel on its own. The internet is just a huge networ]]></description><link>https://blog.gurjeet.tech/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http</link><guid isPermaLink="true">https://blog.gurjeet.tech/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[TCP/UDP]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Fri, 30 Jan 2026 05:38:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769751432107/d91dfdf6-f4cb-4a73-b63d-a2bce814e302.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we open a website, watch a video, send a message, or make a video call, data moves from one computer to another. This data does not magically travel on its own. The internet is just a huge network of computers connected together.</p>
<p>For this communication to work properly, all computers must agree on rules. These rules define how data is sent, how it is received, and what happens if something goes wrong.</p>
<p>These rules are called protocols.</p>
<p>Among many protocols, two very important ones work at the transport level of the internet:</p>
<ul>
<li><p>TCP</p>
</li>
<li><p>UDP</p>
</li>
</ul>
<p>And at a higher level, we often hear about:</p>
<ul>
<li>HTTP</li>
</ul>
<p>To really understand the internet, we must understand how these fit together.</p>
<hr />
<h2><strong>What Are TCP and UDP (High Level)</strong></h2>
<p>TCP and UDP are transport protocols. Their main job is to move data from one computer to another reliably or quickly, depending on the need.</p>
<p>They do not care what the data means.</p>
<p>They only care how data is delivered.</p>
<p>Think of them as delivery methods, not message content.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769751104785/a888ef7f-2edb-495c-91e6-06bfb16c294a.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>TCP: Safe and Reliable Data Delivery</strong></h2>
<p>TCP stands for Transmission Control Protocol.</p>
<p>TCP is used when data must arrive correctly and completely.</p>
<p>Before sending data, TCP first creates a connection between the sender and the receiver. Both sides agree to talk, just like starting a phone call.</p>
<p>While sending data, TCP:</p>
<ul>
<li><p>Sends data in small pieces</p>
</li>
<li><p>Keeps track of every piece</p>
</li>
<li><p>Checks if data is received</p>
</li>
<li><p>Resends data if something is lost</p>
</li>
<li><p>Delivers data in the correct order</p>
</li>
</ul>
<p>Because of all these checks, TCP is slower, but it is very reliable.</p>
<p>A simple analogy is a courier service:</p>
<ul>
<li><p>Every package is tracked</p>
</li>
<li><p>Missing packages are resent</p>
</li>
<li><p>Order is preserved</p>
</li>
<li><p>Delivery confirmation exists</p>
</li>
</ul>
<hr />
<h2><strong>UDP: Fast but Risky Data Delivery</strong></h2>
<p>UDP stands for User Datagram Protocol.</p>
<p>UDP does not create a connection before sending data. It simply sends data and moves on.</p>
<p>UDP does not:</p>
<ul>
<li><p>Check if data is received</p>
</li>
<li><p>Resend lost data</p>
</li>
<li><p>Guarantee order</p>
</li>
</ul>
<p>Because of this, UDP is very fast, but not reliable.</p>
<p>A simple analogy is a live announcement:</p>
<ul>
<li><p>Message is broadcast</p>
</li>
<li><p>If someone misses it, it is gone</p>
</li>
<li><p>No retries</p>
</li>
<li><p>Speed matters more than accuracy</p>
</li>
</ul>
<p>UDP is used when speed is more important than perfection.</p>
<hr />
<h2><strong>Key Differences Between TCP and UDP</strong></h2>
<p>TCP and UDP solve the same problem in different ways.</p>
<p>TCP focuses on:</p>
<ul>
<li><p>Accuracy</p>
</li>
<li><p>Reliability</p>
</li>
<li><p>Order</p>
</li>
<li><p>Safety</p>
</li>
</ul>
<p>UDP focuses on:</p>
<ul>
<li><p>Speed</p>
</li>
<li><p>Low delay</p>
</li>
<li><p>Real time delivery</p>
</li>
</ul>
<p>TCP waits and verifies.</p>
<p>UDP sends and forgets.</p>
<p>Neither is better overall.</p>
<p>Each exists for a different purpose.</p>
<hr />
<h2><strong>When We Use TCP</strong></h2>
<p>We use TCP when losing data is not acceptable.</p>
<p>Examples include:</p>
<ul>
<li><p>Loading a website</p>
</li>
<li><p>Sending emails</p>
</li>
<li><p>Downloading files</p>
</li>
<li><p>Online payments</p>
</li>
<li><p>APIs and backend communication</p>
</li>
</ul>
<p>In these cases, even one missing piece of data can break the whole system. Speed is important, but correctness is more important.</p>
<p>That is why TCP is the default choice for most web related tasks.</p>
<hr />
<h2><strong>When We Use UDP</strong></h2>
<p>We use UDP when real time speed matters more than perfect delivery.</p>
<p>Examples include:</p>
<ul>
<li><p>Video calls</p>
</li>
<li><p>Live streaming</p>
</li>
<li><p>Online gaming</p>
</li>
<li><p>Voice calls</p>
</li>
</ul>
<p>In these cases, it is better to lose a small amount of data than to wait. A delayed video frame is worse than a dropped one.</p>
<p>UDP keeps things fast and smooth, even if some data is lost.</p>
<hr />
<h2><strong>Real World Examples: TCP vs UDP</strong></h2>
<p>To make this clearer, let us compare common real world usage.</p>
<p>Websites:</p>
<ul>
<li><p>Use TCP</p>
</li>
<li><p>Because HTML, CSS, and JS must load correctly</p>
</li>
</ul>
<p>Emails:</p>
<ul>
<li><p>Use TCP</p>
</li>
<li><p>Because missing text is not acceptable</p>
</li>
</ul>
<p>Video calls:</p>
<ul>
<li><p>Use UDP</p>
</li>
<li><p>Because delay feels worse than data loss</p>
</li>
</ul>
<p>Online games:</p>
<ul>
<li><p>Use UDP</p>
</li>
<li><p>Because real time position updates matter</p>
</li>
</ul>
<p>File downloads:</p>
<ul>
<li><p>Use TCP</p>
</li>
<li><p>Because corrupted files are useless</p>
</li>
</ul>
<hr />
<h2><strong>What Is HTTP and Where It Fits</strong></h2>
<p>HTTP stands for HyperText Transfer Protocol.</p>
<p>HTTP is not a transport protocol.</p>
<p>It does not move data on the network by itself.</p>
<p>HTTP is an application level protocol.</p>
<p>Its job is to define:</p>
<ul>
<li><p>How requests are made</p>
</li>
<li><p>How responses are structured</p>
</li>
<li><p>How browsers and servers talk in a meaningful way</p>
</li>
</ul>
<p>HTTP defines things like:</p>
<ul>
<li><p>GET and POST</p>
</li>
<li><p>Headers</p>
</li>
<li><p>Status codes</p>
</li>
<li><p>Request and response format</p>
</li>
</ul>
<p>But HTTP does not care how data travels physically.</p>
<p>It relies on lower level protocols to do that job.</p>
<hr />
<h2><strong>Relationship Between TCP and HTTP</strong></h2>
<p>HTTP runs on top of TCP.</p>
<p>This means:</p>
<ul>
<li><p>TCP handles reliable data delivery</p>
</li>
<li><p>HTTP handles request response logic</p>
</li>
</ul>
<p>When we open a website:</p>
<ol>
<li><p>A TCP connection is created</p>
</li>
<li><p>HTTP request is sent over TCP</p>
</li>
<li><p>Server responds using HTTP</p>
</li>
<li><p>TCP ensures data arrives correctly</p>
</li>
</ol>
<p>HTTP depends on TCP’s reliability.</p>
<p>Without TCP, HTTP would not work properly.</p>
<hr />
<h2><strong>Why HTTP Does Not Replace TCP</strong></h2>
<p>This is a very common beginner confusion.</p>
<p>HTTP and TCP solve different problems.</p>
<p>TCP answers:</p>
<ul>
<li>How does data safely travel between computers?</li>
</ul>
<p>HTTP answers:</p>
<ul>
<li><p>What does this data mean?</p>
</li>
<li><p>Is this a request or a response?</p>
</li>
<li><p>What type of content is it?</p>
</li>
</ul>
<p>HTTP cannot replace TCP because HTTP assumes that data delivery is already reliable.</p>
<p>That reliability comes from TCP.</p>
<hr />
<h2><strong>Is HTTP the Same as TCP?</strong></h2>
<p>No, they are not the same.</p>
<p>A simple way to remember:</p>
<ul>
<li><p>TCP is the road</p>
</li>
<li><p>HTTP is the traffic rules and signs</p>
</li>
</ul>
<p>Without roads, rules are useless.</p>
<p>Without rules, roads are chaotic.</p>
<p>Both are required, but they exist at different layers.</p>
<hr />
<h2><strong>Layering: The Big Picture</strong></h2>
<p>A simplified view of how things work:</p>
<ul>
<li><p>Application Layer → HTTP</p>
</li>
<li><p>Transport Layer → TCP or UDP</p>
</li>
<li><p>Network Layer → IP</p>
</li>
</ul>
<p>Each layer has a clear responsibility.</p>
<p>This separation makes the internet flexible, scalable, and reliable.</p>
<hr />
<h2><strong>Final Summary</strong></h2>
<ul>
<li><p>The internet needs rules to send data</p>
</li>
<li><p>TCP and UDP are transport level rules</p>
</li>
<li><p>TCP is safe and reliable</p>
</li>
<li><p>UDP is fast but risky</p>
</li>
<li><p>HTTP is an application level protocol</p>
</li>
<li><p>HTTP runs on top of TCP</p>
</li>
<li><p>HTTP does not replace TCP</p>
</li>
<li><p>TCP and HTTP are not the same</p>
</li>
</ul>
<p>Understanding this foundation makes everything else in web development easier to learn.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[How DNS Resolution Works]]></title><description><![CDATA[When we open a website like google.com, it feels instant. We type a name, press Enter, and the page loads. What we don’t see is the long chain of systems working behind the scenes to convert that huma]]></description><link>https://blog.gurjeet.tech/how-dns-resolution-works</link><guid isPermaLink="true">https://blog.gurjeet.tech/how-dns-resolution-works</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[#DNS Resolution]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Fri, 30 Jan 2026 05:24:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769750616856/6e7338fa-4e27-45fc-aefe-6e75c8702cbe.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we open a website like <a href="http://google.com">google.com</a>, it feels instant. We type a name, press Enter, and the page loads. What we don’t see is the long chain of systems working behind the scenes to convert that human friendly name into something computers actually understand.</p>
<p>This is where DNS comes in.</p>
<p>DNS is one of those systems every web developer uses every day, often without realising it. To truly understand how the web works, we must understand DNS, not just definitions, but how it behaves in the real world. In this article, we will break DNS down step by step and use the dig command to build a clear mental model of how name resolution actually happens.</p>
<h2><strong>What is DNS and why name resolution exists</strong></h2>
<p>Computers do not understand domain names. They communicate using IP addresses, which are numeric values like 142.250.190.14. Humans, however, cannot easily remember numbers, especially at the scale of the internet.</p>
<p>DNS (Domain Name System) exists to solve this exact problem.</p>
<p>We can think of DNS as the internet’s phonebook. Instead of memorising IP addresses, we remember names like <a href="http://google.com">google.com</a>. DNS acts as the translation system that maps these names to their corresponding IP addresses.</p>
<p>Without DNS, the web would still work, but it would be unusable for humans. Every website visit would require remembering and typing raw IP addresses. DNS makes the web usable, scalable, and human friendly.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749935961/ed294bbf-9ad9-42a3-a05d-9cbf5479e741.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>What is the dig command and when it is used</strong></h2>
<p>dig stands for Domain Information Groper. It is a command line tool used to query DNS servers directly and inspect DNS records.</p>
<p>Browsers perform DNS lookups automatically, but they hide the details from us. dig removes that abstraction. It allows us to ask very specific DNS questions and see exactly which server responds and what information is returned.</p>
<p>We typically use dig when:</p>
<ul>
<li><p>Debugging DNS issues</p>
</li>
<li><p>Understanding how DNS resolution flows</p>
</li>
<li><p>Verifying DNS records like NS, A, MX, TXT</p>
</li>
<li><p>Learning how DNS works internally</p>
</li>
</ul>
<p>In short, dig is not just a tool, it is a lens into the DNS system.</p>
<hr />
<h2><strong>Understanding dig . NS and root name servers</strong></h2>
<p>Let’s start at the very top of DNS.</p>
<p>When we run:</p>
<pre><code class="language-xml">dig . NS
</code></pre>
<p>We are asking:</p>
<p>“Who is responsible for the root of the DNS system?”</p>
<p>The dot (.) represents the DNS root zone. Root name servers do not know IP addresses for domains like <a href="http://google.com">google.com</a>. Instead, they know where to find information about top level domains such as .com, .org, .net, and country codes like .in.</p>
<p>Root servers are the first step in DNS resolution. They act like a directory that says,</p>
<p>“I don’t know the final answer, but I know who might.”</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769750100823/db7e8112-fcb6-41b9-9306-893f2acdb071.png" alt="" style="display:block;margin:0 auto" />

<p>There are total 13 Root servers in the world, but total 1600+ implementations, means there are 1600+ copies present in the world.</p>
<p>This is an important concept: DNS works by referral, not by guessing.</p>
<hr />
<h2><strong>Understanding dig com NS and TLD name servers</strong></h2>
<p>Next, we move one level down the hierarchy.</p>
<p>When we run:</p>
<pre><code class="language-xml">dig com NS
</code></pre>
<p>We are asking:</p>
<p>“Which name servers are responsible for the .com domain?”</p>
<p>These servers are called TLD (Top Level Domain) name servers.</p>
<p>TLD servers do not know the IP address of <a href="http://google.com">google.com</a>. Instead, they know which authoritative name servers are responsible for domains under .com.</p>
<p>So again, we see the same pattern:</p>
<ul>
<li><p>Root → points to TLD</p>
</li>
<li><p>TLD → points to authoritative servers</p>
</li>
</ul>
<p>DNS is intentionally layered to remain scalable across billions of domains.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769750335053/312161c8-cf8e-40a0-98f7-0c07344ff735.png" alt="" style="display:block;margin:0 auto" />

<p>This output shows the result of running dig com NS, which asks DNS who is responsible for the .com top level domain. The important part is the ANSWER SECTION. It lists multiple NS (Name Server) records like <a href="http://a.gtld-servers.net">a.gtld-servers.net</a>, <a href="http://b.gtld-servers.net">b.gtld-servers.net</a>, and so on. These are the official TLD name servers for .com, and they are managed by the .com registry. The number 172800 is the TTL (time to live), which means resolvers can cache this information for about 2 days. This output does not give IP addresses for websites like <a href="http://google.com">google.com</a>; instead, it tells DNS resolvers where to go next to find which authoritative name servers handle a specific .com domain.</p>
<hr />
<h2><strong>Understanding dig</strong> <a href="http://google.com"><strong>google.com</strong></a> <strong>NS and authoritative name servers</strong></h2>
<p>When we run:</p>
<pre><code class="language-xml">dig google.com NS
</code></pre>
<p>We are asking:</p>
<p>“Which name servers are authoritative for <a href="http://google.com">google.com</a>?”</p>
<p>Authoritative name servers are the source of truth for a domain. They are configured by the domain owner (or their DNS provider). These servers contain the actual DNS records A, AAAA, MX, TXT, and more.</p>
<p>Once a resolver reaches the authoritative name server, it can finally ask:</p>
<blockquote>
<p><code>“What is the IP address for</code> <a href="http://google.com"><code>google.com</code></a><code>?”</code></p>
</blockquote>
<p><strong>And this server gives the final answer.</strong></p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769750380840/e0df5fb1-b195-424e-8e47-f8a7cab6bb5c.png" alt="" style="display:block;margin:0 auto" />

<p>This output shows the result of running dig <a href="http://google.com">google.com</a> NS, which asks DNS which name servers are authoritative for the <a href="http://google.com">google.com</a> domain. In the ANSWER SECTION, we see four NS records: <a href="http://ns1.google.com">ns1.google.com</a>, <a href="http://ns2.google.com">ns2.google.com</a>, <a href="http://ns3.google.com">ns3.google.com</a>, and <a href="http://ns4.google.com">ns4.google.com</a>. These are Google’s authoritative name servers, meaning they are the final source of truth for all DNS records of <a href="http://google.com">google.com</a>. The TTL value (270971) tells resolvers how long this information can be cached. The ADDITIONAL SECTION includes the actual IP addresses (both IPv4 A and IPv6 AAAA) of these name servers, so resolvers can contact them directly without doing another lookup. At this stage of DNS resolution, the system now knows exactly where to ask for the final IP addre<strong>ss of</strong> <a href="http://google.com"><strong>google.com</strong></a><strong>.</strong></p>
<hr />
<h2><strong>Understanding dig</strong> <a href="http://google.com"><strong>google.com</strong></a> <strong>and the full DNS resolution flow</strong></h2>
<p>Now let’s connect everything.</p>
<p>When we run:</p>
<pre><code class="language-xml">dig google.com
</code></pre>
<p>dig performs the full lookup and shows us the final DNS response. But behind the scenes, the resolution followed a clear path:</p>
<ol>
<li><p>Ask root name servers where .com lives</p>
</li>
<li><p>Ask .com TLD servers where <a href="http://google.com">google.com</a> lives</p>
</li>
<li><p>Ask Google’s authoritative servers for the IP address</p>
</li>
<li><p>Receive the final answer</p>
</li>
</ol>
<p>This entire process usually happens in milliseconds.</p>
<p>In real life, browsers don’t talk directly to root or TLD servers. They use recursive resolvers (usually provided by ISPs or public services like Google DNS). These resolvers perform all the steps on our behalf and cache results to make future lookups faster.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769750434383/5f7c0e08-d1d9-4941-8c86-95624e0ea202.png" alt="" style="display:block;margin:0 auto" />

<p>This output shows the final step of DNS resolution. The command dig <a href="http://google.com">google.com</a> asks for the A record of <a href="http://google.com">google.com</a>, which means we are now asking for the actual IP address to connect to. In the ANSWER SECTION, DNS returns 172.217.27.174, which is one of Google’s server IPs. The TTL value (107) is very small, showing that Google keeps this record short lived so traffic can be routed dynamically. At this point, DNS resolution is complete, the browser now has a concrete IP address and can open a network connection to Google’s servers.</p>
<hr />
<h2><strong>What NS records represent and why they matter</strong></h2>
<p>NS (Name Server) records define who controls a domain’s DNS.</p>
<p>They are critical because:</p>
<ul>
<li><p>They define authority</p>
</li>
<li><p>They enable delegation</p>
</li>
<li><p>They allow DNS to scale globally</p>
</li>
</ul>
<p>Without NS records, DNS would have no way to know where responsibility for a domain begins and ends.</p>
<p>Whenever we change DNS providers, what we are really doing is changing NS records.</p>
<p><strong>How recursive resolvers use this information behind the scenes</strong></p>
<p>Recursive resolvers are like professional DNS investigators.</p>
<p>They:</p>
<ul>
<li><p>Query root servers</p>
</li>
<li><p>Follow referrals to TLD servers</p>
</li>
<li><p>Reach authoritative servers</p>
</li>
<li><p>Cache responses using TTL values</p>
</li>
</ul>
<p>This caching is why DNS lookups are fast most of the time and slow only on first access.</p>
<p>Resolvers hide complexity, but dig exposes it, making DNS understandable instead of mysterious.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[DNS Record Types Explained]]></title><description><![CDATA[When we type a website name like google.com into a browser and press Enter, the page opens almost instantly. It feels simple and natural. But behind this simple action, something very important happen]]></description><link>https://blog.gurjeet.tech/dns-record-types-explained</link><guid isPermaLink="true">https://blog.gurjeet.tech/dns-record-types-explained</guid><category><![CDATA[dns-records]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 19:17:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749251159/63c0fa72-fe0a-4311-ad90-5707fa2e8183.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we type a website name like <a href="http://google.com">google.com</a> into a browser and press Enter, the page opens almost instantly. It feels simple and natural. But behind this simple action, something very important happens first.</p>
<p>Before a browser can load any website, it must answer one basic question:</p>
<p>“Where does this website live on the internet?”</p>
<p>Browsers do not understand website names. They understand numbers. The system that helps convert human friendly names into machine friendly numbers is called DNS.</p>
<p>In this article, we will understand DNS from the ground up, using simple ideas and real life examples, without going deep into technical jargon.</p>
<h2><strong>What DNS Is (in very simple terms)</strong></h2>
<p>DNS stands for Domain Name System.</p>
<p>The easiest way to understand DNS is to think of it as the phonebook of the internet.</p>
<p>In real life, we save contact names like “Mom” or “Office” in our phone. Behind those names are actual phone numbers. We never dial the numbers directly because names are easier to remember.</p>
<p>The internet works in a similar way.</p>
<ul>
<li><p>Websites have names like <a href="http://example.com">example.com</a></p>
</li>
<li><p>Computers communicate using IP addresses like 93.184.216.34</p>
</li>
</ul>
<p>DNS is the system that connects these two.</p>
<p>So when we enter a website name, DNS tells the browser:</p>
<p>“This name belongs to this IP address.”</p>
<p>Only after that can the browser talk to the correct server.</p>
<hr />
<h2><strong>Why DNS Records Are Needed</strong></h2>
<p>DNS is not just one big list. It is a collection of records, and each record solves a specific problem.</p>
<p>Websites today do more than just show pages. They handle emails, subdomains, security checks, and verifications. One single mapping is not enough for all of this.</p>
<p>DNS records exist so that:</p>
<ul>
<li><p>browsers know where to load the website from</p>
</li>
<li><p>email systems know where to deliver emails</p>
</li>
<li><p>services can verify domain ownership</p>
</li>
<li><p>traffic can be managed cleanly and separately</p>
</li>
</ul>
<p>Each DNS record answers one specific question about a domain.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749457411/de742dd8-d0bc-40a4-ba84-e7ec85b633f5.png" alt="" style="display:block;margin:0 auto" />

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769748915150/ca245780-4093-4421-903e-29f1bbb909ad.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>What an NS Record Is (Who Is Responsible for a Domain)</strong></h2>
<p>NS stands for Name Server.</p>
<p>An NS record tells the internet:</p>
<p>“These servers are responsible for answering DNS questions for this domain.”</p>
<p>This is about authority, not IP addresses.</p>
<p>When DNS lookup starts, the system does not immediately ask for an IP address. First, it asks:</p>
<p>“Who should I talk to about this domain?”</p>
<p>NS records provide that answer.</p>
<p>They act like a signboard saying:</p>
<p>“For anything related to this domain, ask these name servers.”</p>
<p>Without NS records, a domain has no official place to store its DNS information**.**</p>
<hr />
<h2><strong>What an A Record Is (Domain → IPv4 Address)</strong></h2>
<p>An A record connects a domain name to an IPv4 address.</p>
<p>This is the most basic and important DNS record for a website.</p>
<p>When we open a website in a browser, eventually DNS needs to answer:</p>
<p>“Which IP address should we connect to?”</p>
<p>That answer usually comes from an A record.</p>
<p>For example:</p>
<ul>
<li><a href="http://example.com">example.com</a> → 93.184.216.34</li>
</ul>
<p>This is how browsers find the actual server machine that hosts the website.</p>
<hr />
<h2><strong>What an AAAA Record Is (Domain → IPv6 Address)</strong></h2>
<p>An AAAA record does the same job as an A record, but for IPv6 addresses instead of IPv4.</p>
<p>IPv6 exists because the internet ran out of IPv4 addresses.</p>
<p>So:</p>
<ul>
<li><p>A record → IPv4</p>
</li>
<li><p>AAAA record → IPv6</p>
</li>
</ul>
<p>Modern systems can use either. If both exist, the browser usually prefers IPv6.</p>
<p>Conceptually, both records solve the same problem:</p>
<p>turning a name into a reachable server address.</p>
<hr />
<h2><strong>What a CNAME Record Is (One Name Pointing to Another Name)</strong></h2>
<p>CNAME stands for Canonical Name.</p>
<p>A CNAME record does not point to an IP address.</p>
<p>Instead, it points to another domain name.</p>
<p>This is useful when:</p>
<ul>
<li><p>multiple names should lead to the same place</p>
</li>
<li><p>the actual server IP might change later</p>
</li>
</ul>
<p>For example:</p>
<ul>
<li><a href="http://www.example.com">www.example.com</a> → <a href="http://example.com">example.com</a></li>
</ul>
<p>Here, <a href="http://www.example.com">www.example.com</a> does not have its own IP. It simply says:</p>
<p>“Go ask <a href="http://example.com">example.com</a> for the real address.”</p>
<p>CNAME helps avoid duplication and keeps DNS easier to manage.</p>
<hr />
<h2><strong>What an MX Record Is (How Emails Find the Mail Server)</strong></h2>
<p>MX stands for Mail Exchange.</p>
<p>MX records are used only for email, not websites.</p>
<p>When someone sends an email to <a href="mailto:hello@example.com">hello@example.com</a>, the sending mail server asks:</p>
<p>“Where should I deliver emails for this domain?”</p>
<p>The answer comes from MX records.</p>
<p>MX records point to mail servers, not web servers.</p>
<p>This is why:</p>
<ul>
<li><p>a website can be hosted on one service</p>
</li>
<li><p>email can be handled by another service</p>
</li>
</ul>
<p>This separation is intentional and very important.</p>
<hr />
<h2><strong>What a TXT Record Is (Extra Information and Verification)</strong></h2>
<p>TXT records store plain text information about a domain.</p>
<p>They are commonly used for:</p>
<ul>
<li><p>domain ownership verification</p>
</li>
<li><p>email security (SPF, DKIM, DMARC)</p>
</li>
<li><p>service integrations</p>
</li>
</ul>
<p>TXT records usually do not affect website loading directly.</p>
<p>Instead, they help other systems trust the domain.</p>
<p>Think of TXT records as notes attached to a domain, readable by machines.</p>
<hr />
<h2><strong>How All DNS Records Work Together for One Website</strong></h2>
<p>A real website does not rely on just one DNS record.</p>
<p>For a single domain:</p>
<ul>
<li><p>NS records define who controls DNS</p>
</li>
<li><p>A / AAAA records define where the website lives</p>
</li>
<li><p>CNAME records manage alternate names</p>
</li>
<li><p>MX records handle email delivery</p>
</li>
<li><p>TXT records provide verification and security info</p>
</li>
</ul>
<p>Each record has a clear role.</p>
<p>Together, they allow a domain to function fully on the internet.</p>
<p>DNS works well because responsibilities are separated, not mixed.</p>
<hr />
<h3><strong>A Record vs CNAME</strong></h3>
<p>An A record points directly to an IP address.</p>
<p>A CNAME points to another domain name.</p>
<p>If we need a final destination → A / AAAA</p>
<p>If we need an alias → CNAME</p>
<h3><strong>NS vs MX</strong></h3>
<p>NS records decide who answers DNS questions.</p>
<p>MX records decide where emails are delivered.</p>
<p>They solve completely different problems.</p>
<p>At a very high level, this is what happens:</p>
<ol>
<li><p>Browser gets a domain name</p>
</li>
<li><p>DNS finds the correct name servers (NS)</p>
</li>
<li><p>Name servers provide the needed records</p>
</li>
<li><p>Browser gets an IP address (A / AAAA)</p>
</li>
<li><p>Browser connects to the server</p>
</li>
<li><p>Website loads</p>
</li>
</ol>
<p>All of this happens in milliseconds.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Understanding Network Devices]]></title><description><![CDATA[When we open a website, everything feels instant. We type a URL, press Enter, and the page appears. But behind this simple action, multiple networking devices work together in a very specific order.
F]]></description><link>https://blog.gurjeet.tech/understanding-network-devices</link><guid isPermaLink="true">https://blog.gurjeet.tech/understanding-network-devices</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 19:05:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769748006431/7bc84c6a-1056-4eaa-b8ac-c27d29387194.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we open a website, everything feels instant. We type a URL, press Enter, and the page appears. But behind this simple action, multiple networking devices work together in a very specific order.</p>
<p>For many beginners, terms like modem, router, switch, firewall, and load balancer feel confusing because they are often explained separately, without showing how they connect in the real world.</p>
<p>In this article, we will understand what each device does, why it exists, and how all of them work together to deliver the internet to our laptop, phone, or backend server.</p>
<p>The goal is not memorization. The goal is to build a clear mental model.</p>
<h3><strong>How Internet Enters a Home or Office</strong></h3>
<p>The internet does not directly enter our laptop or mobile phone. It first reaches our building through cables owned by an Internet Service Provider (ISP). From there, it passes through a chain of devices, and each device has a single responsibility.</p>
<p>At a high level, the flow looks like this</p>
<p>Internet → Modem → Router → Switch → Devices</p>
<p>In production systems and data centers, this chain becomes longer and more advanced, but the idea remains the same.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769747716001/c64029f6-9b40-4f6c-a966-21bf5952a803.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>What Is a Modem and Why It Exists</strong></h2>
<p>A modem is the device that connects our private network to the internet provided by the ISP.</p>
<p>The internet signal coming from the ISP is not directly usable by our computers. It may come through fiber, cable, or phone lines, and it uses formats that our local network cannot understand. The modem’s job is to translate this signal into a digital form that our router and devices can work with.</p>
<p>The word modem comes from Modulator–Demodulator.</p>
<p>In simple terms, the modem speaks the language of the ISP on one side and the language of our local network on the other side.</p>
<p>A modem does not manage devices, does not provide Wi-Fi, and does not control traffic. Its responsibility is very narrow: bring the internet inside.</p>
<p>A good analogy is a translator at an airport. The translator does not decide where we go. It only makes communication possible.</p>
<hr />
<h2><strong>What Is a Router and How It Directs Traffic</strong></h2>
<p>Once the internet enters through the modem, it reaches the <strong>router</strong>.</p>
<p>The router is the <strong>decision maker</strong> of the network. Its main job is to decide <strong>where a packet should go next</strong>.</p>
<p>Inside a home or office, multiple devices want internet access at the same time. The router assigns <strong>private IP addresses</strong>, manages traffic, and ensures that responses coming from the internet reach the correct device.</p>
<p>This is also where <strong>NAT (Network Address Translation)</strong> usually happens. Many devices share a single public IP address, and the router keeps track of which request belongs to which device.</p>
<p>A router is like a <strong>traffic police officer at a busy junction</strong>.</p>
<p>Cars (data packets) arrive from different roads and are directed toward the correct destination without colliding.</p>
<p>Without a router, multiple devices cannot safely share one internet connection.</p>
<hr />
<h2><strong>Hub vs Switch: How Local Networks Actually Work</strong></h2>
<p>Inside a local network, devices need to talk to each other. This is where <strong>hubs</strong> and <strong>switches</strong> come into the picture.</p>
<p>A <strong>hub</strong> is a very simple and outdated device. When it receives data, it <strong>broadcasts that data to all connected devices</strong>, even if only one device needs it. This causes unnecessary traffic and security issues.</p>
<p>A <strong>switch</strong>, on the other hand, is intelligent. It learns which device is connected to which port using MAC addresses. When data arrives, the switch sends it <strong>only to the intended device</strong>.</p>
<p>This makes switches faster, more secure, and scalable.</p>
<p>Think of a hub like someone <strong>shouting a message in a crowded room</strong>, while a switch is like <strong>sending a private message to one person</strong>.</p>
<p>In modern networks, <strong>switches have completely replaced hubs</strong>.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769747807631/e3aaf21c-21e6-4d78-bdf7-dcd0039669e1.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>What Is a Firewall and Why Security Lives Here</strong></h2>
<p>A <strong>firewall</strong> is a security gate between networks.</p>
<p>Its job is to <strong>allow or block traffic</strong> based on defined rules. These rules may depend on IP addresses, ports, protocols, or even application level data.</p>
<p>Firewalls exist because not all traffic from the internet should be trusted. Without a firewall, every open service would be exposed directly to attackers.</p>
<p>In home networks, firewalls are often built into routers. In enterprises and cloud environments, firewalls are dedicated systems with advanced inspection capabilities.</p>
<p>A firewall is like a <strong>security guard at a building entrance</strong>.</p>
<p>Everyone is checked, and only allowed people can enter.</p>
<p>For backend systems, firewalls are critical because databases, internal services, and admin panels should never be publicly accessible.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769747930161/2be005aa-9ff2-4b49-b049-36af176fcfd7.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>What Is a Load Balancer and Why Scalable Systems Need It</strong></h2>
<p>A <strong>load balancer</strong> sits in front of multiple servers and distributes incoming traffic among them.</p>
<p>When a web application becomes popular, one server is not enough. Multiple backend servers are deployed, and the load balancer ensures that traffic is shared evenly so no single server becomes overloaded.</p>
<p>Load balancers also help with:</p>
<ul>
<li><p>High availability</p>
</li>
<li><p>Fault tolerance</p>
</li>
<li><p>Zero downtime deployments</p>
</li>
</ul>
<p>If one server fails, the load balancer stops sending traffic to it.</p>
<p>A load balancer works like a <strong>toll booth system on a highway</strong>, directing cars to different lanes so traffic keeps moving smoothly.</p>
<p>In modern systems, load balancers are everywhere, cloud platforms, microservices, and container orchestration.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769748069270/dc1d02a7-b0bb-4d76-8321-f6e4b5ed95f2.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>How All These Devices Work Together in Real Life</strong></h2>
<p>Let’s connect everything into one real world flow.</p>
<p>When we open a website:</p>
<ol>
<li><p>The request leaves our device and goes to the <strong>router</strong></p>
</li>
<li><p>The router forwards it to the <strong>modem</strong></p>
</li>
<li><p>The modem sends it to the <strong>ISP and the internet</strong></p>
</li>
<li><p>On the server side, traffic passes through a <strong>firewall</strong></p>
</li>
<li><p>A <strong>load balancer</strong> distributes the request to one backend server</p>
</li>
<li><p>The response follows the same path back</p>
</li>
</ol>
<p>Each device does <strong>one job</strong>, and together they form a reliable system.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[CSS Selectors 101: Targeting Elements with Precision]]></title><description><![CDATA[When we start learning CSS, it often feels like we are just writing colors, fonts, and spacing. But very quickly, we notice something important: CSS does nothing unless it knows which HTML element it ]]></description><link>https://blog.gurjeet.tech/css-selectors-101-targeting-elements-with-precision</link><guid isPermaLink="true">https://blog.gurjeet.tech/css-selectors-101-targeting-elements-with-precision</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[CSS]]></category><category><![CDATA[css_selector]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 18:50:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769747347930/e599f2d5-e8c3-4ce4-8eab-a00dc34e58a2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning CSS, it often feels like we are just writing colors, fonts, and spacing. But very quickly, we notice something important: CSS does nothing unless it knows which HTML element it should apply to.</p>
<p>This is where CSS selectors come in.</p>
<p>Selectors are not about design.</p>
<p>Selectors are about choice.</p>
<p>Before CSS can style anything, it must first decide <em>what</em> to style. That decision is made using selectors.</p>
<h2><strong>Why CSS Selectors Are Needed</strong></h2>
<p>HTML creates structure.</p>
<p>CSS adds appearance.</p>
<p>But a real webpage contains many elements: headings, paragraphs, buttons, links, and sections. If CSS applied styles blindly, everything would look the same.</p>
<p>Selectors solve this problem by acting as filters.</p>
<p>They help us say:</p>
<ul>
<li><p>style all elements of this type</p>
</li>
<li><p>style only these specific elements</p>
</li>
<li><p>style one unique element</p>
</li>
</ul>
<p>Without selectors, CSS would not be able to target elements correctly.</p>
<h2><strong>Selectors as Ways to Choose Elements</strong></h2>
<p>A good way to think about selectors is like addressing people.</p>
<p>If we shout, “Everyone come here,” we get everyone.</p>
<p>If we say, “All students come here,” we get a group.</p>
<p>If we say, “Rahul from class 10,” we get one person.</p>
<p>CSS selectors work the same way.</p>
<p>They tell the browser who should receive the styling.</p>
<hr />
<h2><strong>Element Selector (Selecting by Tag Name)</strong></h2>
<p>The element selector targets elements using their HTML tag name.</p>
<p>Consider this HTML:</p>
<pre><code class="language-xml">&lt;h1&gt;Welcome&lt;/h1&gt;
&lt;p&gt;This is the first paragraph&lt;/p&gt;
&lt;p&gt;This is the second paragraph&lt;/p&gt;
</code></pre>
<p>If we write this CSS:</p>
<pre><code class="language-css">p {
  color: blue;
}
</code></pre>
<p>CSS selects all &lt;p&gt; elements and applies the <strong>c</strong>olor blue to them.</p>
<p>This selector is useful when we want:</p>
<ul>
<li><p>consistent base styling</p>
</li>
<li><p>all elements of the same type to look similar</p>
</li>
</ul>
<p>However, element selectors are very broad.</p>
<p>If later we want one paragraph to look different, this selector becomes limiting.</p>
<p>That is why element selectors are best used for general rules, not detailed design.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769746857442/dcbb36e2-ea30-4a27-b37d-7fa55573ce78.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>Class Selector (Selecting a Group with Meaning)</strong></h2>
<p>A class selector allows us to select elements based on purpose, not just tag name.</p>
<p>Now consider this HTML:</p>
<pre><code class="language-xml">&lt;p class="highlight"&gt;Important note&lt;/p&gt;
&lt;p&gt;Normal paragraph&lt;/p&gt;
</code></pre>
<p>And this CSS:</p>
<pre><code class="language-css">.highlight {
  background-color: yellow;
}
</code></pre>
<p>Here, CSS selects only the element with the class highlight.</p>
<p>The important idea is this:</p>
<p>A class does not describe <em>what</em> the element is.</p>
<p>It describes <em>why</em> the element exists.</p>
<p>Multiple elements can share the same class:</p>
<pre><code class="language-xml">&lt;p class="highlight"&gt;Warning message&lt;/p&gt;
&lt;div class="highlight"&gt;System alert&lt;/div&gt;
</code></pre>
<p>This makes class selectors reusable and flexible.</p>
<p>That is why classes are the most commonly used selectors in real projects.</p>
<hr />
<h2><strong>ID Selector (Selecting One Unique Element)</strong></h2>
<p>An ID selector is used to target one specific element.</p>
<p>Example HTML:</p>
<pre><code class="language-xml">&lt;h1 id="main-heading"&gt;My Website&lt;/h1&gt;
</code></pre>
<p>CSS:</p>
<pre><code class="language-css">#main-heading {
  font-size: 32px;
}
</code></pre>
<p>The ID selector starts with # and must be unique.</p>
<p>Only one element in the entire page can have that ID.</p>
<p>Because IDs are unique, they are very strong selectors.</p>
<p>But this strength can become a problem if we overuse them.</p>
<p>That is why IDs are best used for:</p>
<p>unique layout anchors</p>
<ul>
<li><p>main containers</p>
</li>
<li><p>elements that appear only once</p>
</li>
</ul>
<p>For styling repeated elements, classes are always better.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769746983861/784679b8-46ab-4ed7-bbab-a69fca2fcefc.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>Group Selectors (Applying the Same Style Together)</strong></h2>
<p>Sometimes, different elements need the same styling.</p>
<p>Instead of repeating CSS, we can group selectors.</p>
<p>Example:</p>
<pre><code class="language-css">h1, h2, h3 {
  font-family: Arial;
}
</code></pre>
<p>Here, CSS applies the same font to all three heading types.</p>
<p>Group selectors help us:</p>
<ul>
<li><p>avoid duplicate code</p>
</li>
<li><p>keep CSS clean</p>
</li>
<li><p>maintain consistency</p>
</li>
</ul>
<p>They do not change how selection works, they simply allow us to apply one rule to multiple selectors.</p>
<hr />
<h2><strong>Descendant Selectors (Selecting Based on Structure)</strong></h2>
<p>HTML elements are usually nested inside each other.</p>
<p>Consider this HTML:</p>
<pre><code class="language-xml">&lt;div class="card"&gt;
  &lt;p&gt;This is inside a card&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This is outside the card&lt;/p&gt;
</code></pre>
<p>If we write:</p>
<pre><code class="language-css">.card p {
  color: green;
}
</code></pre>
<p>CSS selects only the paragraph inside .card, not the one outside.</p>
<p>This selector depends on structure, not just class or tag.</p>
<p>Descendant selectors help us style elements differently based on <em>where they live</em> in the document. This becomes extremely important in real layouts where components contain other elements.</p>
<hr />
<h2><strong>Basic Selector Priority (Very High Level)</strong></h2>
<p>Sometimes, multiple selectors target the same element.</p>
<p>Example:</p>
<pre><code class="language-css">p {
  color: blue;
}

.text {
  color: red;
}
</code></pre>
<p>HTML:</p>
<pre><code class="language-xml">&lt;p class="text"&gt;Hello&lt;/p&gt;
</code></pre>
<p>Even though both rules apply, the text becomes red.</p>
<p>At a very basic level, we can remember:</p>
<p><strong>Element &lt; Class &lt; ID</strong></p>
<ul>
<li><p>element selectors are weakest</p>
</li>
<li><p>class selectors are stronger</p>
</li>
<li><p>ID selectors are strongest</p>
</li>
</ul>
<p>This simple idea helps us understand why some styles override others.</p>
<h2><strong>Before and After Styling (Conceptual Example)</strong></h2>
<p>Before CSS, HTML looks plain:</p>
<pre><code class="language-xml">&lt;h1&gt;Title&lt;/h1&gt;
&lt;p&gt;Description text&lt;/p&gt;
</code></pre>
<p>After adding selectors and styles:</p>
<pre><code class="language-css">h1 {
  color: black;
}

p {
  color: gray;
}

.highlight {
  color: red;
}
</code></pre>
<p>Now the page has structure and meaning.</p>
<p>The difference happens not because of fancy CSS, but because selectors correctly identify <em>what should change</em>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Emmet for HTML: A Beginner’s Guide to Writing Faster Markup]]></title><description><![CDATA[When we start learning HTML, writing code feels slower than expected. Even though HTML itself is simple, the process of typing tags again and again takes time. We write opening tags, then closing tags]]></description><link>https://blog.gurjeet.tech/emmet-for-html-a-beginners-guide-to-writing-faster-markup</link><guid isPermaLink="true">https://blog.gurjeet.tech/emmet-for-html-a-beginners-guide-to-writing-faster-markup</guid><category><![CDATA[Emmet]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[HTML5]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 14:31:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769697752386/b88ce23a-fceb-4388-9a9c-d85a2d69e15f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning HTML, writing code feels slower than expected. Even though HTML itself is simple, the process of typing tags again and again takes time. We write opening tags, then closing tags, then make sure everything is properly nested. A small mistake can easily break the structure of the page.</p>
<p>This experience is common. Almost everyone who learns HTML goes through this phase. The problem is not that HTML is difficult. The problem is that writing repetitive structure by hand is inefficient.</p>
<p>This is where Emmet becomes useful.</p>
<p>Emmet is a tool that helps us write HTML faster by allowing us to describe structure in a short form and letting the editor generate the full code for us.</p>
<h2><strong>What Is Emmet (in very simple terms)</strong></h2>
<p>Emmet is a shortcut language for writing HTML.</p>
<p>Instead of typing full HTML elements manually, we write short expressions that represent the structure we want. The code editor then converts those expressions into complete HTML code.</p>
<p>Emmet does not introduce a new language for the browser. The browser never sees Emmet. Emmet only exists inside the code editor to help developers write HTML more efficiently.</p>
<p>Emmet does not change how HTML works.</p>
<p>It only helps you type less and think more about structure.</p>
<hr />
<h2><strong>Why Emmet Is Useful for HTML Beginners</strong></h2>
<p>When we are beginners, most of our energy goes into remembering syntax and avoiding small mistakes. We often forget closing tags, misplace elements, or lose track of nesting. This makes HTML feel harder than it actually is.</p>
<p>Emmet helps reduce these problems. By generating correct HTML structure automatically, Emmet removes many common beginner errors. This allows us to focus more on understanding how HTML elements relate to each other instead of worrying about typing everything perfectly.</p>
<p>Another important benefit is confidence. When writing HTML becomes faster and cleaner, learning feels smoother and more enjoyable. This encourages consistent practice, which is essential when learning web development.</p>
<hr />
<h2><strong>How Emmet Works Inside Code Editors</strong></h2>
<p>Emmet works as a feature inside modern code editors. It is not a separate program that we run manually. Most editors, such as VS Code, already include Emmet by default.</p>
<p>When we type an Emmet abbreviation, the editor recognizes it as a special pattern. When we press a trigger key (usually the Tab key), the editor expands that abbreviation into full HTML.</p>
<p>Internally, the editor uses Emmet rules to understand what elements, nesting, attributes, and repetitions are being described. The final result is plain HTML that behaves exactly the same as if we had written it by hand.</p>
<hr />
<h2><strong>Basic Emmet Syntax and Abbreviations</strong></h2>
<p>Emmet is based on a small set of symbols that describe structure.</p>
<p>These symbols are not random. They are chosen to represent relationships between elements. For example, some symbols indicate parent child relationships, while others indicate sibling elements or repetition.</p>
<p>The important idea is that Emmet allows us to describe how elements are arranged, not just which tags are used. Once this idea is clear, Emmet becomes easy to read and write.</p>
<p>For example:</p>
<ul>
<li><p>Tag names represent elements</p>
</li>
<li><p>&gt; means “inside”</p>
</li>
<li><p>+ means “next to”</p>
</li>
<li><p>* means “repeat”</p>
</li>
</ul>
<p>These symbols are enough for most HTML writing.</p>
<hr />
<h2><strong>Creating HTML Elements Using Emmet</strong></h2>
<p>The most basic use of Emmet is creating individual HTML elements.</p>
<p>Instead of typing an opening tag and a closing tag manually, we write the tag name once and let Emmet generate the full element. This may seem like a small improvement, but it saves time and avoids mistakes, especially when writing many elements.</p>
<p>This approach also encourages consistency. Every generated element follows proper HTML syntax, which keeps the code clean.</p>
<p>If you type:</p>
<p><code>div</code></p>
<p>and press Tab, Emmet expands it to:</p>
<p><code>&lt;div&gt;&lt;/div&gt;</code></p>
<p>If you type:</p>
<p><code>p</code></p>
<p>you get:</p>
<p><code>&lt;p&gt;&lt;/p&gt;</code></p>
<p>This already saves time and prevents mistakes.</p>
<hr />
<h2><strong>Adding Classes, IDs, and Attributes</strong></h2>
<p>In real world HTML, elements almost always have classes, IDs, or attributes. Writing these repeatedly can become tedious.</p>
<p>Emmet allows us to attach classes and IDs directly to the element definition. This keeps related information together and makes the structure easier to read at a glance.</p>
<p>Attributes can also be added using a clear and readable format. This makes Emmet especially useful when Emmet is used alongside CSS and JavaScript, where classes and IDs are frequently needed.</p>
<p>Emmet makes classes and IDs very easy.</p>
<p>Instead of writing:</p>
<p><code>&lt;div class="container"&gt;&lt;/div&gt;</code></p>
<p>You write:</p>
<p><code>div.container</code></p>
<p>For IDs:</p>
<p><code>div#main</code></p>
<p>This expands into proper HTML with class or id.</p>
<p>You can also add attributes like this:</p>
<p><code>input[type=text]</code></p>
<p>Emmet understands that you want an input element with attributes.</p>
<p>This keeps your focus on what the element is, not how to write it.</p>
<hr />
<h2><strong>Creating Nested Elements</strong></h2>
<p>HTML is mostly about nesting. Without Emmet, nesting feels slow and error prone. With Emmet, nesting is natural. Suppose we want this structure in our page:</p>
<ul>
<li><p>A wrapper div</p>
</li>
<li><p>Inside it, another div</p>
</li>
<li><p>Inside that, a main section</p>
</li>
<li><p>Inside main, a paragraph</p>
</li>
</ul>
<p>Using Emmet, we can write:</p>
<p><code>div&gt;div&gt;main&gt;p</code></p>
<p>This single line describes the entire hierarchy.</p>
<p>Reading it from left to right, we are describing levels:</p>
<ul>
<li><p>A div</p>
</li>
<li><p>inside another div</p>
</li>
<li><p>inside main</p>
</li>
<li><p>inside p</p>
</li>
</ul>
<p>Emmet expands it into a properly nested structure.</p>
<p>This helps beginners understand <strong>parent and child relationships</strong> in HTML.</p>
<hr />
<h2><strong>Repeating Elements Using Multiplication</strong></h2>
<p>Many HTML structures repeat the same element.</p>
<p>Lists are the best example.</p>
<p>Instead of writing &lt;li&gt; five times manually, you can write:</p>
<p><code>li*5</code></p>
<p>Emmet understands that you want five list items.</p>
<p>This is extremely useful for menus, cards, tables, and layouts.</p>
<p>You save time and reduce typing fatigue.</p>
<hr />
<h2><strong>Generating Full HTML Boilerplate with Emmet</strong></h2>
<p>One of the most popular Emmet shortcuts is generating the HTML boilerplate.</p>
<p>If you type:</p>
<p><code>!</code> or <code>html:5</code> and then press Enter</p>
<p>Emmet generates this complete HTML structure:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769696686429/6ce4c2d5-4e40-470e-9d71-536b1b19c9d9.png" alt="" style="display:block;margin:0 auto" />

<ul>
<li><p>&lt;!DOCTYPE html&gt;</p>
</li>
<li><p>&lt;html&gt;</p>
</li>
<li><p>&lt;head&gt;</p>
</li>
<li><p>&lt;meta charset&gt;</p>
</li>
<li><p>&lt;body&gt;</p>
</li>
</ul>
<p>This is not magic.</p>
<p>It is just Emmet giving you a correct starting structure instantly.</p>
<p>This ensures beginners always start with valid HTML.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[How a Browser Works: A Beginner Friendly Guide to Browser Internals]]></title><description><![CDATA[What Really Happens Inside a Browser When You Open a Website?
Most people think a browser is just an app that opens websites. But in reality it is very complex, it is like a separate operating system,]]></description><link>https://blog.gurjeet.tech/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals</link><guid isPermaLink="true">https://blog.gurjeet.tech/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[Browsers]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 13:07:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769693824201/8de3a3aa-a5b2-47c1-a90b-8ac390ed460f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>What Really Happens Inside a Browser When You Open a Website?</strong></h2>
<p>Most people think a browser is just an app that opens websites. But in reality it is very complex, it is like a separate operating system, it is very different what we think. When we type a URL, press Enter and a page appears, it seems like magically the website landing page appears but behind the scenes, there are a lot of things going on in a specific order.<br />In this blog we will understand the complete behind the scene process, it is very important because every web developer works with the browser, whether they write HTML, CSS or JS.</p>
<p>Now let’s answer one simple question:</p>
<p><strong>What happens after when we type a URL and press Enter?</strong></p>
<h3><strong>A Browser Is Not One Thing</strong></h3>
<p>A browser is not a single program doing everything.</p>
<p>It is a collection of components, each with a clear job.</p>
<p>You can think of it like a small factory:</p>
<ul>
<li><p>One part talks to the internet</p>
</li>
<li><p>One part reads HTML</p>
</li>
<li><p>One part understands CSS</p>
</li>
<li><p>One part draws pixels on your screen</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769690995816/66d886d5-ee88-4577-8e61-fc0097e0ef42.png" alt="" style="display:block;margin:0 auto" />

<p>All of them work together to show a webpage.</p>
<p>At a very high level, a browser has:</p>
<ul>
<li><p>A user interface (address bar, tabs, buttons) - Handles visible elements like the address bar, tabs, back/forward buttons, bookmarks, and menus. It provides the interactive shell for user input and navigation, it is directly connected with browser’s backend.</p>
</li>
<li><p>A Browser Engine (Gecko - Used by Firefox , Blink - Used by Google Chrome, Webkit - Used by Apple) - Acts as a coordinator or bridge between the user interface and other core components, such as the rendering and user interface and javascript engine.</p>
</li>
<li><p>A networking layer (to fetch files) - Manages HTTP requests to fetch resources like HTML, CSS, images, and scripts from servers.</p>
</li>
<li><p>A rendering engine (to turn code into visuals) - Parses HTML/CSS into the DOM and CSSOM, builds the render tree, performs layout (calculating positions), and paints pixels to the screen.</p>
</li>
<li><p>A JavaScript engine (to run JS) - Compiles and executes JavaScript code, enabling dynamic interactions by manipulating the DOM. Examples: V8 (Chrome), SpiderMonkey (Firefox).</p>
</li>
<li><p>Internal data structures (DOM, CSSOM) - Core models like the DOM (Document Object Model) for HTML structure and CSSOM (CSS Object Model) for styles, used by rendering and JS engines for processing.</p>
</li>
</ul>
<p>Each part has one responsibility.</p>
<hr />
<h2><strong>The User Interface: Where Everything Starts</strong></h2>
<p>The user interface is the visible part of the browser.</p>
<p>This includes:</p>
<ul>
<li><p>Address bar</p>
</li>
<li><p>Back and forward buttons</p>
</li>
<li><p>Tabs</p>
</li>
<li><p>Reload button</p>
</li>
</ul>
<p>When you type a URL and press Enter, the UI does not load the website itself. User interface is usually connected with backend, that give functionality to the buttons.</p>
<p>It simply passes the URL to the browser’s internal systems and says: Go get whatever lives at this address.</p>
<hr />
<h2>Browser Engine vs Rendering Engine (simple distinction)</h2>
<p>The browser engine acts like a coordinator or manager. It sits between the user interface and the rest of the browser. When we type a URL, click refresh, open a new tab, or press the back button, the browser engine decides what should happen next.<br />It tells the networking part to fetch data, tells the rendering engine to update the page, and keeps everything moving in the correct order. It does not draw anything on the screen by itself. Its main job is coordination and control.</p>
<ul>
<li><p>The boss / coordinator</p>
</li>
<li><p>Controls the whole page loading process</p>
</li>
<li><p>Connects UI ↔ rendering ↔ JavaScript</p>
</li>
<li><p>Decides when things happen</p>
</li>
</ul>
<p>Overall, keep one thing in mind that browser engine is like a manger, who coordinated between different process.</p>
<p>The rendering engine, on the other hand, focuses only on turning code into visuals. It takes HTML and CSS, builds internal structures, calculates layout, paints pixels, and prepares the page for display. Whenever you see text, colors, boxes, or images on a webpage, that work is done by the rendering engine.</p>
<ul>
<li><p>The worker</p>
</li>
<li><p>Reads HTML + CSS</p>
</li>
<li><p>Calculates layout</p>
</li>
<li><p>Draws pixels on the screen</p>
</li>
</ul>
<p>Overall, thing render engine is like a painter, who paints the whole page UI.</p>
<hr />
<h2><strong>Networking: How a Browser Fetches HTML, CSS, and JavaScript</strong></h2>
<p>When we press Enter after typing a URL, the browser first needs to find where the website lives. Computers do not understand website names, so the browser must convert the domain name into an IP address. This is done using DNS.</p>
<p>The browser first checks its cache to see if it already knows the IP address. If not, it asks a DNS resolver. The resolver then follows a fixed path: it asks the root DNS server, then the TLD server (like .com or .app), and finally the authoritative DNS server. The authoritative DNS returns the correct IP address, which is sent back to the browser and saved in cache.</p>
<p>Once the browser has the IP address, it creates a connection with the server using TCP. If the site uses HTTPS, a secure connection is also established. After the connection is ready, the browser sends a request asking for the webpage.</p>
<p>The server responds with the HTML file. While reading the HTML, the browser finds links to CSS, JavaScript, images, and fonts, and sends more requests to fetch them. When all required files arrive, networking is done and the browser moves on to parsing and rendering the page.</p>
<hr />
<h2><strong>HTML Parsing: Turning Text into Structure</strong></h2>
<p>HTML arrives as plain text.</p>
<p>The browser cannot use text directly to draw a page.</p>
<p>So it parses the HTML.</p>
<p>Parsing simply means: Reading something step by step and understanding its meaning.</p>
<p>While reading HTML, the browser builds a structure called the DOM (Document Object Model).</p>
<p>You can imagine the DOM as a tree:</p>
<ul>
<li><p>&lt;html&gt; is the root</p>
</li>
<li><p>&lt;body&gt; is a branch</p>
</li>
<li><p>Headings, paragraphs, links are smaller branches</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769688683325/7163a613-d522-4a66-805e-324f420f73b9.png" alt="" style="display:block;margin:0 auto" />

<p>This DOM represents what elements exist on the page, not how they look.</p>
<hr />
<h2><strong>CSS Parsing: Understanding Styles</strong></h2>
<p>CSS is also plain text when downloaded.</p>
<p>The browser parses CSS separately and builds another structure called the CSSOM.</p>
<p>The CSSOM answers questions like:</p>
<ul>
<li><p>What color is this text?</p>
</li>
<li><p>How wide is this box?</p>
</li>
<li><p>Where should this element be positioned?</p>
</li>
</ul>
<p>So now the browser has:</p>
<ul>
<li><p>DOM → what exists</p>
</li>
<li><p>CSSOM → how it should look</p>
</li>
</ul>
<hr />
<h2><strong>DOM + CSSOM: Creating the Render Tree</strong></h2>
<p>The browser now combines DOM and CSSOM.</p>
<p>The result is the Render Tree.</p>
<p>The Render Tree:</p>
<ul>
<li><p>Includes only visible elements</p>
</li>
<li><p>Contains layout and style information</p>
</li>
<li><p>Is ready to be drawn on screen</p>
</li>
</ul>
<p>Hidden elements like display: none are excluded here**.**</p>
<hr />
<h2><strong>Layout, Painting, and Display</strong></h2>
<p>Once the Render Tree is ready, the browser moves through three final steps:</p>
<p><strong>Layout (Reflow)</strong></p>
<p>The browser calculates:</p>
<ul>
<li><p>Exact position of each element</p>
</li>
<li><p>Exact size of each element</p>
</li>
</ul>
<p><strong>Painting</strong></p>
<p>The browser fills pixels:</p>
<ul>
<li><p>Colors</p>
</li>
<li><p>Text</p>
</li>
<li><p>Images</p>
</li>
<li><p>Borders</p>
</li>
</ul>
<p><strong>Display (Compositing)</strong></p>
<p>Everything is combined and sent to your screen.</p>
<p>At this point, you finally see the webpage.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769691794418/6622bb8e-97c6-4bed-9429-71b40000e073.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>A Very Simple Parsing Example</strong></h2>
<p>Parsing simply means breaking something into parts and understanding its structure.</p>
<p>Take this expression: 1 + 2 * 3.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769690240052/caf33362-8ced-4170-b9e1-e76822172247.png" alt="" style="display:block;margin:0 auto" />

<p>At first glance, it looks like a single line of text. But to evaluate it correctly, we cannot read it from left to right blindly.</p>
<p>A parser first looks at the expression and understands the rules. It knows that multiplication has higher priority than addition. So instead of adding first, it groups 2 * 3 together.</p>
<p>The parser then converts this expression into a tree. At the top is the + operator. On one side is 1. On the other side is the *operator, which has 2 and 3 as its children.</p>
<p>This tree structure clearly shows what should happen first and what should happen next. The computer can now easily evaluate the expression by following the tree.</p>
<p>Browsers do the same thing with HTML and CSS. They take plain text, parse it, and turn it into tree structures like the DOM and CSSOM so the page can be understood and rendered correctly.</p>
<p><strong>Just remember the flow:</strong></p>
<ol>
<li><p>URL entered</p>
</li>
<li><p>Files fetched</p>
</li>
<li><p>HTML → DOM</p>
</li>
<li><p>CSS → CSSOM</p>
</li>
<li><p>DOM + CSSOM → Render Tree</p>
</li>
<li><p>Layout → Paint → Display</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Understanding HTML Tags and Elements]]></title><description><![CDATA[HTML is usually the first thing people learn when they start web development. Because it looks simple, many beginners don’t take it seriously. They think HTML is just about writing a few tags and then]]></description><link>https://blog.gurjeet.tech/understanding-html-tags-and-elements</link><guid isPermaLink="true">https://blog.gurjeet.tech/understanding-html-tags-and-elements</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[HTML]]></category><dc:creator><![CDATA[Gurjeet Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 10:53:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769684604901/bf9121fe-2f2f-484b-abc5-e28e3d3adae9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>HTML is usually the first thing people learn when they start web development. Because it looks simple, many beginners don’t take it seriously. They think HTML is just about writing a few tags and then moving on to CSS or JavaScript.<br />But HTML is not just syntax. It is a core part of the World Wide Web. To really understand web development, you need to understand what HTML is, why it exists, and how browsers use it.<br />This article explains HTML from the basics, focusing on ideas and meaning, not memorisation.</p>
<h2>What HTML is and why we use it</h2>
<p>The question is why HTML exist and why we use it. Before HTML exist, documents on the computer were just plain text files, that files has no built in structure and no standardised way to connect documents together across different devices. Sharing documents globally was difficult.</p>
<p>In 1989, Tim Berners Lee was working at CERN. He proposed a system to share information using connected documents. This idea later became the World Wide Web (WWW).</p>
<p>The World Wide Web was built using three main parts:</p>
<ul>
<li><p><strong>HTML</strong> - To describe documents</p>
</li>
<li><p><strong>HTTP</strong> - To transfer documents</p>
</li>
<li><p><strong>URLs</strong> - To locate documents</p>
</li>
</ul>
<p>HTML was not created alone. It was created as one part of the web system. Its role was clear, describe the structure and meaning of documents so that they could be shared and read anywhere.</p>
<p>HTML was designed mainly for documents, not apps. That is why it focuses on text, headings, paragraphs, and links.</p>
<p>So basically, HTML(HyperText Markup Language) is not a programming language. It is a declarative markup language that describes Structure + Meaning of the document so that machine (browser) render it.<br />HTML is like, it describes things,</p>
<ul>
<li><p>This is header <code>&lt;h1&gt;Header&lt;/h1&gt;</code></p>
</li>
<li><p>This is paragraph <code>&lt;p&gt;Paragraph&lt;/p&gt;</code></p>
</li>
<li><p>This is image <code>&lt;img&gt;</code></p>
</li>
<li><p>This part is navigation <code>&lt;nav&gt;Nav Bar&lt;/nav&gt;</code></p>
</li>
<li><p>This part is main content <code>&lt;main&gt;Main Content&lt;/main&gt;</code></p>
</li>
</ul>
<p><strong>HTML as structure of Web</strong></p>
<p>Think of HTML as the structure that holds the web together. A webpage without CSS and JavaScript still works. You can still read the content. That content exists because of HTML.<br />But without HTML, there is nothing to show at all. That is why HTML is always present, even in modern frameworks. React, Vue, and others still produce HTML in the end, because browsers understand HTML, not frameworks.<br />HTML only describes meaning</p>
<ul>
<li><p>CSS controls how things look</p>
</li>
<li><p>JavaScript controls how things behave</p>
</li>
<li><p>HTML stays focused on structure.</p>
</li>
</ul>
<hr />
<h2>What an HTML tag is</h2>
<p>An HTML tag is a marker used to describe content. A tag tells the browser where something starts or ends.<br />Example:</p>
<p><code>&lt;p&gt;</code></p>
<p>This tag tells the browser that a paragraph starts here.</p>
<p>Tags are not content. Users never see them. They exist only for browsers and machines to understand the structure of a document.</p>
<p>There are three main kinds of tags:</p>
<ul>
<li><p>opening tags</p>
</li>
<li><p>closing tags</p>
</li>
<li><p>self closing (void) tags</p>
</li>
</ul>
<p>Each type helps define how content is structured.</p>
<hr />
<h2>Opening tag, Closing tag and Content</h2>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769678927723/c9f68a68-1031-41f0-bc13-8417df8603cd.png" alt="" style="display:block;margin:0 auto" />

<p>Consider this example:</p>
<p><code>&lt;p&gt;This is a paragraph&lt;/p&gt;</code></p>
<p>This line has three parts:</p>
<ul>
<li><p>&lt;p&gt; tells where the paragraph starts</p>
</li>
<li><p>This is a paragraph is the actual content</p>
</li>
<li><p>&lt;/p&gt; tells where the paragraph ends</p>
</li>
</ul>
<p>Closing tags are important because HTML is based on structure. If we do not add closing tag then browser will not know like after how much text this paragraph should be ended. To start using other tag we have to end previous one. The browser needs to know where one element ends and another begins.</p>
<hr />
<h2>What an HTML element means</h2>
<p>An HTML element is the complete unit formed by tags and content. It combines both opening tag + content + closing tag (if required).</p>
<p>An element includes:</p>
<ul>
<li><p>opening tag</p>
</li>
<li><p>content</p>
</li>
<li><p>closing tag (if required)</p>
</li>
</ul>
<p>So this:</p>
<p><code>&lt;p&gt;This is a paragraph&lt;/p&gt;</code></p>
<p>is one element.</p>
<p>A tag is only a part of an element.</p>
<p>Browsers convert HTML into a structure in memory called the DOM (Document Object Model). JavaScript works with this DOM, not directly with the HTML text.</p>
<p>That is why JavaScript selects elements, not tags.</p>
<hr />
<h2><strong>Self Closing (Void) Elements</strong></h2>
<p>Some elements do not wrap content. These are called void elements. These elements do not have any kind of closing tag, they work without closing tags,</p>
<p>Examples include:</p>
<ul>
<li><p><code>&lt;img&gt;</code></p>
</li>
<li><p><code>&lt;br&gt;</code></p>
</li>
<li><p><code>&lt;input&gt;</code></p>
</li>
</ul>
<p>These elements represent single things, such as an image or an input field. Because there is nothing inside them, they do not need closing tags.</p>
<hr />
<h2><strong>Block Level and Inline Elements</strong></h2>
<p>HTML elements are divided into block level and inline elements to describe structure.</p>
<p>Block level elements are used to build the main layout of a page. They usually start on a new line and group content together. They contains full width of the screen</p>
<p>Examples:</p>
<ul>
<li><p><code>&lt;div&gt;</code></p>
</li>
<li><p><code>&lt;p&gt;</code></p>
</li>
<li><p><code>&lt;h1&gt;</code></p>
</li>
<li><p><code>&lt;section&gt;</code></p>
</li>
</ul>
<p>Inline elements are used inside text. They do not break the line and are meant to describe small parts of content. They contain only that much space that is needed.</p>
<p>Examples:</p>
<ul>
<li><p><code>&lt;span&gt;</code></p>
</li>
<li><p><code>&lt;a&gt;</code></p>
</li>
<li><p><code>&lt;strong&gt;</code></p>
</li>
</ul>
<p>A simple idea is:</p>
<ul>
<li><p>block elements are containers</p>
</li>
<li><p>inline elements live inside containers</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769683228139/85e2ef57-44ed-4bb2-9bf0-f34e3c35b451.png" alt="" style="display:block;margin:0 auto" />

<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769683250430/46fe5fc7-8cae-41b5-b32d-8c67cf0a84a2.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2><strong>Why Semantic HTML Exists</strong></h2>
<p>As the web grew, developers needed a clearer way to describe meaning. This is like telling browser that this part include this type of content and this part includes that types of content. Semantic tags give meaning to the structure of the website, this is helpful for screen readers that work behind the scene in the browser. Screen readers helps visual impaired people to understand the content of the website.</p>
<p>Tags like:</p>
<ul>
<li><p><code>&lt;header&gt;</code></p>
</li>
<li><p><code>&lt;nav&gt;</code></p>
</li>
<li><p><code>&lt;main&gt;</code></p>
</li>
<li><p><code>&lt;footer&gt;</code></p>
</li>
</ul>
<p>tell what a section is meant for.</p>
<p>These tags help:</p>
<ul>
<li><p>search engines understand content</p>
</li>
<li><p>screen readers work better</p>
</li>
<li><p>developers read code more easily</p>
</li>
</ul>
<p>Semantic HTML keeps documents clear and meaningful, just like HTML was originally designed to be.</p>
<hr />
<h2><strong>Commonly Used HTML Tags</strong></h2>
<p>HTML has many tags, but they all exist for a reason.</p>
<p>Some tags are used to structure text, such as headings and paragraphs. Some are used for grouping content, like &lt;div&gt; and &lt;span&gt;. Others are used for links, images, and forms.</p>
<p>For example:</p>
<ul>
<li><p>headings show importance and order</p>
</li>
<li><p>paragraphs group sentences</p>
</li>
<li><p>links connect pages</p>
</li>
<li><p>images display media</p>
</li>
<li><p>form tags collect user input</p>
</li>
</ul>
<p>Some frequently used HTML tags are:</p>
<ul>
<li><p><code>&lt;html&gt;</code> - Root of the document</p>
</li>
<li><p><code>&lt;head&gt;</code> - Metadata</p>
</li>
<li><p><code>&lt;title&gt;</code> - Page title</p>
</li>
<li><p><code>&lt;body&gt;</code> - Visible content</p>
</li>
<li><p><code>&lt;h1&gt;</code> to <code>&lt;h6&gt;</code> - Headings</p>
</li>
<li><p><code>&lt;p&gt;</code> - Paragraph</p>
</li>
<li><p><code>&lt;a&gt;</code> - Link</p>
</li>
<li><p><code>&lt;img&gt;</code> - Image</p>
</li>
<li><p><code>&lt;div&gt;</code> - Container</p>
</li>
<li><p><code>&lt;span&gt;</code> - Inline container</p>
</li>
<li><p><code>&lt;br&gt;</code> - Line break</p>
</li>
<li><p><code>&lt;hr&gt;</code> - Horizontal line</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>