<?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[🧊 GaurangPods]]></title><description><![CDATA[I believe the thoughtful use of technology quietly improves lives, and that belief fuels everything I build and explore 💻. Whatever I learn during this exploration, I try to share it here so others can benefit from it. I’m fascinated by how technology empowers people, businesses, and startups.]]></description><link>https://blogs.gaurangpods.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 15:11:37 GMT</lastBuildDate><atom:link href="https://blogs.gaurangpods.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Template Literals in JavaScript]]></title><description><![CDATA[Let’s start with what we were doing earlier before template literals even came into picture.
When we had to combine strings with variables, we used normal string concatenation. Something like:
const n]]></description><link>https://blogs.gaurangpods.com/template-literals-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/template-literals-in-javascript</guid><category><![CDATA[template literals]]></category><category><![CDATA[basics]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Fri, 24 Apr 2026 09:20:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/2b8b1009-9fea-4b6a-98a4-06b981c35324.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let’s start with what we were doing earlier before template literals even came into picture.</p>
<p>When we had to combine strings with variables, we used normal string concatenation. Something like:</p>
<pre><code class="language-javascript">const name = "Gaurang";
const age = 20;

const message = "My name is " + name + " and I am " + age + " years old.";
</code></pre>
<p>Now this works, there is no issue as such. But if you look at it closely, it starts getting messy very quickly. You have quotes, plus signs, spaces that you need to manually handle, and if the string gets longer, it becomes harder to read.</p>
<p>Now imagine if there are multiple variables or conditions. It becomes even more cluttered. You might even miss a space or a quote and then spend time figuring out what went wrong.</p>
<p>This is exactly the problem template literals try to solve.</p>
<h3>What are template literals</h3>
<p>Template literals are just another way of writing strings in JavaScript, but with more flexibility.</p>
<p>Instead of using single quotes or double quotes, we use backticks.</p>
<p>So the same example becomes:</p>
<pre><code class="language-javascript">const name = "Gaurang";
const age = 20;

const message = `My name is \({name} and I am \){age} years old.`;
</code></pre>
<p>Now if you compare both, this one feels more natural to read. It almost looks like a normal sentence.</p>
<p>So the main idea here is instead of breaking the string and adding variables using plus, we directly embed variables inside the string using this syntax: ${variable}</p>
<h3>Embedding variables inside strings</h3>
<p>This is where template literals actually shine.</p>
<p>Inside backticks, whenever you want to insert a variable, you use ${ } and put the variable inside it.</p>
<p>For example:</p>
<pre><code class="language-javascript">const price = 100;
const quantity = 2;

const total = `Total price is ${price * quantity}`;
</code></pre>
<p>Here we are not just putting a variable, we are even doing a calculation inside it. That is something you cannot do cleanly with normal concatenation without making it look messy. So basically whatever you put inside ${ } gets evaluated and then inserted into the string.</p>
<h3>Multi line strings</h3>
<p>Now this is something which used to be annoying earlier. If you wanted a string in multiple lines, you had to do something like this:</p>
<pre><code class="language-javascript">const text = "This is line one\n" +
             "This is line two\n" +
             "This is line three";
</code></pre>
<p>Again, not wrong, but not very clean.</p>
<p>With template literals, you can directly write:</p>
<pre><code class="language-javascript">const text = `This is line one
This is line two
This is line three`;
</code></pre>
<p>And that is it. No extra symbols, no manual line breaks.</p>
<p>It just works as you write it.</p>
<h3>Comparing old vs new approach</h3>
<p>If you really compare both approaches, the difference is mostly about readability. With concatenation, your focus shifts to managing syntax. You are thinking about quotes, plus signs, spacing. With template literals, your focus shifts back to the actual content of the string and that is a big deal when your code grows.</p>
<h3>Where this is actually useful</h3>
<p>In real projects, strings are everywhere. you are building UI messages, logging data, creating dynamic content, working with APIs. In all these places, you often need to combine static text with dynamic values. Template literals make this process smoother.</p>
<p>Especially when dealing with:</p>
<p>dynamic messages, HTML templates in frontend, logging complex values, building URLs with variables</p>
<p>It reduces chances of mistakes and improves readability.</p>
<h3>One small thing to remember</h3>
<p>Template literals are not just for variables. They can also handle expressions, so anything inside ${ } is evaluated.</p>
<p>For example:</p>
<pre><code class="language-javascript">const a = 5;
const b = 10;

console.log(`Sum is ${a + b}`);
</code></pre>
<p>This directly gives you the computed result inside the string.</p>
<h3>Closing thought</h3>
<p>At the end of the day, template literals are not about doing something new. They are about doing the same thing in a cleaner way. String concatenation still works, and it will always work. But once you start using template literals, going back feels unnecessary.<br />It just makes the code easier to read, easier to write, and honestly less error prone and in real development, that clarity matters more than anything else.</p>
]]></content:encoded></item><item><title><![CDATA[Array Flatten in JavaScript]]></title><description><![CDATA[So let’s start from the very basic idea. When we talk about arrays, we usually think of a simple list of elements separated by commas. Something like [1, 2, 3, 4], clean and straightforward. But thing]]></description><link>https://blogs.gaurangpods.com/array-flatten-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/array-flatten-in-javascript</guid><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[basics]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Fri, 24 Apr 2026 08:03:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/765c847b-8866-4091-86ab-242ae76fc6ca.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So let’s start from the very basic idea. When we talk about arrays, we usually think of a simple list of elements separated by commas. Something like [1, 2, 3, 4], clean and straightforward. But things start getting a bit layered when one of those elements itself becomes an array.</p>
<p>That is exactly what a nested array is.</p>
<p>If you have something like [1, 2, [3, 4], 5], then the third element is not just a number, it is another array. So now you have an array inside an array. That is your simplest form of a nested array. And this does not stop at just one level. You can go deeper like [1, [2, [3, [4]]]] and it keeps going depending on how complex the data is.</p>
<p>Now the problem starts when we try to work with such data.</p>
<p>Because honestly, dealing with nested arrays directly is not very convenient. Imagine you want to sum all numbers or apply some logic. You now have to handle multiple levels, check if something is an array, then go inside it, and so on. This is where flattening comes into picture.</p>
<p>Flattening simply means converting a nested array into a single level array. So instead of [1, 2, [3, 4], 5], you turn it into [1, 2, 3, 4, 5]. Everything comes out at the same level.</p>
<p>That is the whole idea. Take a complex structure and simplify it.</p>
<p>If you visualize it, think of nested arrays like boxes inside boxes. Flattening is just opening all the boxes and putting everything on the table.</p>
<p>Now coming to how JavaScript helps us here.</p>
<h3>The .flat() method</h3>
<p>This is the most direct way to deal with nested arrays. If you have an array and you call .flat() on it, JavaScript will remove one level of nesting.</p>
<p>For example:</p>
<pre><code class="language-javascript">const arr = [1, 2, [3, 4], 5];
console.log(arr.flat());
// [1, 2, 3, 4, 5]
</code></pre>
<p>What it does is it breaks that inner array and pulls its elements into the main array.</p>
<p>Now an interesting part is that .flat() can take an argument. That argument decides how many levels you want to flatten.</p>
<p>So if you have something deeper like:</p>
<pre><code class="language-javascript">const arr = [1, [2, [3, [4]]]];
</code></pre>
<p>If you do:</p>
<pre><code class="language-javascript">arr.flat(1)
</code></pre>
<p>It will only remove one level.</p>
<p>If you do:</p>
<pre><code class="language-javascript">arr.flat(2)
</code></pre>
<p>It will go two levels deep.</p>
<p>And if you are not sure how deep your nesting is, which honestly happens most of the time, you can just do:</p>
<pre><code class="language-javascript">arr.flat(Infinity)
</code></pre>
<p>This basically says flatten everything, no matter how deep it is.</p>
<p>This is why in real scenarios, people often go with Infinity because counting levels manually is not always practical.</p>
<h3>The .flatMap() method</h3>
<p>Now this one is slightly different. It combines two operations into one. First mapping, then flattening.</p>
<p>You already know that .map() applies a function to each element and returns a new array. The number of elements stays the same.</p>
<p>For example:</p>
<pre><code class="language-javascript">[1, 2, 3].map(x =&gt; x * 2)
// [2, 4, 6]
</code></pre>
<p>Now .flatMap() does something similar, but after mapping, it also flattens the result by one level.</p>
<p>So if your mapping function returns arrays, .flatMap() will merge them into a single array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const arr = [1, 2, 3];

const result = arr.flatMap(x =&gt; [x, x * 2]);
console.log(result);
// [1, 2, 2, 4, 3, 6]
</code></pre>
<p>Here each element becomes an array, and then those arrays get flattened automatically.</p>
<p>One important thing to note is that .flatMap() only flattens one level. You cannot control depth here like .flat().</p>
<p>So if your nesting is deeper, .flatMap() alone will not solve everything.</p>
<h3>Another approach you might see</h3>
<p>Sometimes in interviews or even real projects, people do not use .flat() directly. Either because they want to show understanding or because of compatibility reasons.</p>
<p>A common way is using recursion.</p>
<p>The idea is simple. You go through each element. If it is not an array, you push it into a result. If it is an array, you call the same function again on it.</p>
<p>Something like this:</p>
<pre><code class="language-typescript">function flatten(arr) {
  let result = [];

  for (let item of arr) {
    if (Array.isArray(item)) {
      result = result.concat(flatten(item));
    } else {
      result.push(item);
    }
  }

  return result;
}
</code></pre>
<p>This works for any level of nesting and shows clear thinking.</p>
<h3>Why flattening is actually useful</h3>
<p>This is not just a theoretical thing. In real problems, data often comes nested.</p>
<p>APIs can return nested structures. UI components might generate nested lists. Even simple transformations can accidentally create nested arrays.</p>
<p>Before applying operations like filtering, reducing, or calculations, flattening makes the data easier to work with.</p>
<p>It is like cleaning your workspace before starting actual work.</p>
<h3>Common interview scenarios</h3>
<p>This topic shows up quite often, but not always in a direct way.</p>
<p>Sometimes they simply ask you to flatten an array without using built in methods. That is where recursion or loops come into play.</p>
<p>Sometimes they give you a nested structure and ask you to extract or sum values. If you understand flattening, the problem becomes much simpler.</p>
<p>Another variation is combining map and flatten logic, where .flatMap() becomes useful.</p>
<p>And in some cases, they check whether you know about Infinity in .flat() which is a small detail but tells a lot about practical exposure.</p>
<h3>Closing thought</h3>
<p>At the core of it, flattening is about reducing complexity. Nested arrays are not wrong, they are just harder to deal with directly. Once flattened, everything becomes linear and easier to process.</p>
<p>If you understand when to use .flat(), when .flatMap() fits, and how to manually approach the problem, you are already ahead for most real scenarios as well as interviews.</p>
<p>And honestly, once you start noticing nested arrays in real data, this concept stops being theoretical and becomes very practical.</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Modules: Import and Export Explained]]></title><description><![CDATA[In this blog, we will understand modules from the ground up. We will go from what modules are, why they are needed, how export and import work, and finally touch on bundlers at a basic level. The goal]]></description><link>https://blogs.gaurangpods.com/javascript-modules-and-import-export-explained</link><guid isPermaLink="true">https://blogs.gaurangpods.com/javascript-modules-and-import-export-explained</guid><category><![CDATA[import export ]]></category><category><![CDATA[modules]]></category><category><![CDATA[clean code]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Thu, 23 Apr 2026 12:58:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/83c2d867-1ffc-4f3f-908e-68f142e79e7d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog, we will understand modules from the ground up. We will go from what modules are, why they are needed, how export and import work, and finally touch on bundlers at a basic level. The goal is to make the whole flow clear without overcomplicating things.</p>
<p>When we write code in a single file, everything sits together. As the project grows, this becomes messy. Functions, classes, and logic start overlapping, and it becomes hard to manage.</p>
<p>To solve this, we divide code into smaller parts. These parts are called modules.</p>
<p>A module is simply a file (or a group of files) that contains code which can be used in other files.</p>
<p>If a file contains reusable code and we expose it using export, it becomes a module. That reusable code is what we call modular code.</p>
<p>Why modules are needed</p>
<p>Without modules, things start breaking down in a very practical way. Code becomes scattered. The same logic gets written again &amp; again. It becomes hard to find where a specific function is written. Debugging slows down. Updating a feature becomes risky because you are not sure what else might break.</p>
<p>Here is a simple example of the problem:</p>
<pre><code class="language-js">// everything in one file

function calculateTotal() { }
function sendEmail() { }
function validateUser() { }
function generateReport() { }
</code></pre>
<p>Now imagine this file grows to 2000 lines. Finding anything becomes painful.</p>
<p>What modular code does</p>
<p>We break code into meaningful groups.</p>
<pre><code class="language-javascript">// user.js
export function validateUser() { }

// order.js
export function calculateTotal() { }

// email.js
export function sendEmail() { }
</code></pre>
<p>Now everything is organized. Each file has a purpose. It is easy to locate code. Easy to update. Easy to reuse. This is modular code.</p>
<h3>Exporting code</h3>
<p>1. Named Export</p>
<p>We export multiple things by their names.</p>
<pre><code class="language-javascript">// math.js
export function add(a, b) {
  return a + b;
}

export function subtract(a, b) {
  return a - b;
}
</code></pre>
<p>Importing:</p>
<pre><code class="language-javascript">import { add, subtract } from './math.js';
</code></pre>
<p>Here you must use the exact names, and you must use curly braces.</p>
<p>2.Default Export</p>
<p>We export only one main thing.</p>
<pre><code class="language-javascript">// logger.js
export default function log(message) {
  console.log(message);
}
</code></pre>
<p>Importing:</p>
<pre><code class="language-javascript">import log from './logger.js';
</code></pre>
<p>Here there are no curly braces, and the name can be anything.</p>
<pre><code class="language-javascript">import myLogger from './logger.js';
</code></pre>
<p>Exporting entire file:</p>
<p>There is no single keyword like export all automatically, but there are practical ways to achieve this.</p>
<p>Option 1: Export everything manually from a file</p>
<pre><code class="language-javascript">// utils.js
export function a() {}
export function b() {}
export function c() {}
</code></pre>
<p>Then import everything together:</p>
<pre><code class="language-javascript">import * as utils from './utils.js';

utils.a();
utils.b();
</code></pre>
<p>This is the closest to importing the whole file.</p>
<p>Option 2: Export as one object</p>
<pre><code class="language-javascript">// utils.js
function a() {}
function b() {}

const utils = {
  a,
  b
};

export default utils;
</code></pre>
<p>Import:</p>
<pre><code class="language-javascript">import utils from './utils.js';

utils.a();
</code></pre>
<p>Here utils is clearly defined inside the file, so the flow is complete.</p>
<p>Importing modules (flow):</p>
<p>The flow is simple. You write code in a file. You export the required parts. Then you import them wherever needed. That is the full cycle.</p>
<p>Benefits of modular code</p>
<p>Reusability - You write once and use it everywhere. Maintainability - It is easy to update specific parts. Readability - Code stays clean and structured. Scalability - The project can grow without chaos. Developer efficiency - You do not have to search the entire codebase.</p>
<h3>Code organization improvement:</h3>
<p>Without modules, everything is mixed and there is no clear structure.</p>
<p>With modules, we get feature based grouping, logical separation, and faster navigation.</p>
<p>Example:</p>
<pre><code class="language-javascript">/project
  /user
    user.service.js
    user.controller.js
  /order
    order.service.js
</code></pre>
<p>Now you instantly know where to go.</p>
<h3>What are bundlers?</h3>
<p>A bundler is a tool that takes multiple modules and combines them into a smaller number of files, often a single optimized file.</p>
<p>Tools like Webpack or Vite do this.</p>
<p>Why this is needed is simple. Browsers are not efficient at loading hundreds of small files separately. Bundlers optimize this by packaging things together.</p>
<p>For now, while learning modules, you do not need to go deep into bundlers. Just focus on export and import.</p>
<h3>Final clarity</h3>
<p>A module is not just any file, but a file designed for reuse. Export does not automatically export everything. Named export uses curly braces while importing. Default export does not use curly braces. And if you want something close to importing the whole file, you can use import * as.</p>
<p>This completes the full picture from modules to bundlers in a clean and usable way.  </p>
<p>I tried covering all essentials under one hut. I hope this was helpful.</p>
]]></content:encoded></item><item><title><![CDATA[Control Flow in JavaScript: If, Else, and Switch Explained]]></title><description><![CDATA[When we write programs, we are not just asking the computer to execute instructions one after another. Real programs often need to make decisions based on conditions. Sometimes we want something to ha]]></description><link>https://blogs.gaurangpods.com/control-flow-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/control-flow-in-javascript</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[if-else]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 17:58:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/6dbd998f-6bf0-45a1-8074-5dcfb100bd10.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we write programs, we are not just asking the computer to execute instructions one after another. Real programs often need to make decisions based on conditions. Sometimes we want something to happen only if a certain requirement is met. Other times we want different actions depending on different situations.</p>
<p>This ability to control the path that a program follows is called <strong>control flow</strong>.</p>
<p>In simple terms, control flow determines <strong>which part of the code runs and when it runs</strong>.</p>
<p>To understand this better, think about a small real life example.</p>
<p>Imagine you are leaving your house in the morning.</p>
<p>If it is raining, you take an umbrella.<br />If it is not raining, you simply leave.</p>
<p>Your decision depends on a condition. Programming works in a very similar way. The program checks a condition and decides which instruction should run.</p>
<p>JavaScript provides several control flow structures that allow us to make these decisions.</p>
<p>In this article we will explore</p>
<p>The if statement<br />The if else statement<br />The else if ladder<br />The switch statement<br />When to use switch vs if else</p>
<p>Everything will be explained with simple beginner friendly examples.</p>
<h3>The if statement</h3>
<p>The <strong>if statement</strong> is the most basic way to control program flow. It allows the program to run a block of code only when a condition is true.</p>
<p>Think of it as asking a question.</p>
<p>If the answer is true, the code runs.<br />If the answer is false, the code is skipped.</p>
<p>Here is a simple example.</p>
<pre><code class="language-javascript">let age = 20;

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

console.log("Program finished.");
</code></pre>
<p>Output</p>
<p>You are eligible to vote.  </p>
<p>Program finished.</p>
<p>Step by step explanation</p>
<p>First the variable age is stored as 20.  </p>
<p>The program checks the condition age &gt;= 18.  </p>
<p>Since 20 is greater than 18, the condition becomes true.  </p>
<p>Because it is true, the message inside the if block runs.</p>
<p>If the age was smaller than 18, the message inside the block would simply not run.</p>
<p>The program would continue with the next instruction.</p>
<h3>The if else statement</h3>
<p>Sometimes we want the program to do <strong>one thing if the condition is true and another thing if it is false</strong>.</p>
<p>For that we use the <strong>if else statement</strong>.</p>
<p>It provides two possible paths for the program.</p>
<p>Example</p>
<pre><code class="language-javascript">let marks = 45;

if (marks &gt;= 50) {
    console.log("You passed the exam.");
} else {
    console.log("You did not pass the exam.");
}
</code></pre>
<p>Output</p>
<p>You did not pass the exam.</p>
<p>Explanation</p>
<p>The program checks whether marks are greater than or equal to 50.  </p>
<p>Since 45 is less than 50, the condition becomes false.  </p>
<p>Because of this, the code inside the else block runs.</p>
<p>This structure is very useful when you want to clearly handle both outcomes of a condition.</p>
<h3>The else if ladder</h3>
<p>In many situations we have more than two possibilities.</p>
<p>For example, when checking grades, we may want different messages depending on the marks obtained.</p>
<p>This is where the <strong>else if ladder</strong> becomes useful.</p>
<p>It allows the program to check multiple conditions one after another.</p>
<p>Example</p>
<pre><code class="language-javascript">let score = 82;

if (score &gt;= 90) {
    console.log("Grade A");
} else if (score &gt;= 75) {
    console.log("Grade B");
} else if (score &gt;= 60) {
    console.log("Grade C");
} else {
    console.log("Grade D");
}
</code></pre>
<p>Output</p>
<p>Grade B</p>
<p>How the program runs</p>
<p>The program first checks if score is greater than or equal to 90.  </p>
<p>Since 82 is not greater than 90, it moves to the next condition.</p>
<p>Next it checks whether score is greater than or equal to 75.  </p>
<p>This time the condition is true.</p>
<p>Because this condition is true, the program prints Grade B and stops checking the remaining conditions.</p>
<p>Only the first true condition gets executed.</p>
<p>This step by step checking is what makes the else if ladder powerful for handling multiple scenarios.</p>
<h3>The switch statement</h3>
<p>Another way to control program flow is the <strong>switch statement</strong>.</p>
<p>Switch is commonly used when we want to compare a variable with several fixed values.</p>
<p>It can sometimes make the code cleaner than writing many else if statements.</p>
<p>Example</p>
<pre><code class="language-javascript">let dayNumber = 3;

switch (dayNumber) {
    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("Invalid day number");
}
</code></pre>
<p>Output</p>
<p>Wednesday</p>
<p>Explanation</p>
<p>The switch statement checks the value of dayNumber.</p>
<p>If the value matches case 1, it prints Monday.  </p>
<p>If it matches case 2, it prints Tuesday.  </p>
<p>If it matches case 3, it prints Wednesday.</p>
<p>Since the value is 3, the third case runs.</p>
<p>The <strong>break statement</strong> is very important here.</p>
<p>Once a case matches, break stops the program from continuing to the next cases.</p>
<p>If break was missing, the program would continue running the remaining cases as well. This is called fall through behavior.</p>
<p>The default block runs if none of the cases match.</p>
<h3>When to use switch vs if else</h3>
<p>Both switch and if else help control program flow, but they are suited for slightly different situations.</p>
<p>If else is better when</p>
<p>You are checking ranges like marks greater than 80 or age less than 18  </p>
<p>You have complex conditions involving multiple variables  </p>
<p>You need logical comparisons like greater than or less than</p>
<p>Switch is better when</p>
<p>You are comparing one variable against multiple fixed values  </p>
<p>The cases are clear and predefined such as days of the week or menu options  </p>
<p>You want cleaner and more structured code</p>
<p>For example, checking grade ranges is easier with if else.</p>
<p>But printing a day of the week based on a number is usually cleaner with switch.</p>
<p>Understanding when to use each structure helps make your code more readable and maintainable.</p>
<h3>Assignment practice</h3>
<p>To truly understand control flow, the best approach is to practice writing small programs.</p>
<p>Try implementing the following exercises.</p>
<p>Program 1</p>
<p>Write a program that checks whether a number is positive, negative, or zero.</p>
<p>Example code idea</p>
<pre><code class="language-javascript">let number = -5;

if (number &gt; 0) {
    console.log("The number is positive.");
} else if (number &lt; 0) {
    console.log("The number is negative.");
} else {
    console.log("The number is zero.");
}
</code></pre>
<p>Output</p>
<p>The number is negative.</p>
<p>In this program we used the <strong>else if ladder</strong> because there are three possible conditions.</p>
<p>Program 2</p>
<p>Write a program that prints the day of the week using a switch statement.</p>
<p>Example idea</p>
<pre><code class="language-javascript">let day = 5;

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

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

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

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

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

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

    case 7:
        console.log("Saturday");
        break;

    default:
        console.log("Invalid input");
}
</code></pre>
<p>Output</p>
<p>Thursday</p>
<p>We used a switch here because we were comparing a single variable with fixed values representing days of the week.</p>
<h3>Final thoughts</h3>
<p>Control flow is one of the most important foundations in programming. Without it, a program would simply run every line of code from top to bottom without making any decisions.</p>
<p>Using if, if else, else if ladders, and switch statements allows us to create intelligent programs that respond to different situations.</p>
<p>As you continue learning JavaScript, these concepts will appear everywhere. From validating user input to controlling application behavior, decision making structures form the backbone of real software.</p>
<p>The best way to master them is by experimenting with small examples and observing how the program behaves when the conditions change.</p>
<p>Once you become comfortable with control flow, writing logical and structured programs becomes much easier.</p>
<p>Hope this blog gave the necessary insights needed.</p>
]]></content:encoded></item><item><title><![CDATA[Arrow Functions in JavaScript: A Simpler Way to Write Functions]]></title><description><![CDATA[When people first start learning JavaScript, functions often look a little bulky. You write the function keyword, give the function a name, add parentheses, then curly brackets, and finally a return s]]></description><link>https://blogs.gaurangpods.com/arrow-functions-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/arrow-functions-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[functions]]></category><category><![CDATA[ Arrow Functions In JavaScript]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 17:39:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/72e834ec-3801-4c1c-bb79-ee2cee31597c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When people first start learning JavaScript, functions often look a little bulky. You write the function keyword, give the function a name, add parentheses, then curly brackets, and finally a return statement. It works perfectly fine, but sometimes it feels like a lot of ceremony for doing something very small. For simple tasks like adding numbers or greeting someone, the traditional function syntax can feel slightly verbose.</p>
<p>Modern JavaScript introduced arrow functions to reduce this boilerplate and make functions shorter and easier to read. They are widely used in real projects today, especially when working with arrays, callbacks, and functional programming patterns. Once you start seeing them in codebases, you realize how frequently they appear in everyday JavaScript development.</p>
<p>In this article we will understand what arrow functions are, how their syntax works, how implicit return works, and how they differ from normal functions. The goal here is not to dive into complex theory but to build a clear beginner level understanding with simple and practical examples. Let us start by seeing why arrow functions exist in the first place.</p>
<h3>How arrow functions reduce boilerplate</h3>
<p>Consider a simple function that adds two numbers.</p>
<pre><code class="language-javascript">function add(a, b) {
  return a + b;
}

console.log(add(4, 6));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">10
</code></pre>
<p>This is completely valid and you will still see this style everywhere. But for a very small operation like addition, writing the function keyword and the return statement every time can feel slightly repetitive.</p>
<p>Arrow functions allow us to write the same logic in a shorter and cleaner way.</p>
<pre><code class="language-javascript">const add = (a, b) =&gt; {
  return a + b;
};

console.log(add(4, 6));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">10
</code></pre>
<p>The arrow symbol replaces the function keyword and makes the intent clearer. Once you get used to reading this syntax, it becomes very natural and easy to follow.</p>
<p>Now let us understand the syntax step by step.</p>
<h3>Basic arrow function syntax</h3>
<p>The general structure of an arrow function looks like this.</p>
<pre><code class="language-javascript">const functionName = (parameters) =&gt; {
  // code
};
</code></pre>
<p>Here is a simple example that greets a user.</p>
<pre><code class="language-javascript">const greet = (name) =&gt; {
  return "Hello " + name;
};

console.log(greet("Gaurang"));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">Hello Gaurang
</code></pre>
<p>We store the function inside a variable using const, then write the parameters inside parentheses, followed by the arrow symbol and the function body. The logic inside the curly brackets works just like a normal function.</p>
<p>This syntax becomes even simpler when the function has only one parameter.</p>
<h3>Arrow functions with one parameter</h3>
<p>If a function has only one parameter, JavaScript allows us to remove the parentheses around it. This makes the function even more compact.</p>
<p>Example</p>
<pre><code class="language-javascript">const square = number =&gt; {
  return number * number;
};

console.log(square(5));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">25
</code></pre>
<p>The function receives a number and returns its square. Removing the parentheses makes the code slightly shorter while still keeping it easy to read. Many developers prefer this style for very small helper functions.</p>
<h3>Arrow functions with multiple parameters</h3>
<p>If the function has more than one parameter, parentheses are required.</p>
<p>Example</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; {
  return a * b;
};

console.log(multiply(3, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">12
</code></pre>
<p>Here we are multiplying two numbers. The structure remains almost identical to a normal function, except the function keyword is replaced by the arrow syntax.</p>
<p>Now let us look at one of the most useful features of arrow functions.</p>
<h3>Implicit return vs explicit return</h3>
<p>In normal functions, we always write the return keyword to send a value back.</p>
<p>Example</p>
<pre><code class="language-javascript">function subtract(a, b) {
  return a - b;
}

console.log(subtract(9, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">5
</code></pre>
<p>Arrow functions introduce something called implicit return. If the function body contains only a single expression, JavaScript can automatically return that value without writing the return keyword.</p>
<p>Example</p>
<pre><code class="language-javascript">const subtract = (a, b) =&gt; a - b;

console.log(subtract(9, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">5
</code></pre>
<p>Notice that we removed the curly braces and the return keyword. The expression automatically becomes the returned value.</p>
<p>This is called implicit return.</p>
<p>If we keep curly braces, then we must write return. That is known as explicit return.</p>
<p>Example with explicit return</p>
<pre><code class="language-javascript">const divide = (a, b) =&gt; {
  return a / b;
};

console.log(divide(20, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">5
</code></pre>
<p>Example with implicit return</p>
<pre><code class="language-javascript">const divide = (a, b) =&gt; a / b;

console.log(divide(20, 4));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">5
</code></pre>
<p>Both approaches work perfectly fine. Developers usually choose based on readability and how complex the function body is.</p>
<h3>Difference between arrow function and normal function</h3>
<p>For a beginner, the most visible difference is the syntax.</p>
<p>Normal function</p>
<pre><code class="language-javascript">function sayHello(name) {
  return "Hello " + name;
}

console.log(sayHello("Riya"));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">Hello Riya
</code></pre>
<p>Arrow function</p>
<pre><code class="language-javascript">const sayHello = name =&gt; "Hello " + name;

console.log(sayHello("Riya"));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">Hello Riya
</code></pre>
<p>The arrow function version is shorter and is often preferred in modern JavaScript codebases. Both approaches behave the same for simple tasks like greetings or small math operations.</p>
<p>There are deeper differences involving how the keyword this behaves inside functions, but that topic is better explored later once you are comfortable with basic functions.</p>
<p>For now, the key takeaway is that arrow functions provide a cleaner and more modern way to write functions.</p>
<h3>Arrow functions with arrays</h3>
<p>Arrow functions are extremely useful when working with arrays. They make callback functions shorter and easier to read.</p>
<p>Let us look at a simple example using map.</p>
<pre><code class="language-javascript">const numbers = [2, 4, 6, 8];

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

console.log(doubled);
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">[4, 8, 12, 16]
</code></pre>
<p>The arrow function takes each number from the array and multiplies it by two. Because the function body is small, implicit return keeps the code clean and easy to understand.</p>
<p>This is one of the situations where arrow functions really shine.</p>
<h3>Assignment idea</h3>
<p>If you want to practice what you learned, try the following small exercises.</p>
<p>First, write a normal function that calculates the square of a number.</p>
<pre><code class="language-javascript">function findSquare(num) {
  return num * num;
}

console.log(findSquare(7));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">49
</code></pre>
<p>Now rewrite the same function using an arrow function.</p>
<pre><code class="language-javascript">const findSquare = num =&gt; num * num;

console.log(findSquare(7));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">49
</code></pre>
<p>Next, create an arrow function that checks whether a number is even or odd.</p>
<pre><code class="language-javascript">const checkEvenOdd = num =&gt; {
  if (num % 2 === 0) {
    return "Even";
  }
  return "Odd";
};

console.log(checkEvenOdd(10));
console.log(checkEvenOdd(7));
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">Even
Odd
</code></pre>
<p>Finally, use an arrow function inside map.</p>
<pre><code class="language-javascript">const values = [1, 2, 3, 4];

const squares = values.map(n =&gt; n * n);

console.log(squares);
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">[1, 4, 9, 16]
</code></pre>
<p>These small exercises help build confidence with arrow functions and show how naturally they fit into modern JavaScript code.</p>
<h3>Final thoughts</h3>
<p>Arrow functions are one of the most commonly used features in modern JavaScript. They help reduce unnecessary syntax and make functions easier to read, especially when writing short pieces of logic.</p>
<p>For beginners, the most important things to remember are the basic syntax, when parentheses are optional, and how implicit return works. Once you become comfortable with these ideas, you will start noticing arrow functions everywhere in real world JavaScript projects.</p>
<p>Learning them early helps you write code that looks clean, modern, and easier for other developers to understand.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[When someone starts learning programming, one of the first concepts they encounter is variables. At first the word might sound technical, but the idea behind it is actually very simple. Variables help]]></description><link>https://blogs.gaurangpods.com/understanding-variables-and-data-types-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/understanding-variables-and-data-types-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[variables]]></category><category><![CDATA[datatypes]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 16:38:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/39d08ec0-ac39-4022-88c6-8d6e3f37f423.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When someone starts learning programming, one of the first concepts they encounter is variables. At first the word might sound technical, but the idea behind it is actually very simple. Variables help us store information so that our program can use it later.</p>
<p>Think of a variable as a box that stores some data. The box has a label on it, and inside the box we place a value. Whenever the program needs that value, it simply looks at the box using its label.</p>
<p>For example, imagine writing down someone's name, age, and whether they are a student. Instead of repeatedly typing the values everywhere in the program, we store them inside variables and reuse them whenever needed.</p>
<p>This makes programs easier to manage and understand.</p>
<h3>Why Variables Are Needed</h3>
<p>Programs constantly work with information. A website might store a user's name, a game might track the player's score, and a shopping application might calculate the total price of items.</p>
<p>Without variables, we would have to repeat the same values again and again throughout the program. That would quickly make the code messy and difficult to maintain.</p>
<p>Variables solve this problem by allowing us to store information once and reuse it multiple times.</p>
<p>For example, if we store a person's name in a variable, we can use that name anywhere in our program. If the value changes, we only need to update it in one place.</p>
<h3>Declaring Variables in JavaScript</h3>
<p>In JavaScript there are three common ways to declare variables. These are var, let, and const.</p>
<p>Let us look at a simple example of declaring variables.</p>
<pre><code class="language-javascript">var city = "Indore"
let age = 21
const country = "India"

console.log(city)
console.log(age)
console.log(country)
</code></pre>
<p>Output</p>
<p>Indore  </p>
<p>21  </p>
<p>India</p>
<p>In this example we created three variables and stored values in them. Each variable has a name and a value.</p>
<p>The console.log statements print the stored values to the console.</p>
<p>Although all three keywords can declare variables, they behave slightly differently. We will understand those differences shortly.</p>
<h3>Understanding Primitive Data Types</h3>
<p>Whenever we store information in a variable, that value belongs to a certain type. These are called data types.</p>
<p>JavaScript has several data types, but beginners usually start with a few basic ones.</p>
<p>One common type is a string. Strings represent text values.</p>
<p>Example</p>
<pre><code class="language-javascript">let name = "Rohit"

console.log(name)
</code></pre>
<p>Output</p>
<p>Rohit</p>
<p>Here the variable name stores a piece of text, so its type is string.</p>
<p>Another common type is number. Numbers represent numeric values.</p>
<pre><code class="language-javascript">let age = 20

console.log(age)
</code></pre>
<p>Output</p>
<p>20</p>
<p>In this example the variable age stores a numeric value.</p>
<p>Another simple type is boolean. A boolean represents either true or false.</p>
<pre><code class="language-javascript">let isStudent = true

console.log(isStudent)
</code></pre>
<p>Output</p>
<p>true</p>
<p>Boolean values are often used when checking conditions such as whether a user is logged in or whether a task is completed.</p>
<p>JavaScript also has two special data types called null and undefined.</p>
<p>Null represents an intentional empty value.</p>
<pre><code class="language-javascript">let middleName = null

console.log(middleName)
</code></pre>
<p>Output</p>
<p>null</p>
<p>Undefined represents a variable that has been declared but not assigned any value.</p>
<pre><code class="language-javascript">let score

console.log(score)
</code></pre>
<p>Output</p>
<p>undefined</p>
<p>Understanding these basic data types helps in choosing the right type of value for each variable.</p>
<h3>Basic Difference Between var, let, and const</h3>
<p>All three keywords var, let, and const are used to create variables, but there are a few important differences between them.</p>
<p>The var keyword is the older way of declaring variables in JavaScript. It is still supported but modern JavaScript usually prefers let and const.</p>
<p>The let keyword allows us to declare a variable whose value can change later.</p>
<p>Example</p>
<pre><code class="language-javascript">let score = 10
console.log(score)

score = 15
console.log(score)
</code></pre>
<p>Output</p>
<p>10  </p>
<p>15</p>
<p>Here the value of score was updated successfully.</p>
<p>The const keyword is used when the value should not change after being assigned.</p>
<p>Example</p>
<pre><code class="language-javascript">const birthYear = 2004

console.log(birthYear)
</code></pre>
<p>Output</p>
<p>2004</p>
<p>If we try to change the value of a const variable, JavaScript throws an error.</p>
<pre><code class="language-javascript">const birthYear = 2004

birthYear = 2005
</code></pre>
<p>Output</p>
<p>Error because a const value cannot be reassigned</p>
<p>Because of this behavior, const is often used when we want to ensure that a value remains constant throughout the program.</p>
<h3>Understanding Scope in a Simple Way</h3>
<p>Scope refers to where a variable can be accessed in a program.</p>
<p>You can think of scope as the area where a variable is visible and usable.</p>
<p>Consider the following example.</p>
<pre><code class="language-javascript">let message = "Hello JavaScript"

console.log(message)
</code></pre>
<p>Output</p>
<p>Hello JavaScript</p>
<p>Here the variable message is available in the entire script.</p>
<p>Now look at this example using a block of code.</p>
<pre><code class="language-javascript">if (true) {
    let greeting = "Welcome"
    console.log(greeting)
}

console.log(greeting)
</code></pre>
<p>Output</p>
<p>Welcome  </p>
<p>Error because greeting cannot be accessed outside the block</p>
<p>The variable greeting only exists inside the block where it was created. Outside that block it is not available.</p>
<p>This idea helps prevent variables from interfering with each other in larger programs.</p>
<h3>A Small Practice Exercise</h3>
<p>The best way to understand variables is to try creating them yourself.</p>
<p>Let us create three variables that represent a person's details.</p>
<pre><code class="language-javascript">let name = "Aarav"
let age = 19
let isStudent = true

console.log("Name:", name)
console.log("Age:", age)
console.log("Is Student:", isStudent)
</code></pre>
<p>Output</p>
<p>Name: Aarav  </p>
<p>Age: 19  </p>
<p>Is Student: true</p>
<p>Now try changing the value of the age variable.</p>
<pre><code class="language-javascript">age = 20

console.log("Updated Age:", age)
</code></pre>
<p>Output</p>
<p>Updated Age: 20</p>
<p>The value changes successfully because the variable was declared using let.</p>
<p>Now try the same with const.</p>
<pre><code class="language-javascript">const country = "India"

country = "USA"
</code></pre>
<p>Output</p>
<p>Error because const values cannot be reassigned</p>
<p>This small experiment helps demonstrate how variables behave differently depending on how they are declared.</p>
<p>Variables are one of the most fundamental parts of programming. They allow us to store, update, and reuse information throughout a program. Once you become comfortable using variables and understanding basic data types, many other JavaScript concepts start becoming easier to learn.</p>
<p>Understanding how variables work is an important step toward writing organized and readable programs.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Objects in JavaScript]]></title><description><![CDATA[When we begin writing programs, we usually work with simple values like numbers, strings, or arrays. These work well for many tasks, but as programs start representing real world information, we often]]></description><link>https://blogs.gaurangpods.com/objects-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/objects-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Object Oriented Programming]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 07:05:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/1fb4255e-8679-4c3c-8dee-fc21316d2b35.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we begin writing programs, we usually work with simple values like numbers, strings, or arrays. These work well for many tasks, but as programs start representing real world information, we often need a better way to organize related data together.</p>
<p>This is where objects become extremely useful.</p>
<p>An object in JavaScript is a structure that stores information using <strong>key value pairs</strong>. Each piece of data is stored with a label called a key, and the value attached to that key describes something about the object.</p>
<p>You can think of an object like a small container that holds related information together.</p>
<p>For example, imagine we want to represent a person in our program. A person may have a name, age, and city. Instead of storing these values separately, we can group them inside a single object.</p>
<p>This makes the program easier to understand and manage.</p>
<h3>Why Objects Are Needed</h3>
<p>Programs often deal with entities that have multiple related properties. A student has a name, age, and course. A car has a brand, model, and year. A user account has a username, email, and password.</p>
<p>Objects help us store this type of structured information.</p>
<p>Instead of creating many unrelated variables, we can place all related values inside one object. This improves readability and keeps data organized.</p>
<p>Another benefit of objects is flexibility. We can easily update properties, add new ones, or remove them when needed.</p>
<h3>Objects vs Arrays</h3>
<p>Before creating objects, it helps to see how they differ from arrays.</p>
<p>An array stores values in a list where each item is accessed using an index number.</p>
<p>Example array</p>
<pre><code class="language-javascript">let colors = ["red", "blue", "green"]

console.log(colors[0])
</code></pre>
<p>Output</p>
<p>red</p>
<p>Here the value is accessed using the position inside the array.</p>
<p>Objects work differently. Instead of index positions, objects use keys.</p>
<p>Example object</p>
<pre><code class="language-javascript">let person = {
    name: "Ravi",
    age: 24,
    city: "Indore"
}

console.log(person.name)
</code></pre>
<p>Output</p>
<p>Ravi</p>
<p>In an object, each piece of data is accessed using the key rather than a numeric position.</p>
<p>This makes objects very suitable for representing real world entities.</p>
<h3>Creating Objects in JavaScript</h3>
<p>Creating an object in JavaScript is quite simple. We define an object using curly braces and place key value pairs inside it.</p>
<p>Here is an example.</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

console.log(person)
</code></pre>
<p>Output</p>
<p>{ name: 'Ananya', age: 22, city: 'Bhopal' }</p>
<p>In this example we created an object called person. It has three properties.</p>
<p>name stores the person's name  </p>
<p>age stores the person's age  </p>
<p>city stores the city where the person lives</p>
<p>Each property follows the pattern key followed by a value.</p>
<h3>Accessing Object Properties</h3>
<p>Once an object is created, we often need to access its properties. JavaScript provides two common ways to do this.</p>
<p>The first way is called <strong>dot notation</strong>.</p>
<p>Example</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

console.log(person.name)
console.log(person.age)
</code></pre>
<p>Output</p>
<p>Ananya  </p>
<p>22</p>
<p>Dot notation is simple and widely used when we know the property name beforehand.</p>
<p>The second way is called <strong>bracket notation</strong>.</p>
<p>Example</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

console.log(person["city"])
</code></pre>
<p>Output</p>
<p>Bhopal</p>
<p>Bracket notation is useful when the property name is dynamic or stored in a variable.</p>
<p>Example</p>
<pre><code class="language-javascript">let property = "name"

console.log(person[property])
</code></pre>
<p>Output</p>
<p>Ananya</p>
<p>Both approaches achieve the same result but are useful in different situations.</p>
<h3>Updating Object Properties</h3>
<p>Sometimes we need to modify the values stored in an object.</p>
<p>Updating a property is very straightforward. We simply assign a new value to the property.</p>
<p>Example</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

person.age = 23

console.log(person.age)
</code></pre>
<p>Output</p>
<p>23</p>
<p>Here we updated the age property from 22 to 23.</p>
<p>This ability to modify properties makes objects flexible and adaptable for changing data.</p>
<h3>Adding and Deleting Properties</h3>
<p>Objects in JavaScript are dynamic, which means new properties can be added at any time.</p>
<p>Example of adding a new property.</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22
}

person.city = "Bhopal"

console.log(person)
</code></pre>
<p>Output</p>
<p>{ name: 'Ananya', age: 22, city: 'Bhopal' }</p>
<p>We simply assign a new key and value to the object.</p>
<p>Deleting properties is also possible using the delete keyword.</p>
<p>Example</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

delete person.city

console.log(person)
</code></pre>
<p>Output</p>
<p>{ name: 'Ananya', age: 22 }</p>
<p>The city property was removed from the object.</p>
<p>This flexibility allows objects to evolve as program requirements change.</p>
<h3>Looping Through Object Keys</h3>
<p>Sometimes we want to see every property stored in an object. JavaScript allows us to loop through object keys using a loop.</p>
<p>A commonly used approach is the for in loop.</p>
<p>Example</p>
<pre><code class="language-javascript">let person = {
    name: "Ananya",
    age: 22,
    city: "Bhopal"
}

for (let key in person) {
    console.log(key + " : " + person[key])
}
</code></pre>
<p>Output</p>
<p>name : Ananya  </p>
<p>age : 22  </p>
<p>city : Bhopal</p>
<p>The loop runs through every key in the object. Using the key we can access its corresponding value.</p>
<p>This is very helpful when working with objects that contain many properties.</p>
<h3>A Small Practice Exercise</h3>
<p>To become comfortable with objects, try creating one yourself.</p>
<p>Create an object representing a student and include properties such as name, age, and course.</p>
<p>Example solution</p>
<pre><code class="language-javascript">let student = {
    name: "Arjun",
    age: 20,
    course: "Computer Science"
}

student.age = 21

for (let key in student) {
    console.log(key + " : " + student[key])
}
</code></pre>
<p>Output</p>
<p>name : Arjun  </p>
<p>age : 21  </p>
<p>course : Computer Science</p>
<p>First the object was created with three properties. Then the age property was updated. Finally we used a loop to print all keys and values.</p>
<p>Exercises like this help in understanding how objects store and organize information.</p>
<p>Objects are one of the most important structures in JavaScript. They allow programs to represent real world entities in a clean and organized way. As you continue learning JavaScript, you will see objects used everywhere from simple applications to complex systems.</p>
<p>Once you become comfortable with creating and manipulating objects, writing structured and readable programs becomes much easier.</p>
<p>I hope this blog gave you the necessary insights into the objects in JavaScript.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Object Oriented Programming in JavaScript]]></title><description><![CDATA[When people start learning programming, most code they write is a sequence of instructions. The program runs line by line and performs tasks step by step. This approach works well for small programs, ]]></description><link>https://blogs.gaurangpods.com/understanding-object-oriented-programming-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/understanding-object-oriented-programming-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Object Oriented Programming]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 06:34:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/6fe71a47-da45-4583-81c6-28e3ea2c961b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When people start learning programming, most code they write is a sequence of instructions. The program runs line by line and performs tasks step by step. This approach works well for small programs, but as applications grow larger it becomes harder to manage everything in a simple sequence.</p>
<p>That is where Object Oriented Programming becomes useful. It helps organize code into meaningful structures so that large programs become easier to build and maintain.</p>
<p>Object Oriented Programming, often called OOP, is a way of writing programs using objects that represent real world things. Instead of thinking only about functions and variables, we think about entities such as a student, a car, or a user.</p>
<p>Each object contains data and behavior related to that entity. The data describes the object and the behavior defines what the object can do.</p>
<p>Before diving into code, it helps to think about a real world example.</p>
<h3>A Simple Real World Analogy</h3>
<p>Imagine a company that manufactures cars.</p>
<p>Before any car is produced, engineers first design a blueprint. The blueprint defines what a car should look like and what properties it should have. For example the blueprint might describe things like the brand, color, and engine type.</p>
<p>Using that blueprint, the company can create many cars. Each car follows the same design but has its own specific values.</p>
<p>One car might be red while another is blue. One might have a different engine model. Even though they are different cars, they are all created from the same blueprint.</p>
<p>Object Oriented Programming follows a very similar idea.</p>
<p>The blueprint is called a class. The actual cars created from that blueprint are called objects.</p>
<p>Once we define a class, we can create multiple objects from it. This makes our code reusable and organized.</p>
<h3>What is a Class in JavaScript</h3>
<p>In JavaScript, a class is a template used to create objects. It defines the properties and methods that objects created from it will have.</p>
<p>Let us look at a small example of a class.</p>
<pre><code class="language-javascript">class Person {

    constructor(name, age) {
        this.name = name
        this.age = age
    }

    introduce() {
        console.log("Hi, my name is " + this.name + " and I am " + this.age + " years old.")
    }

}
</code></pre>
<p>In this example we created a class called Person.</p>
<p>Inside the class we defined a constructor and a method called introduce.</p>
<p>The constructor is responsible for assigning initial values when an object is created.</p>
<p>The introduce method describes behavior that the object can perform.</p>
<p>Now that the blueprint exists, we can create objects from it.</p>
<h3>Creating Objects Using Classes</h3>
<p>Creating an object from a class is called instantiation.</p>
<p>To create an object we use the new keyword followed by the class name.</p>
<p>Here is how we can create two person objects.</p>
<pre><code class="language-javascript">let person1 = new Person("Rahul", 22)
let person2 = new Person("Meera", 25)

person1.introduce()
person2.introduce()
</code></pre>
<p>Output</p>
<p>Hi, my name is Rahul and I am 22 years old.  </p>
<p>Hi, my name is Meera and I am 25 years old.</p>
<p>Both objects were created using the same class. The structure is identical but the values are different.</p>
<p>This is exactly like creating multiple cars using the same blueprint.</p>
<h3>Understanding the Constructor Method</h3>
<p>The constructor method plays a very important role in classes.</p>
<p>It runs automatically whenever a new object is created.</p>
<p>Its purpose is to initialize properties of the object.</p>
<p>Look again at the constructor inside the Person class.</p>
<pre><code class="language-javascript">constructor(name, age) {
    this.name = name
    this.age = age
}
</code></pre>
<p>When we create a new object like this</p>
<p>Person("Rahul", 22)</p>
<p>the constructor receives the values Rahul and 22 and assigns them to the object.</p>
<p>The keyword this refers to the current object being created.</p>
<p>So <a href="http://this.name">this.name</a> stores the name value inside that object.</p>
<h3>Methods Inside a Class</h3>
<p>Methods are functions that belong to a class.</p>
<p>They define what an object can do.</p>
<p>In the Person class we added a method called introduce. This method prints information about the person.</p>
<p>Let us look at another example using a Car class.</p>
<pre><code class="language-javascript">class Car {

    constructor(brand, model) {
        this.brand = brand
        this.model = model
    }

    showDetails() {
        console.log("Car brand is " + this.brand + " and model is " + this.model)
    }

}

let car1 = new Car("Toyota", "Corolla")
car1.showDetails()
</code></pre>
<p>Output</p>
<p>Car brand is Toyota and model is Corolla</p>
<p>Here the showDetails method describes behavior associated with the car object.</p>
<p>This is one of the strengths of Object Oriented Programming. Data and behavior related to an entity stay together.</p>
<h3>Basic Idea of Encapsulation</h3>
<p>Another important concept in OOP is encapsulation.</p>
<p>Encapsulation simply means keeping related data and functions together in one place.</p>
<p>In our earlier examples the class contains properties and methods that belong to the same concept.</p>
<p>The Person class stores name and age and also contains behavior related to a person.</p>
<p>The Car class stores brand and model and contains behavior related to a car.</p>
<p>Instead of scattering logic throughout the program, we group everything inside classes.</p>
<p>This makes programs easier to read and maintain.</p>
<p>Encapsulation also helps protect data by controlling how it is accessed, although deeper concepts of data protection are usually learned later.</p>
<p>For beginners it is enough to understand that classes help keep related code organized.</p>
<h3>Why OOP Helps in Real Projects</h3>
<p>Object Oriented Programming provides several advantages when building larger programs.</p>
<p>First, it promotes code reuse. Once a class is written, we can create many objects without rewriting the same logic again.</p>
<p>Second, it makes code easier to understand because each class represents a clear concept.</p>
<p>Third, it helps maintain large applications since related behavior stays grouped together.</p>
<p>For example, if a project manages hundreds of students, having a Student class keeps all student related information and behavior in one place.</p>
<p>Without OOP, managing such systems becomes messy very quickly.</p>
<h3>A Small Practice Exercise</h3>
<p>To really understand OOP, it helps to create a class yourself.</p>
<p>Try creating a class called Student that stores the name and age of a student.</p>
<p>Then add a method that prints the student details.</p>
<p>Example solution</p>
<pre><code class="language-javascript">class Student {

    constructor(name, age) {
        this.name = name
        this.age = age
    }

    showDetails() {
        console.log("Student name: " + this.name + ", Age: " + this.age)
    }

}

let student1 = new Student("Arjun", 20)
let student2 = new Student("Sneha", 21)

student1.showDetails()
student2.showDetails()
</code></pre>
<p>Output</p>
<p>Student name: Arjun, Age: 20  </p>
<p>Student name: Sneha, Age: 21</p>
<p>Both students were created using the same class. The structure is shared while the values are different.</p>
<p>This small example demonstrates how classes help create structured and reusable code.</p>
<p>Once you become comfortable with classes and objects, Object Oriented Programming starts to feel very natural. Many real world applications rely on these ideas to manage complex systems in an organized way.</p>
<p>Understanding this concept early will make it easier to explore more advanced JavaScript patterns in the future.  </p>
<p>I hope this blog gave you the necessary insight needed.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding this, call(), apply(), and bind() in JavaScript]]></title><description><![CDATA[When people first come across the keyword this in JavaScript, it often feels confusing. The word itself sounds simple, but the behavior changes depending on how a function is called.
A very practical ]]></description><link>https://blogs.gaurangpods.com/understanding-this-call-apply-and-bind-in-javascript</link><guid isPermaLink="true">https://blogs.gaurangpods.com/understanding-this-call-apply-and-bind-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[js]]></category><category><![CDATA[this keyword]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 05:24:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/c2876565-d8e5-494b-ac38-891926ce3554.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When people first come across the keyword <strong>this</strong> in JavaScript, it often feels confusing. The word itself sounds simple, but the behavior changes depending on how a function is called.</p>
<p>A very practical way to think about it is this.</p>
<p><strong>this refers to the object that is calling the function.</strong></p>
<p>Whenever a function runs, JavaScript checks who called that function. The caller becomes the value of this.</p>
<p>Once you keep this idea in mind, most situations become much easier to understand.</p>
<p>Let us walk through a few common cases.</p>
<h3>What this Means in JavaScript</h3>
<p>In JavaScript, <strong>this is a keyword that points to the object executing the current function</strong>.</p>
<p>It is not fixed. The value of this depends on how the function is invoked.</p>
<p>Consider this small example.</p>
<pre><code class="language-javascript">function showContext() {
    console.log(this)
}

showContext()
</code></pre>
<p>If you run this in the browser console, JavaScript prints the global object. In browsers this is usually the <code>window</code> object.</p>
<p>This happens because the function was called directly and not through any object.</p>
<p>So JavaScript falls back to the global context.</p>
<h3>this Inside Normal Functions</h3>
<p>When a function runs without being attached to an object, this refers to the global object in non strict mode.</p>
<p>Here is a simple illustration.</p>
<pre><code class="language-javascript">function printName() {
    console.log(this.name)
}

let name = "Gaurang"

printName()
</code></pre>
<p>The function prints Gaurang because JavaScript looks at the global scope where the variable name exists.</p>
<p>This behavior is one reason beginners get confused. The function itself does not contain the name variable, but the global scope does.</p>
<h3>this Inside Objects</h3>
<p>Things become clearer when functions are defined inside objects.</p>
<pre><code class="language-javascript">let user = {
    name: "Rohit",
    greet: function () {
        console.log("Hello, my name is " + this.name)
    }
}

user.greet()
</code></pre>
<p>Here the function greet is called by the object user.</p>
<p>Since user called the function, this refers to user.</p>
<p>That means <a href="http://this.name">this.name</a> becomes Rohit.</p>
<p>You can think about it in a very simple way.</p>
<p>If an object calls the function, this points to that object.</p>
<h3>What call() Does</h3>
<p>JavaScript also allows us to manually decide what this should be. One way to do this is with the <strong>call()</strong> method.</p>
<p>The call method executes a function immediately and lets us specify what this should refer to.</p>
<p>Look at this example.</p>
<pre><code class="language-javascript">function introduce() {
    console.log("Hi, I am " + this.name)
}

let person1 = { name: "Aman" }
let person2 = { name: "Neha" }

introduce.call(person1)
introduce.call(person2)
</code></pre>
<p>In the first line, the function runs with person1 as this.</p>
<p>In the second line, the function runs with person2 as this.</p>
<p>Even though the function is the same, the result changes depending on the object we pass.</p>
<p>This technique is often called <strong>method borrowing</strong>.</p>
<h3>What apply() Does</h3>
<p>The <strong>apply()</strong> method is very similar to call.</p>
<p>The only real difference is how arguments are passed.</p>
<p>With call, arguments are passed separately.</p>
<p>With apply, arguments are passed inside an array.</p>
<p>Example.</p>
<pre><code class="language-javascript">function addNumbers(a, b) {
    console.log(a + b)
}

addNumbers.call(null, 4, 6)

addNumbers.apply(null, [4, 6])
</code></pre>
<p>Both statements give the same result.</p>
<p>The difference lies only in the format of the arguments.</p>
<p>call uses individual values.  </p>
<p>apply uses an array.</p>
<h3>What bind() Does</h3>
<p>The <strong>bind()</strong> method behaves slightly differently from call and apply.</p>
<p>Instead of running the function immediately, bind returns a new function.</p>
<p>That new function always uses the this value we provided.</p>
<p>Example.</p>
<pre><code class="language-javascript">function greet() {
    console.log("Hello " + this.name)
}

let person = { name: "Karan" }

let greetPerson = greet.bind(person)

greetPerson()
</code></pre>
<p>The function greetPerson now permanently uses person as this.</p>
<p>This is useful when you want to store a function and run it later while keeping the correct context.</p>
<h3>Difference Between call, apply, and bind</h3>
<p>All three methods control the value of this, but they behave differently.</p>
<p>call executes the function immediately and accepts arguments one by one.</p>
<p>apply also executes the function immediately but expects arguments inside an array.</p>
<p>bind does not run the function immediately. It returns a new function with this fixed.</p>
<p>A quick way to remember this is:</p>
<p>call runs the function now  </p>
<p>apply runs the function now with array arguments  </p>
<p>bind creates a function to run later</p>
<h3>Small Practice Exercise</h3>
<p>Trying these ideas yourself makes the concept clearer.</p>
<p>First create an object with a method that uses this.</p>
<pre><code class="language-javascript">let car = {
    brand: "Toyota",
    showBrand: function () {
        console.log("Car brand is " + this.brand)
    }
}

car.showBrand()
</code></pre>
<p>Now borrow the method using call.</p>
<pre><code class="language-javascript">let anotherCar = {
    brand: "Honda"
}

car.showBrand.call(anotherCar)
</code></pre>
<p>Even though the method belongs to car, it now runs using anotherCar.</p>
<p>Next try apply with array arguments.</p>
<pre><code class="language-javascript">function multiply(a, b) {
    console.log(a * b)
}

multiply.apply(null, [3, 5])
</code></pre>
<p>Finally try bind and store the function.</p>
<pre><code class="language-javascript">function sayHello() {
    console.log("Hello " + this.name)
}

let student = { name: "Arjun" }

let helloStudent = sayHello.bind(student)

helloStudent()
</code></pre>
<p>Once you experiment with these patterns a few times, the behavior of this starts making sense.</p>
<p>The most important thing to remember is simple.</p>
<p><strong>this points to the object that calls the function.</strong></p>
<p>call, apply, and bind are simply tools that help you control that behavior when you need it.</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Operators: The Basics You Need to Know]]></title><description><![CDATA[When you start learning JavaScript, operators are one of those things you begin using almost immediately. Sometimes you don’t even notice it at first. Every time you add numbers, compare values, or ch]]></description><link>https://blogs.gaurangpods.com/javascript-operators-the-basics-you-need-to-know</link><guid isPermaLink="true">https://blogs.gaurangpods.com/javascript-operators-the-basics-you-need-to-know</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Operators]]></category><category><![CDATA[basics]]></category><category><![CDATA[basics of javascript]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 05:23:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/8b4c2c31-5414-4b3b-87ad-8abb879f6a6e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When you start learning JavaScript, operators are one of those things you begin using almost immediately. Sometimes you don’t even notice it at first. Every time you add numbers, compare values, or check a condition inside an if statement, you’re using operators.</p>
<p>Simply put, operators are symbols that perform operations on values. The values being used are called operands. For example, if you write 5 + 3, the plus symbol is the operator and the numbers are the operands.</p>
<p>These operators appear everywhere in JavaScript programs. Whether you are doing simple calculations or controlling the flow of your code, they quietly power a lot of the logic behind the scenes.</p>
<p>Let’s go through the most commonly used ones.</p>
<p>Arithmetic Operators</p>
<p>Arithmetic operators are used for mathematical calculations. If you’ve done basic math in school, these will feel very familiar.</p>
<p>JavaScript supports addition, subtraction, multiplication, division, and modulus. These operators help you perform everyday calculations inside your program.</p>
<p>Here’s a simple example.</p>
<pre><code class="language-javascript">let apples = 12
let friends = 4

let total = apples + friends
let difference = apples - friends
let product = apples * friends
let division = apples / friends
let remainder = apples % friends

console.log("Total:", total)
console.log("Difference:", difference)
console.log("Product:", product)
console.log("Division:", division)
console.log("Remainder:", remainder)
</code></pre>
<p>When you run this code, JavaScript performs each calculation and prints the result in the console.</p>
<p>The modulus operator is a bit different from the others. Instead of giving the division result, it returns the remainder.</p>
<p>This operator is often used when checking whether a number is even or odd.</p>
<pre><code class="language-javascript">let number = 15

console.log(number % 2)
</code></pre>
<p>If the output is 0, the number is even. If the output is 1, the number is odd.</p>
<p>Arithmetic operators are commonly used in counters, loops, calculations, and many other everyday programming situations.</p>
<p>Comparison Operators</p>
<p>Comparison operators help us compare two values. Instead of returning a number, they return a boolean value, which means the result will be either true or false.</p>
<p>These are very useful when writing conditions in programs.</p>
<pre><code class="language-javascript">let score = 75
let passingMarks = 50

console.log(score &gt; passingMarks)
console.log(score &lt; passingMarks)
</code></pre>
<p>The first comparison returns true because 75 is greater than 50. The second comparison returns false.</p>
<p>Now let’s look at something that confuses many beginners: the difference between double equals and triple equals.</p>
<p>The double equals operator checks if two values are equal after JavaScript converts their types if needed.</p>
<pre><code class="language-javascript">console.log(10 == "10")
</code></pre>
<p>This prints true because JavaScript converts the string "10" into the number 10 before comparing.</p>
<p>The triple equals operator is stricter. It checks both the value and the data type.</p>
<pre><code class="language-javascript">console.log(10 === "10")
</code></pre>
<p>This returns false because one value is a number and the other is a string.</p>
<p>In modern JavaScript, developers usually prefer the triple equals operator because it avoids unexpected type conversions.</p>
<p>Logical Operators</p>
<p>Logical operators allow us to combine multiple conditions together. They are commonly used in decision making inside if statements.</p>
<p>JavaScript mainly uses three logical operators: AND, OR, and NOT.</p>
<p>The AND operator checks whether both conditions are true.</p>
<pre><code class="language-javascript">let age = 20
let hasID = true

console.log(age &gt;= 18 &amp;&amp; hasID)
</code></pre>
<p>This will only return true if the person is at least 18 years old and has an ID.</p>
<p>The OR operator checks if at least one condition is true.</p>
<pre><code class="language-javascript">let hasCoupon = false
let isPremiumMember = true

console.log(hasCoupon || isPremiumMember)
</code></pre>
<p>Even though the person does not have a coupon, the result will still be true because they are a premium member.</p>
<p>The NOT operator simply flips a boolean value.</p>
<pre><code class="language-javascript">let loggedIn = false

console.log(!loggedIn)
</code></pre>
<p>Since loggedIn is false, the result becomes true.</p>
<p>Logical operators are extremely useful when writing conditions that depend on multiple factors.</p>
<p>Assignment Operators</p>
<p>Assignment operators are used to assign values to variables.</p>
<p>The most common one is the equals operator, which simply stores a value in a variable.</p>
<pre><code class="language-javascript">let balance = 500
</code></pre>
<p>JavaScript also provides shorthand assignment operators that combine arithmetic with assignment.</p>
<pre><code class="language-javascript">let points = 10

points += 5
console.log(points)

points -= 3
console.log(points)
</code></pre>
<p>The statement points plus equals 5 is just a shorter way of writing points equals points plus 5.</p>
<p>Similarly, points minus equals 3 is equivalent to writing points equals points minus 3.</p>
<p>These shorthand operators make the code shorter and easier to read.</p>
<p>A Small Practice Idea</p>
<p>A quick way to get comfortable with operators is to try a few small experiments in the console.</p>
<p>I am sharing you few tasks that you should be doing if you are not well versed with operators, these are very simple ones. I am not attaching their answers.<br />Kindly practice them if you are a beginner either in your IDE or on browser.</p>
<p>First, perform some arithmetic operations with two numbers.</p>
<pre><code class="language-javascript">let a = 8
let b = 3

console.log("Addition:", a + b)
console.log("Multiplication:", a * b)
console.log("Remainder:", a % b)
</code></pre>
<p>Next, compare two values using both equality operators.</p>
<pre><code class="language-javascript">let value1 = 5
let value2 = "5"

console.log(value1 == value2)
console.log(value1 === value2)
</code></pre>
<p>Finally, try writing a small condition using logical operators.</p>
<pre><code class="language-javascript">let temperature = 32
let isSunny = true

if (temperature &gt; 30 &amp;&amp; isSunny) {
    console.log("Good day for ice cream")
}
</code></pre>
<p>Operators may look like tiny symbols, but they play a huge role in programming. Almost every piece of JavaScript logic depends on them in some way. Once you get comfortable using them, writing conditions, calculations, and decision-making code becomes much more natural.</p>
<p>Hope it was helpful, sometimes writing blog for such direct concepts becomes a bit tricky if you don't cover everything from scratch considering that this is very basic and everyone must be aware of these, Hence I deliberately tried to cover everything from scratch.</p>
]]></content:encoded></item><item><title><![CDATA[Function Declaration vs Function Expression: What’s the Difference?]]></title><description><![CDATA[When people begin learning JavaScript, one concept shows up very early and becomes extremely useful almost immediately. That concept is functions.
If you think about it, most programs repeat certain a]]></description><link>https://blogs.gaurangpods.com/function-declaration-vs-function-expression-what-s-the-difference</link><guid isPermaLink="true">https://blogs.gaurangpods.com/function-declaration-vs-function-expression-what-s-the-difference</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sun, 15 Mar 2026 05:23:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/5d6cccd4-c7cc-4b00-b3c7-87b588a59991.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When people begin learning JavaScript, one concept shows up very early and becomes extremely useful almost immediately. That concept is <strong>functions</strong>.</p>
<p>If you think about it, most programs repeat certain actions again and again. Instead of writing the same code multiple times, JavaScript allows us to group that logic into a reusable block. That reusable block is called a function.</p>
<p>A function is simply a piece of code that performs a specific task. Once written, you can run it whenever needed. This makes programs easier to read, maintain, and reuse.</p>
<p>Imagine you frequently need to add two numbers in your program. Instead of writing the addition logic in many places, you can create a function once and call it whenever required.</p>
<p>Let us first see what a basic function looks like.</p>
<h3>What Functions Are and Why We Need Them</h3>
<p>A function allows us to wrap logic into a reusable block of code. When we want to run that logic, we simply call the function.</p>
<p>Here is a very small example that adds two numbers.</p>
<pre><code class="language-javascript">function addNumbers(a, b) {
    let result = a + b
    console.log("Sum is:", result)
}

addNumbers(5, 3)
</code></pre>
<p>Output</p>
<p>Sum is: 8</p>
<p>In this example, we created a function called addNumbers. The function accepts two values and prints their sum.</p>
<p>Functions help in three important ways. They reduce repetition, organize code better, and make programs easier to understand.</p>
<p>Now that we know what functions are, let us look at two different ways JavaScript allows us to create them.</p>
<h3>Function Declaration</h3>
<p>The first way to create a function is called a <strong>function declaration</strong>.</p>
<p>This is the most common style beginners learn.</p>
<p>Here is the syntax.</p>
<pre><code class="language-javascript">function greetUser(name) {
    console.log("Hello " + name)
}

greetUser("Aman")
</code></pre>
<p>Output</p>
<p>Hello Aman</p>
<p>In this example, the function greetUser is declared using the keyword function followed by the function name.</p>
<p>After defining the function, we call it using greetUser("Aman").</p>
<p>Function declarations are straightforward and easy to read. This is why they are commonly used when writing regular program logic.</p>
<p>Let us look at another small example.</p>
<pre><code class="language-javascript">function calculateArea(length, width) {
    let area = length * width
    console.log("Area is:", area)
}

calculateArea(4, 6)
</code></pre>
<p>Output</p>
<p>Area is: 24</p>
<p>The function takes two values, multiplies them, and prints the result.</p>
<h3>Function Expression</h3>
<p>The second way to create a function is called a <strong>function expression</strong>.</p>
<p>Instead of declaring the function directly, we store the function inside a variable.</p>
<p>Here is an example.</p>
<pre><code class="language-javascript">let greetUser = function(name) {
    console.log("Hello " + name)
}

greetUser("Neha")
</code></pre>
<p>Output</p>
<p>Hello Neha</p>
<p>In this case, the function is assigned to a variable called greetUser.</p>
<p>So instead of declaring the function directly, we create the function and store it inside a variable.</p>
<p>Here is another example with numbers.</p>
<pre><code class="language-javascript">let subtractNumbers = function(a, b) {
    let result = a - b
    console.log("Difference is:", result)
}

subtractNumbers(9, 4)
</code></pre>
<p>Output</p>
<p>Difference is: 5</p>
<p>Function expressions work almost the same way as function declarations when we call them. The main difference lies in how they are created and when they become available.</p>
<h3>Declaration vs Expression Side by Side</h3>
<p>To see the difference more clearly, look at these two examples.</p>
<p>Function declaration</p>
<pre><code class="language-javascript">function multiply(a, b) {
    let result = a * b
    console.log("Multiplication result:", result)
}

multiply(3, 5)
</code></pre>
<p>Output</p>
<p>Multiplication result: 15</p>
<p>Function expression</p>
<pre><code class="language-javascript">let multiply = function(a, b) {
    let result = a * b
    console.log("Multiplication result:", result)
}

multiply(3, 5)
</code></pre>
<p>Output</p>
<p>Multiplication result: 15</p>
<p>At first glance, both look very similar. They both perform the same job and produce the same result.</p>
<p>The difference becomes important when we talk about something called <strong>hoisting</strong>.</p>
<h3>Basic Idea of Hoisting</h3>
<p>Hoisting is a behavior in JavaScript where certain declarations are moved to the top of their scope during execution.</p>
<p>This may sound technical, but we can understand it with a simple experiment.</p>
<p>Let us try calling a function before defining it.</p>
<p>Example using a function declaration.</p>
<pre><code class="language-javascript">sayHello()

function sayHello() {
    console.log("Hello from declaration")
}
</code></pre>
<p>Output</p>
<p>Hello from declaration</p>
<p>Even though the function was written after the call, JavaScript still runs it successfully.</p>
<p>This happens because function declarations are hoisted. JavaScript internally prepares them before the code starts running.</p>
<p>Now try the same thing with a function expression.</p>
<pre><code class="language-javascript">sayHello()

let sayHello = function() {
    console.log("Hello from expression")
}
</code></pre>
<p>Output</p>
<p>Error occurs because sayHello is not a function yet</p>
<p>Here JavaScript throws an error. The function cannot be used before it is defined.</p>
<p>This happens because only the variable is hoisted, not the function stored inside it.</p>
<p>So when the program tries to run sayHello earlier, the function does not exist yet.</p>
<p>This is one of the biggest differences between function declarations and function expressions.</p>
<h3>When Should You Use Each Type</h3>
<p>Both styles are valid and widely used in JavaScript.</p>
<p>Function declarations are often used when you want to define general program logic that can be accessed anywhere in the file. They are easier to read and naturally hoisted.</p>
<p>Function expressions are useful when functions need to be treated like values. Since they are stored in variables, they can be passed around, returned from other functions, or stored inside objects.</p>
<p>In modern JavaScript development, function expressions are very common, especially when working with callbacks or event handling.</p>
<p>However, for beginners and for general logic, function declarations remain very simple and readable.</p>
<h3>A Small Practice Exercise</h3>
<p>The best way to understand these differences is by trying them yourself.</p>
<p>First write a function declaration that multiplies two numbers.</p>
<pre><code class="language-javascript">function multiplyNumbers(a, b) {
    let result = a * b
    console.log("Result from declaration:", result)
}

multiplyNumbers(6, 7)
</code></pre>
<p>Output</p>
<p>Result from declaration: 42</p>
<p>Now write the same logic using a function expression.</p>
<pre><code class="language-javascript">let multiplyNumbersExp = function(a, b) {
    let result = a * b
    console.log("Result from expression:", result)
}

multiplyNumbersExp(6, 7)
</code></pre>
<p>Output</p>
<p>Result from expression: 42</p>
<p>Finally try calling them before their definitions and observe the behavior.</p>
<p>You will notice that the declaration version works while the expression version throws an error.</p>
<p>Understanding this small difference helps you see how JavaScript prepares functions before execution.</p>
<p>Functions themselves are one of the most important building blocks of JavaScript. Whether you use declarations or expressions, the goal remains the same. You are organizing logic into reusable pieces so that your code becomes cleaner and easier to maintain.</p>
<p>Once you get comfortable with both styles, reading and writing JavaScript becomes much more natural.</p>
]]></content:encoded></item><item><title><![CDATA[Array Methods You Must Know]]></title><description><![CDATA[In this blog we will be seeing methods like
push() and pop()
shift() and unshift()
map()
filter()
reduce() (basic explanation only)
forEach()
If you are not well versed with the basics of Array, you c]]></description><link>https://blogs.gaurangpods.com/array-methods</link><guid isPermaLink="true">https://blogs.gaurangpods.com/array-methods</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[basics]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[arrays]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Fri, 13 Mar 2026 08:44:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/c0fc7241-7ae1-4649-a9ac-59710fc635d1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog we will be seeing methods like</p>
<p>push() and pop()</p>
<p>shift() and unshift()</p>
<p>map()</p>
<p>filter()</p>
<p>reduce() (basic explanation only)</p>
<p>forEach()</p>
<p>If you are not well versed with the basics of Array, you can refer to my blog named <strong>Arrays 101</strong>. It will make your fundamentals clear to an extent that you will never get confused with Array and its fundamentals.</p>
<p>Arrays 101 Blog link:<br /><a href="https://blogs.gaurangpods.com/javascript-arrays-101">https://blogs.gaurangpods.com/javascript-arrays-101</a></p>
<p>Now we will see each method.</p>
<h2>push() and pop()</h2>
<p>push and pop are methods that are used to push an element into the Array. It is used to put a new element into the array.</p>
<p>The thing to note here is that it shoves the new element into the last. The newer element is not pushed randomly anywhere in the array. Instead it is given the last index.</p>
<p>So every new element that is pushed takes the n index if the array is of length n.</p>
<p>So the new array will be of the length n+1 and the index of the element shoved by us via push method will be n.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let arr = [1,2,3];
</code></pre>
<p>Using push</p>
<pre><code class="language-javascript">arr.push(4);
</code></pre>
<p>After</p>
<pre><code class="language-javascript">[1,2,3,4]
</code></pre>
<p>Now pop is the method that pops out the last element from the array and returns that particular element only.</p>
<p>This is a caveat that you need to remember. Pop method basically pops out the last element from the array and only returns that popped out element and not the array that is left after popping out. A lot of people get confused in it.</p>
<p>Pop pops out the element having the last index. If the length of the array is n then element having index n-1 is popped out.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let arr = [1,2,3,4];
</code></pre>
<pre><code class="language-javascript">let removed = arr.pop();
</code></pre>
<p>After</p>
<pre><code class="language-javascript">removed -&gt; 4
arr -&gt; [1,2,3]
</code></pre>
<h2>shift()</h2>
<p>Next method is shift().</p>
<p>It is basically used to remove the very first element of the array. If we were to remove the element with index 0 of an array we will be using the shift method to remove it.</p>
<p>One thing to note is that shift returns the element that was removed.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let arr = [1,2,3,4];
</code></pre>
<pre><code class="language-javascript">let removed = arr.shift();
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">removed -&gt; 1
arr -&gt; [2,3,4]
</code></pre>
<p>Here shift removed the number 1 which was at index 0.</p>
<h2>unshift()</h2>
<p>Now we will see the unshift method.</p>
<p>This .unshift() basically shoves the element into the very beginning of the array. It makes the new element occupy the index starting from 0 of the array.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let arr = [3,4,5];
</code></pre>
<pre><code class="language-javascript">arr.unshift(1,2);
</code></pre>
<p>After</p>
<pre><code class="language-javascript">[1,2,3,4,5]
</code></pre>
<p>NOTE  </p>
<p>If we unshift multiple elements into an existing array, those elements will be shoved into the array starting from index 0.</p>
<p>So if three new elements are shoved, they will be taking the index 0, 1, 2 and the element which was at index 0 earlier will get moved ahead.</p>
<p>Before we see the example of the use of .map() method, keep this in mind.</p>
<p>Next methods that we will be seeing are</p>
<p>.map()</p>
<p>.filter()</p>
<p>.reduce()</p>
<p>.forEach()</p>
<p>Out of these only .forEach() does not return a new array.</p>
<p>.map() and .filter() return a new array.</p>
<p>.reduce() returns a single value which could be number, string, object etc.</p>
<h2>map()</h2>
<p>We will now see the .map() method.</p>
<p>What it does is it iterates over each element of the array and returns a new array according to the condition described in the callback inside map().</p>
<p>Important thing to keep in mind is that it returns a new array.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let numbers = [2,4,6];
</code></pre>
<p>Using map</p>
<pre><code class="language-javascript">let doubled = numbers.map(function(num){
   return num * 2
})
</code></pre>
<p>After</p>
<pre><code class="language-javascript">doubled -&gt; [4,8,12]
numbers -&gt; [2,4,6]
</code></pre>
<p>Original array stays unchanged.</p>
<h3>Traditional loop vs map</h3>
<p>Traditional loop</p>
<pre><code class="language-javascript">let numbers = [2,4,6]
let doubled = []

for(let i = 0; i &lt; numbers.length; i++){
   doubled.push(numbers[i] * 2)
}
</code></pre>
<p>Using map</p>
<pre><code class="language-javascript">let doubled = numbers.map(num =&gt; num * 2)
</code></pre>
<p>Both work the same but map makes the intent clearer.</p>
<h2>filter()</h2>
<p>Next is filter.</p>
<p>It filters out the elements according to the condition provided and returns a new array according to that condition.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let numbers = [5,12,8,20];
</code></pre>
<p>Using filter</p>
<pre><code class="language-javascript">let greaterThanTen = numbers.filter(function(num){
   return num &gt; 10
})
</code></pre>
<p>After</p>
<pre><code class="language-javascript">[12,20]
</code></pre>
<p>So filter only keeps the elements that satisfy the condition.</p>
<h2>reduce()</h2>
<p>Next is reduce method.</p>
<p>Reduce is used when we want to calculate something out of the array and get a single result.</p>
<p>Example</p>
<p>Before</p>
<pre><code class="language-javascript">let numbers = [5,10,15];
</code></pre>
<p>Using reduce</p>
<pre><code class="language-javascript">let sum = numbers.reduce(function(accumulator,current){
   return accumulator + current
},0)
</code></pre>
<p>Result</p>
<pre><code class="language-javascript">sum -&gt; 30
</code></pre>
<p>Here the accumulator keeps adding the values step by step until the final result is produced.</p>
<h2>forEach()</h2>
<p>Now the last one we will see is the forEach array method.</p>
<p>The important thing is that it does not return a new array. It simply runs a function for every element in the array.</p>
<p>It looks like this</p>
<pre><code class="language-javascript">arr.forEach((element,index) =&gt; {

})
</code></pre>
<p>You can see it has a callback with element and index as its parameters.</p>
<p>Example</p>
<pre><code class="language-javascript">let numbers = [10,20,30];

numbers.forEach(function(num){
   console.log(num)
})
</code></pre>
<p>Output</p>
<pre><code class="language-javascript">10
20
30
</code></pre>
<p>One important thing to remember is that forEach does not wait for asynchronous tasks.  </p>
<p>Hope you enjoyed the blog and it helped in your journey of becoming a 100x Dev!</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Arrays 101]]></title><description><![CDATA[Arrays are considered non-primitive in JavaScript. The data type of arrays in JavaScript is Object. In JavaScript, objects are counted as non-primitive data types. Non-primitive data types are slightl]]></description><link>https://blogs.gaurangpods.com/javascript-arrays-101</link><guid isPermaLink="true">https://blogs.gaurangpods.com/javascript-arrays-101</guid><category><![CDATA[array]]></category><category><![CDATA[arrays]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[array methods]]></category><category><![CDATA[Objects]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Thu, 05 Mar 2026 22:14:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/d00848a7-7560-4adc-836f-d950aa69a829.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Arrays are considered <strong>non-primitive</strong> in JavaScript. The data type of arrays in JavaScript is <strong>Object</strong>. In JavaScript, objects are counted as non-primitive data types. Non-primitive data types are slightly more complex because they can store multiple values or combinations of primitive data types. Arrays fall into this category because they can store multiple values inside them.</p>
<p>Arrays are represented using <strong>square brackets []</strong>. Whatever is present inside these brackets is called an <strong>element</strong>, and the elements are separated by commas. These elements can be of any data type. They can be primitive values like numbers and strings, or they can also be non-primitive values like objects or even other arrays.</p>
<p>The elements are separated by commas. To access or work with elements inside an array, JavaScript provides multiple inbuilt methods such as <code>.filter()</code>, <code>.sort()</code>, <code>.map()</code> etc. These methods help in iterating over arrays and returning elements based on our requirement. Depending on the use case, we decide which method to apply.</p>
<p>In simple terms, an <strong>array is a collection of values stored in a particular order</strong>. Because the values are stored in order, each element gets a position number. This position is called the <strong>index</strong>.</p>
<p>Indexing in arrays <strong>starts from 0</strong>.</p>
<p>So the first element has index <strong>0</strong>, the second element has index <strong>1</strong>, and it continues in the same manner. If an array has <strong>n elements</strong>, then the last element will have the index <strong>(n-1)</strong>.</p>
<p>The last element has index <strong>n-1 and not n</strong> because indexing starts from <strong>0 and not from 1</strong>.</p>
<h3>How to create an array</h3>
<p>Now comes the question of how to create an array. There are multiple ways to create arrays in JavaScript. We will look at some of the most commonly used ones.</p>
<p><strong>1.First method</strong></p>
<p>The first way is to initialize a variable with empty square brackets.</p>
<pre><code class="language-plaintext">let books = [];
</code></pre>
<p>This creates an empty array named <code>books</code>.</p>
<h2><strong>NOTE:</strong></h2>
<h3>1. Why arrays are needed</h3>
<p>Example:-</p>
<p>Instead of:</p>
<pre><code class="language-javascript">let book1 = "Maths"
let book2 = "Physics"
let book3 = "Chemistry"
</code></pre>
<p>We use:</p>
<pre><code class="language-javascript">let books = ["Maths", "Physics", "Chemistry"]
</code></pre>
<h3>2. Accessing array elements using index</h3>
<p>Example:</p>
<pre><code class="language-javascript">let books = ["Maths", "Physics", "Chemistry"];

console.log(books[0]); // first element ie "Maths"
console.log(books[2]); // third element ie "Physics"
</code></pre>
<p>2. <strong>Second method</strong></p>
<p>Another way is to directly add elements inside the square brackets, separated by commas.</p>
<p>Example:</p>
<pre><code class="language-plaintext">let books = ["Maths", "Physics", "Chemistry"];
</code></pre>
<p>This creates an array with three elements.</p>
<p><strong>3. Third method</strong></p>
<p>If we want to create an array with a fixed number of empty slots, we can use the <code>Array()</code> constructor.</p>
<p>Example:</p>
<pre><code class="language-plaintext">let books = Array(3);
</code></pre>
<p>This creates an array with a length of <strong>3</strong>. Now what this means is that our array will be containing three elements separated by commas. So this way It creates an array <strong>with length 3 but no defined values yet</strong>.</p>
<p><strong>Another method that is useful for creating an array is</strong> <code>Array.of()</code>.  </p>
<p>What it basically does is create a new array. The important thing to keep in mind is that we need to provide the elements directly inside the argument of <code>Array.of()</code>. In other words, the method will create the array, but the actual elements must be passed as arguments to <code>Array.of()</code>.</p>
<p><strong>Example</strong></p>
<pre><code class="language-javascript">let books = Array.of("Maths", "Physics", "Chemistry");

console.log(books);
</code></pre>
<p>Output:</p>
<pre><code class="language-javascript">["Maths", "Physics", "Chemistry"]
</code></pre>
<p>In this example, the elements <code>"Maths"</code>, <code>"Physics"</code> and <code>"Chemistry"</code> are passed as arguments to <code>Array.of()</code>, and the method creates an array containing these values.</p>
<p><code>Second method is Array.from()</code> , this is also one way to crete an Array, like if we want to create<br />the array containing charachters of a particular string, we would be using this method. see the example below to understand</p>
<pre><code class="language-javascript">const myString = "hello";
const stringArray = Array.from(myString);

console.log(stringArray);
// Output: ['h', 'e', 'l', 'l', 'o']
</code></pre>
<hr />
<h3>Updating elements in an array</h3>
<p>In order to update elements in an array, there are multiple ways depending on the use case.</p>
<p>For example, if we want to remove a particular element from an array, we can use the <strong>splice()</strong> method. How <code>splice()</code> is used depends on the situation and the index we want to modify.</p>
<p>If we want to add or change a value at a particular index, we can directly assign a new value to that index.</p>
<pre><code class="language-javascript">let books = ["Biology", "Economics", "History"]

//Now we want to update the books array by removing the last two elements of the array and add the element "English" into the array.

//We use  .splice(index of the element you want to delete , number of elements to be deleted, new element in quotes.

//splice(startIndex, numberOfElementsToDelete, newElement)

books.splice(1, 2, "English")
</code></pre>
<p>Output:</p>
<pre><code class="language-javascript">books = ["Biology", "English"];
</code></pre>
<p>Refer to the Excalidraw diagram below to understand this visually.  </p>
<p>Now we will see the use of splice method to not only remove an element but to also add<br />an element in place of the removed one ie how it swaps. Look at the excalidraw image below:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6950f282d7c55cc3d6748277/d27db981-06d9-4432-b215-5edf9cfaf71c.png" alt="" style="display:block;margin:0 auto" />

<p>What we did above is that we replaced the element having "Physics" as string with "Economics". So splice() method can not only delete but also add elements simultaneously<br />in the array and hence modifies the array in this manner.</p>
<h3>Array length property</h3>
<p>If we want to know how many elements are present in an array, we use the <strong>length property</strong>.</p>
<pre><code class="language-javascript">arrayName.length
</code></pre>
<p>Example:</p>
<pre><code class="language-javascript">let books = ["Maths", "Physics", "Chemistry"]
</code></pre>
<pre><code class="language-plaintext">books.length gives us 3 as output, since we are having 3 elements in the Array.
</code></pre>
<p>This returns the total number of elements in the array.</p>
<hr />
<h3>Looping over an array</h3>
<p>If we want to go through all elements of an array one by one, we use loops. There are multiple ways to do this depending on the situation.</p>
<p>One common way is using a <strong>for loop</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">for(let i = 0; i &lt; books.length; i++){
    console.log(books[i]);
}
</code></pre>
<p>This loop runs through the array and prints each element one by one.</p>
<p>Another way is using a <strong>for...of loop</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">for(let book of books){
    console.log(book);
}
</code></pre>
<p>This directly gives us the elements of the array while looping.</p>
<p>NOTE: We dont use for..in loop in Arrays generally bcz it is more apt to be used for iterating over Objects, and we tend to not use them in Arrays. However, Arrays are also Objects and hence for..in loop also works for Arrays.<br />Here is the code for it :-<br />Example:</p>
<pre><code class="language-javascript">let books = ["Biology", "Economics", "History"];

for (let index in books) {
    console.log(books[index]); // prints the value
}
</code></pre>
<p>So this is all you need to know related to Arrays in Javascript. Hope it helps!</p>
]]></content:encoded></item><item><title><![CDATA[CSS Selectors 101: Targeting Elements with Precision]]></title><description><![CDATA[When we start learning CSS, one of the first questions that naturally comes up is how CSS knows which part of the HTML to style. We write rules, add colors, change sizes, but unless CSS knows where to apply those rules, nothing really happens. This i...]]></description><link>https://blogs.gaurangpods.com/css-selectors-101-targeting-elements-with-precision</link><guid isPermaLink="true">https://blogs.gaurangpods.com/css-selectors-101-targeting-elements-with-precision</guid><category><![CDATA[CSS]]></category><category><![CDATA[selectors]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[basics]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Fri, 30 Jan 2026 13:38:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769780222001/49c8fb85-5323-44ed-b9c9-b4c42fdc89f6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning CSS, one of the first questions that naturally comes up is how CSS knows which part of the HTML to style. We write rules, add colors, change sizes, but unless CSS knows where to apply those rules, nothing really happens. This is where CSS selectors come in. Selectors are simply a way to tell CSS, this is the element I want you to style. Without selectors, CSS would have no direction and no purpose.</p>
<p>You can think of selectors as a way of choosing elements from your HTML. Just like in real life, when you want to talk to someone specific, you need to call them out clearly. CSS works in the same way. It needs a clear instruction about which element or group of elements should receive a certain style. Once this idea clicks, CSS becomes much easier to understand.</p>
<p>The most basic type of selector is the element selector. This selector targets HTML elements directly by their tag name. For example, if you want to style all paragraph tags on a page, you simply write a rule for the p element. This tells CSS to apply the same styling to every paragraph present in the document. Element selectors are simple and powerful, but they affect all instances of that element, which is not always what we want.</p>
<p>As our web pages grow, we often need more control. This is where class selectors become useful. A class allows us to label specific elements so that we can style only those elements and ignore the rest. In HTML, we assign a class attribute to an element, and in CSS, we target that class using a dot followed by the class name. This gives us flexibility because the same class can be reused on multiple elements. It is a clean and practical way to apply consistent styling without affecting everything.</p>
<p>Going one step further, we have ID selectors. An ID is meant to be unique and should be used only once on a page. When we assign an ID to an element, we are saying that this element is special and should be treated differently from others. In CSS, an ID selector is written using a hash symbol followed by the ID name. Because IDs are unique, they allow very precise styling. However, beginners should use them carefully and only when uniqueness is truly required.</p>
<p>Sometimes, we want to apply the same style to multiple elements at once, even if they are different types. Group selectors help us do exactly that. By separating multiple selectors with commas, we can write one CSS rule that applies to all of them. This keeps our CSS clean and avoids repetition. It also makes the code easier to read and maintain, especially as projects become larger.</p>
<p>Another important concept is the descendant selector. This selector allows us to target elements that are inside other elements. For example, if you want to style only the paragraphs that are inside a div, you can do that using a descendant selector. This is extremely useful because it helps us apply styles based on structure, not just labels. It reflects how HTML is actually nested and organized.</p>
<p>While working with selectors, it is also important to understand that not all selectors are treated equally by CSS. There is a basic priority system involved. At a very high level, ID selectors have more priority than class selectors, and class selectors have more priority than element selectors. This means that if multiple rules try to style the same element, the one with higher priority will usually win. Understanding this early prevents confusion when styles do not behave as expected.</p>
<p>To really see the impact of selectors, it helps to look at before and after styling. Before applying CSS, HTML appears plain and unstructured. Once selectors are used correctly, the same HTML becomes organized, readable, and visually appealing. Nothing changes in the HTML itself, only the way we select and style elements does.</p>
<p>At the end of the day, CSS selectors are the foundation of CSS. Every layout, every color, every design decision depends on selecting the right elements. Once you are comfortable with selectors, the rest of CSS feels far less intimidating. As a beginner, spending time understanding selectors deeply is one of the best investments you can make in your frontend journey.</p>
]]></content:encoded></item><item><title><![CDATA[How a Browser Works: A Beginner Friendly Guide to Browser Internals]]></title><description><![CDATA[Now we will see how a browser is actually able to show a website to us. In computer science, we often have a habit of using complex or rich terms for things that are actually very simple. So instead of saying how a browser shows a website, we usually...]]></description><link>https://blogs.gaurangpods.com/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals</link><guid isPermaLink="true">https://blogs.gaurangpods.com/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals</guid><category><![CDATA[Browsers]]></category><category><![CDATA[browser]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[CSS]]></category><category><![CDATA[DOM]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Fri, 30 Jan 2026 05:49:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769752072996/88ffe355-ce37-4eb6-a328-b005f128243f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Now we will see how a browser is actually able to show a website to us. In computer science, we often have a habit of using complex or rich terms for things that are actually very simple. So instead of saying how a browser shows a website, we usually say how a browser renders a website. In this section, we will understand how a browser renders things in a simple and beginner-friendly way.</p>
<p>Browser is not just a tool to open websites, but a software system whose job is to request resources from servers, process them, and turn them into something humans can see and interact with. This helps beginners reset their mental model early.</p>
<p>Now, coming to the first step, whenever we type a website name in the browser’s URL bar and press Enter, the browser does not immediately know where that website lives. The first thing that happens is a DNS query. This DNS query goes out and comes back with the IP address of the server where the website is hosted. If you are not already aware of how a DNS query works, you can go through my separate blog on DNS, which explains this part in detail.<br />Link to DNS Query Blog: <a target="_blank" href="https://blogs.gaurangpods.com/dns-resolution">DNS Resolution Blog</a></p>
<p>Once the DNS query is completed, the browser now has the IP address of the server. After this, the browser makes an HTTP request over TCP to that server. The server then responds with data, and this data mainly contains HTML, CSS, and JavaScript. These three things together are what the browser needs in order to display the website.</p>
<p>Now the question arises of how the browser is able to process all this data efficiently and display a webpage on the screen. A browser is not just a single piece of software but a collection of different components working together. First, there is the user interface, which includes things like the address bar, tabs, back and forward buttons, and the visible screen area where the webpage appears.</p>
<p>Behind the user interface, there is something called the browser engine. The browser engine acts as a coordinator between the user interface and the rendering engine. It controls how actions from the UI are passed to the rendering engine and how the rendered content is shown back on the screen.</p>
<p>Inside the browser, there are mainly three important engines. The first is the browser engine, which we just discussed. The second is the rendering engine, and the third is the JavaScript engine. The rendering engine is responsible for understanding and processing HTML and CSS. The JavaScript engine is responsible for executing JavaScript code. In Chrome, the most popular JavaScript engine is V8.</p>
<p>When the server response is received, the rendering engine starts working on the HTML and CSS. At this stage, something called parsing happens. Parsing simply means taking the raw HTML and CSS text and converting it into a structured format that the browser can understand. This structure follows specific rules and looks like a tree.</p>
<p>The result of HTML parsing is called the Document Object Model, or DOM. Similarly, the result of CSS parsing is called the CSS Object Model, or CSSOM. These object models are internal representations that the browser uses to understand the structure of the page and how it should look.</p>
<p>While the HTML is being parsed, if the browser encounters JavaScript linked inside the HTML, that JavaScript is passed to the JavaScript engine for execution. JavaScript can interact with the DOM and change it, which means the structure of the page can be modified even after it has been initially created.</p>
<p>Once both the DOM and CSSOM are ready, they are brought together. This step allows the browser to figure out which styles apply to which elements. After this, the browser moves on to layout. During layout, the browser calculates the size and position of each element on the page. This step is also commonly referred to as reflow.</p>
<p>After layout is complete, the browser starts painting. Painting means filling in pixels, colors, text, images, and borders based on the calculated layout. Once painting is done, the final result is displayed on the screen. This is the point where the webpage becomes visible to the user.</p>
<p>If the DOM changes later, for example due to JavaScript updates, this internal process can happen again. The browser may need to recalculate layout, repaint parts of the page, and then update the display. This entire flow is how a browser renders a webpage from the moment you press Enter to the moment you see content on the screen.</p>
<p>Note that you do not need to memorize all the steps. it’s just that you should have a basic idea about the overall workflow.</p>
]]></content:encoded></item><item><title><![CDATA[Emmet for HTML: A Beginner’s Guide to Writing Faster Markup]]></title><description><![CDATA[If you have ever written HTML by hand, you know how repetitive it can get very quickly. Typing angle brackets, writing opening and closing tags, and making sure everything is properly nested takes time. For someone who is just starting out, this can ...]]></description><link>https://blogs.gaurangpods.com/emmet-for-html-a-beginners-guide-to-writing-faster-markup</link><guid isPermaLink="true">https://blogs.gaurangpods.com/emmet-for-html-a-beginners-guide-to-writing-faster-markup</guid><category><![CDATA[HTML5]]></category><category><![CDATA[HTML]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><category><![CDATA[Emmet]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Thu, 29 Jan 2026 23:55:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769730805862/1fda826b-81fa-43eb-95a5-764a48c60e93.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you have ever written HTML by hand, you know how repetitive it can get very quickly. Typing angle brackets, writing opening and closing tags, and making sure everything is properly nested takes time. For someone who is just starting out, this can feel slow and sometimes even frustrating. Emmet exists to remove this friction and make writing HTML feel smoother.</p>
<p>Emmet is a shortcut system that helps you write HTML faster. Instead of typing full HTML tags every time, you write short abbreviations and let the code editor expand them into complete HTML. You are still writing normal HTML, just in a much quicker way. Think of it as a helper that understands what you want to write and fills in the repetitive parts for you.</p>
<p>For HTML beginners, Emmet is especially useful because it reduces the chances of small mistakes. You no longer have to worry much about forgetting a closing tag or breaking the structure of your page. This allows you to focus more on understanding how a webpage is built rather than getting stuck on syntax errors.</p>
<p>Emmet works inside most modern code editors without any extra setup. Editors like VS Code support Emmet by default. You simply type an Emmet abbreviation and press the Tab key, and the editor converts it into proper HTML. Once you see this happen a few times, it starts to feel very natural.</p>
<p>The basic idea behind Emmet is simple. You describe the element you want using a short form, and Emmet expands it. For example, typing <code>p</code> and pressing Tab generates a paragraph tag. Typing <code>h1</code> creates a heading. This works for most commonly used HTML elements and covers a large part of daily HTML writing.</p>
<p>You can also create elements with classes, IDs, and attributes directly using Emmet. Writing <code>div.card</code> creates a div with a class named card, and writing <code>section#about</code> creates a section with an id called about. This saves time and keeps your focus on structure instead of typing.</p>
<p>Creating nested elements is another area where Emmet really shines. When you want one element inside another, you can describe that relationship directly. For example, writing <code>div&gt;p</code> expands into a div that contains a paragraph. This makes layouts easier to visualize while you type.</p>
<p>Emmet also helps when you need repeated elements. If you want multiple similar elements, you can use multiplication. Writing <code>li*5</code> generates five list items at once. This is very handy when creating menus, lists, or repeated sections.</p>
<p>One of the most commonly used Emmet shortcuts is generating a full HTML boilerplate. Typing <code>!</code> and pressing Tab instantly creates the basic HTML structure with the doctype, head, and body tags already in place. This removes the small but repetitive task of setting up a new file.</p>
<p>The best way to get comfortable with Emmet is to try it yourself while writing HTML. Type the abbreviation, press Tab, and see what gets generated. Emmet is not mandatory, but once you get used to it, writing HTML without it feels unnecessarily slow.  </p>
<p>To make this more practical, here are a few very simple examples you can try on your own. If you type <code>p</code> in your editor and press Tab, it expands into a paragraph tag ready for text. Typing <code>div.container</code> creates a div with a class named container. Writing <code>ul&gt;li*3</code> generates an unordered list with three list items inside it. You can also try <code>a</code> and press Tab to see how a link tag appears. These small shortcuts may look minor at first, but once you start using them regularly, they save a surprising amount of time.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding HTML Tags and Elements]]></title><description><![CDATA[HTML which is Hyper Text Markup Language is basically the one who makes the skeleton of a website. Just like in a human body , we first have a skeleton , then skin and then the brain, similarly in the case of website we have HTML, CSS JavaScript. whe...]]></description><link>https://blogs.gaurangpods.com/understanding-html-tags-and-elements</link><guid isPermaLink="true">https://blogs.gaurangpods.com/understanding-html-tags-and-elements</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Hashnode]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Thu, 29 Jan 2026 14:28:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769696224492/ade6e88b-8da3-433a-ae38-ac440fd269a7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>HTML which is Hyper Text Markup Language is basically the one who makes the skeleton of a website. Just like in a human body , we first have a skeleton , then skin and then the brain, similarly in the case of website we have HTML, CSS JavaScript. wherin HTML acts like the skeleton of the website, while CSS acts as the skin on top of that skeleton while JavaScript forms the brain of the website.</p>
<p>In its simplest form, <strong>HTML</strong> (HyperText Markup Language) is the standard language used to create the structure of a webpage. It isn't a programming language; instead, it is a <strong>markup language</strong> that uses "tags" to tell the browser how to display content.</p>
<p><strong>HyperText</strong>: Refers to the "links" that connect webpages to one another.</p>
<p><strong>Markup</strong>: Refers to the special symbols (tags) used to annotate text, images, and other content so the browser knows if something is a heading, a paragraph, or a list.</p>
<p><strong>Language</strong>: Refers to the set of rules and syntax that must be followed, So that every browser interprets the code the same way.</p>
<p>Lets see some frequently used common tags and an Analogy to understand HTML</p>
<h3 id="heading-the-box-analogy">The Box Analogy</h3>
<p>Think of an HTML tag as a <strong>label on a storage box</strong>. The opening tag (<code>&lt;tag&gt;</code>) is like opening the lid, the content inside is the item you’re storing, and the closing tag (<code>&lt;/tag&gt;</code>) is like shutting the lid. The "box" (the element) tells the browser exactly what kind of content is inside so it knows how to handle it.</p>
<p>NOTE: Difference between a tag and an element:- A tag when contains the content(text, image, files etc) becomes an element.</p>
<p>Tags:</p>
<ul>
<li><p><code>&lt;h1&gt;</code>: The primary heading used to define the main title or most important topic of a webpage.</p>
</li>
<li><p><code>&lt;p&gt;</code>: The standard element used to distribute text into readable paragraphs.</p>
</li>
<li><p><code>&lt;div&gt;</code>: A generic block-level container used to group elements together for layout or styling purposes.</p>
</li>
<li><p><code>&lt;span&gt;</code>: An inline container used to mark up or style a specific part of a text without breaking the line.</p>
</li>
<li><p><code>&lt;ul&gt;</code>: Defines an unordered list where items are typically displayed with bullet points.</p>
</li>
<li><p><code>&lt;li&gt;</code>: Represents a single item within a list, whether that list is ordered or unordered.</p>
</li>
<li><p><code>&lt;a&gt;</code>: Creates a hyperlink that allows users to navigate to other pages, files, or locations on the same page.</p>
</li>
<li><p><code>&lt;img&gt;</code>: An empty, self-closing element used to embed an image by referencing its source file path.</p>
</li>
<li><p><code>&lt;section&gt;</code>: A semantic element used to wrap a standalone portion of a document that relates to a specific theme.</p>
</li>
<li><p><code>&lt;header&gt;</code>: Represents introductory content at the top of a page or section, often containing titles or navigation.</p>
</li>
<li><p><code>&lt;footer&gt;</code>: Contains concluding information at the bottom of a page or section, such as copyright and contact details.</p>
</li>
</ul>
<p>Some HTML elements naturally start on a new line and take the full width of the page, such as headings, paragraphs, and divs. Others stay within the same line and only take as much space as needed, like span and links. This difference becomes very useful later when styling pages. This is block level vs inline elements. Block-level elements include <code>h1</code> to <code>h6</code>, <code>p</code>, <code>div</code>, <code>section</code>, <code>header</code>, <code>footer</code>, <code>ul</code>, and <code>li</code>. Inline elements include <code>span</code>, <code>a</code>, <code>img</code>, <code>strong</code>, <code>em</code>, and <code>br</code>.</p>
<p>Not all HTML elements wrap content inside them. Some elements, like the image tag, only need a single tag because there is no content to place inside. These are called self-closing or void elements.</p>
<p>One good habit while learning HTML is to open any website, right click on it, and click on “Inspect”. What you see there is the HTML of that page. This helps in understanding how real websites are structured and makes HTML feel less abstract and more practical.</p>
<p>Hope this crisp blog helps you understand the HTML and its common Tags.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with cURL]]></title><description><![CDATA[Curl = Client URL Request Library. With this, we can upload or download data from the internet using the command line. We can also use the cURL command to transfer data between machines. If you ever go to cURL’s website, you will see the subtitle “Tr...]]></description><link>https://blogs.gaurangpods.com/getting-started-with-curl</link><guid isPermaLink="true">https://blogs.gaurangpods.com/getting-started-with-curl</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><category><![CDATA[terminal command]]></category><category><![CDATA[web]]></category><category><![CDATA[server]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Wed, 28 Jan 2026 04:47:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769575199585/42601997-3e0f-4b99-9f7a-7d5e6c1013f8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Curl = Client URL Request Library. With this, we can upload or download data from the internet using the command line. We can also use the cURL command to transfer data between machines. If you ever go to cURL’s website, you will see the subtitle “Transferring data since 1998,” which is very apt.</p>
<p>It is a command-line tool that lets you transfer data to or from a server using various protocols like HTTP, HTTPS, FTP, and more.</p>
<p>To view a website via cURL in the command line, we should use:</p>
<p>curl -L &lt;your website name&gt;</p>
<p>For example, if we want to see the website <a target="_blank" href="http://gaurangpods.com">gaurangpods.com</a> via the terminal, we can simply run the command:<br />curl -L https://<a target="_blank" href="http://gaurangpods.com">gaurangpods.com</a></p>
<p>However, note that upon running this command, it does not save anything on our system in a folder. It basically just shows us all the content that the website contains in the terminal, but it does not save it anywhere on our system.</p>
<p>cURL prints the raw response to the terminal. What you see is raw HTML, JSON, or other data.</p>
<p>Unlike a browser, which is designed to make things look pretty for humans, cURL is designed to give developers raw, unfiltered access to server responses.</p>
<p>cURL doesn’t download images, doesn’t execute JavaScript, and doesn’t render CSS. It just fetches data. This makes it fast and lightweight.</p>
<p>cURL works identically on Windows, macOS, and Linux, so your commands are portable across environments.</p>
<p>The <code>-v</code> (verbose) flag shows you everything that cURL sends and receives.</p>
<p>This shows you DNS resolution, connection details, the SSL handshake for HTTPS, full request headers, and full response headers.</p>
<p>Lines starting with <code>&gt;</code> show what cURL sends to the server, and lines starting with <code>&lt;</code> show what the server sends back.</p>
<p>The <code>-I</code> flag fetches only the headers and not the body, which includes the HTTP status code.</p>
<p>GET is the default HTTP method. It is used to retrieve information without modifying anything on the server.</p>
<p>POST is another common HTTP method used with cURL. Unlike GET, which is used only to fetch data, POST is used when we want to send data to the server, such as submitting a form, sending login details, or creating a new record. In cURL, POST requests are usually made when we want the server to process some data and return a response based on that input.</p>
<p>cURL needs to know which protocol to use, so always include <code>http://</code> or <code>https://</code> in the URL.</p>
]]></content:encoded></item><item><title><![CDATA[DNS resolution]]></title><description><![CDATA[DNS is the Domain Name System. As the name suggests, it is basically a system that has been created to manage domains. Simply put, domains are the names of the websites that users visit. Although computers don’t understand human language like English...]]></description><link>https://blogs.gaurangpods.com/dns-resolution</link><guid isPermaLink="true">https://blogs.gaurangpods.com/dns-resolution</guid><category><![CDATA[dns]]></category><category><![CDATA[dns resolver]]></category><category><![CDATA[dns-records]]></category><category><![CDATA[basics]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Tue, 27 Jan 2026 13:43:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769521275731/90ce11c9-de99-4052-a340-ba224fb3fc57.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>DNS is the Domain Name System. As the name suggests, it is basically a system that has been created to manage domains. Simply put, domains are the names of the websites that users visit. Although computers don’t understand human language like English, for users it is very difficult to remember websites in a computer-understandable language. Hence, this system came into place which basically converts the name of the website into computer-understandable language internally, called IP addresses.</p>
<p>So every website is given an IP address, which is nothing but the address where the code of the website is deployed, indicating on which server in the world it is hosted. Just like we humans live in houses and each house has an address associated with it which helps us identify its location in the world, websites have IP addresses which help in identifying the address where the code is deployed or “living” in the server’s world.<br />So, DNS resolution is the process of converting a human-readable domain name into its corresponding IP address.<br />This allows browsers and applications to locate and communicate with the correct server on the internet.</p>
<p><code>dig</code> (Domain Information Groper) is a command-line tool used to query DNS servers and fetch information like IP addresses, MX records, or name servers for a domain.</p>
<p>Now, first understand a few terms related to DNS servers.<br />Firstly, what are DNS servers? They are basically servers that track DNS records. For storing the IP addresses of websites, we have dedicated servers called DNS servers, and within them there are further classifications.</p>
<p>Firstly, recursive DNS servers. These are the servers that browsers talk to directly, or in other words, browsers send their DNS queries to these servers first. They cache IP addresses, and if a particular IP is not cached, they internally follow the DNS resolution process to get the IP, which they then cache and also send back to the client who requested it.</p>
<p>Internally, the request first goes to the root servers, which are basically 13 logical root server groups. These servers keep track of which servers handle which top-level domains. For example, these servers know which servers across the globe contain information about “.com” ending websites. So if a DNS query comes for a <code>.com</code> domain, they direct the request to the correct top-level domain servers.</p>
<p>Then, these top-level domain servers contain information about which authoritative servers are responsible for a particular domain. They direct the query to the correct server that has authority over that domain. These servers are called authoritative servers, meaning they have the authority to provide the final DNS answer for that domain. These servers then send the response back to the recursive DNS server as the answer to the DNS query.</p>
<p>So the request flow as mentioned above is:<br />Client → Recursive DNS Server → Root Server → Top-Level Domain Server → Authoritative Server.<br />The authoritative server responds back to the recursive DNS server with the IP address where the website is hosted, and then the final flow is:<br />Recursive DNS Server → Client.</p>
<p>Now we will see the commands that help us fetch information like IP addresses using a command-line tool. But before that, we need to understand one very important concept, which is the NS record.</p>
<p>An NS record, as the name suggests, is a Name Server record. It indicates which server has authority over your domain. Let’s say you bought your domain from Hostinger for your website. Later, when you built the frontend and backend of your website and wanted to deploy it, you realized that you don’t want to use Hostinger’s servers for deployment. Instead, you decide to deploy on Vercel because they provide CDN and SSL certificates, meaning security-related features which otherwise you would have to configure yourself using tools like Nginx, firewalls, etc.</p>
<p>So, to avoid that extra effort, you choose Vercel since it is free and also provides built-in security features. Now, since you bought the domain from Hostinger, you need to go to your Hostinger account, open the DNS records of your domain, and update the NS records provided by Vercel. This tells the entire internet that “Hostinger is no longer responsible for this domain; ask Vercel where the website is.” Hostinger does not host the code anymore, it only points to the manager (Vercel) who knows where the code is hosted.</p>
<p>The <code>dig . NS</code> command helps us identify the list of root name servers, so it shows the names of the root servers.</p>
<p>The <code>dig com NS</code> command helps us get the name servers for the <code>.com</code> top-level domain. These are the authoritative servers responsible for maintaining records of <code>.com</code> domains.</p>
<p>The <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code> command shows the name servers that have authority over the <a target="_blank" href="http://google.com"><code>google.com</code></a> domain. Since Google is a tech giant, they have their own authoritative DNS servers to handle DNS queries, unlike most developers who use providers like Vercel or Netlify.</p>
<p>When you run <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a>, the command asks the DNS system for the basic DNS information of the domain, and by default it mainly shows the A record, which gives the IP address of <a target="_blank" href="http://google.com"><code>google.com</code></a>. This IP address is what the browser ultimately uses to connect to Google’s servers and load the website.</p>
<p>However, when you run <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code>, you are being specific and asking only for the NS (Name Server) records, which tell you which DNS servers are responsible for managing the <a target="_blank" href="http://google.com"><code>google.com</code></a> domain, not its IP address.  </p>
<p>So these are the dig commands application that takes place for getting information similart ot what we got above. Hope this simple-short blog helped you in making the concept of DNS RESOLUTION crystal clear.</p>
]]></content:encoded></item><item><title><![CDATA[DNS Record Types Explained]]></title><description><![CDATA[DNS is Domain Name system. As the name suggests it is basically a system that has been created to manage the domains. Simply put, Domains are basically the name of the website on which the users are visiting. Although the computers dont understand th...]]></description><link>https://blogs.gaurangpods.com/dns-record-types-explained</link><guid isPermaLink="true">https://blogs.gaurangpods.com/dns-record-types-explained</guid><category><![CDATA[dns]]></category><category><![CDATA[dns-records]]></category><category><![CDATA[basics]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[beginner]]></category><dc:creator><![CDATA[Gaurang Nagar]]></dc:creator><pubDate>Sat, 24 Jan 2026 06:52:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769237422233/bb2bf9e3-3cb2-4693-a1bb-1ed70c205a39.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>DNS is Domain Name system. As the name suggests it is basically a system that has been created to manage the domains. Simply put, Domains are basically the name of the website on which the users are visiting. Although the computers dont understand the human language like english but for the users its very difficult to remember the websites in the computer understandable language. Hence this system got in place which basically converts the name of the website into computer understandable language internally called as IP addresses.</p>
<p>So every website is given an IP address which is nothing but the address where the code of the website is deployed on which server in the world. Just like we humans live in houses and each house has an address associated to it which helps us in identifying the location of that house in the world, we have IP addresses which helps us in identifying the address where our code is deployed/living in the server’s world.</p>
<p>Now there are Different types of different records in DNS and each solve a particular purpose. Let’s see them one by one-</p>
<p>A record : This is basically the record that gives the address where our website have been deployed, so it gives the IP address associated with that domain . its usually a key value pair where key is like “@” and there is value associated to it like 1212.12.12 .The IP that used to be given for A records was IPv4</p>
<p>AAAA record: This is similar like the A record , its just that instead of giving IP of the type IPv4 , we give here IPv6. This we have started doing bcz IPv4 Limit was to reach bcz the number of IP provided reached to its maximum capacity and hence a new version was designed to cater the ever-growing need of the new IP addresses. This also tells the IP address associated with the domain.</p>
<p>NS record: NS record as the name suggest is Name Server record ie it is the one who handles the authority of your domain. Let’s say you bought your domain from hostinger for your website but when you wrote the frontend and the backend of your website and wanted to deploy it to make it live, You realised that i dont want to use hostinger server's for deployment instead you want to deploy them on Vercel server bcz they provide you CDN and also ssl certificate ie security related stuffs which otherwise you would have to do by yourself by implementing nginx, firewall etc, so in order to skip that headache u chose to use vercel as they are free and at the same time provide the security features that otherwise u would have implemented by yourself whihch again is a tedious job, so u chose vercel. Now since u have bought the domain from the hostinger u need to go to hostinger account and go to dns records of your purchased domain and there update the ns record given by vercel. This basically tells the whole internet that "Hey, hostinger isn't the boss of this domain anymore, go ask Vercel where the website is." So it doesn't host the code itself, it just points to the "manager" (Vercel) who knows where the code is living. This is pro customer as customer is having complete freedom on which service to use for deploying the code .</p>
<p>CNAME: This is the record that gives the owner the option to add aliases, like multiple subdomains can be added on a single domain. So it gives the customer this ability to put different different names and they all will be internally pointing to the server having code of domain that is hosted on the server, so no matter which name is hit on the domain name internally the domain inside which the CNAME is given, only that domain will open up.</p>
<p>MX record: these records are essential for receiving the mails that are linked to a particular domain. This is best used for the case when we have Professional emails that don’t end with @gmail.com or @zohomail etc instead they end with the domain name, example the domain <a target="_blank" href="http://gaurangpods.com">gaurangpods.com</a> has an official mail as <a target="_blank" href="mailto:consultant@gaurangpods.com">consultant@gaurangpods.com</a>, so in order to receive mails at this mail, we will have to update the MX records at the DNS records section where we have purchased the domain for our website.</p>
<p><strong>TXT record:</strong> TXT record is a type of DNS record that is used to store extra information about a domain. This information is mostly meant for verification and security purposes rather than for directly opening a website. For example, when you want to connect services like Google Search Console, email providers, or any third-party tool with your domain, they often ask you to add a TXT record. By doing this, you are basically proving that you are the real owner of the domain.</p>
<p>TXT records are also used for email security. Things like SPF, DKIM, and DMARC are added as TXT records to tell other mail servers that emails coming from your domain are genuine and allowed. So when an email is sent from your domain, the receiving server checks these TXT records to verify whether the email should be trusted or not. In simple words, TXT records act like an ID proof for your domain on the internet.</p>
<p><strong>How all DNS records work together for one website:</strong></p>
<p>For a single website, multiple DNS records work together, each solving a different problem. When a user types your website name in the browser, the first thing that happens is that the browser checks the NS record to know which name server is responsible for your domain. That name server is the one that has all the correct DNS information for your website.</p>
<p>Once the correct name server is found, it then looks at the A record or AAAA record to find the actual IP address where your website is hosted. If your domain is using aliases or subdomains, the CNAME record helps in pointing those names to the main domain without needing separate IP addresses. If someone is trying to send an email to your domain, the MX record tells the internet which mail server should receive those emails. At the same time, TXT records sit in the background to help verify domain ownership and ensure that emails and services linked to the domain are trusted.</p>
<p>So instead of thinking of DNS as a single setting, it is better to think of it as a small system where each record has a specific role. Together, they make sure that your website opens correctly, your emails get delivered properly, and your domain stays secure and verified on the internet.</p>
]]></content:encoded></item></channel></rss>