<?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[Ashish Dev's Journal]]></title><description><![CDATA[Ashish Dev's Journal]]></description><link>https://blog.ashishkumarsaini.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 13:38:47 GMT</lastBuildDate><atom:link href="https://blog.ashishkumarsaini.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[String Polyfills and Common Interview Questions in JavaScript]]></title><description><![CDATA[In Javascript, strings are used everywhere, but many developers do not know how they actually work behind the scenes.
When you call a method like .toUpperCase() on a string primitive, JavaScript creat]]></description><link>https://blog.ashishkumarsaini.dev/string-polyfills-and-common-interview-questions</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/string-polyfills-and-common-interview-questions</guid><category><![CDATA[js strings]]></category><category><![CDATA[js-polyfills]]></category><category><![CDATA[stringpolyfills]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Tue, 21 Apr 2026 21:34:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/9bab08a8-273d-4a05-8b2b-3580a9c7172c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Javascript, strings are used everywhere, but many developers do not know how they actually work behind the scenes.</p>
<p>When you call a method like <code>.toUpperCase()</code> on a string primitive, JavaScript creates a temporary wrapper object (using the <code>String</code> constructor) so the method can be executed. Once the operation is done, that object is immediately discarded, and the result is returned as a primitive.</p>
<h2>What Are String Methods?</h2>
<p>String methods are the built-in functions that are used to manipulate and update the string.</p>
<p>Here are some of the string methods:</p>
<ul>
<li><p><code>toUpperCase()</code></p>
</li>
<li><p><code>toLowerCase()</code></p>
</li>
<li><p><code>slice()</code></p>
</li>
<li><p><code>substring()</code></p>
</li>
<li><p><code>includes()</code></p>
</li>
<li><p><code>split()</code></p>
</li>
<li><p><code>trim()</code></p>
</li>
</ul>
<p>These methods don’t modify the original string (because strings are immutable). Instead, they return a new string.</p>
<h2>How string method work internally?</h2>
<p>Let's take an example <code>toUpperCase</code> and understand how it works.</p>
<p>When you call <code>string.toUpperCase()</code></p>
<pre><code class="language-javascript">const str = 'Hello';

str.toUpperCase();
</code></pre>
<ol>
<li><p>Javascript iterate over each character</p>
</li>
<li><p>Convert that character into uppercase</p>
</li>
<li><p>Build a new string</p>
</li>
</ol>
<blockquote>
<p>Think of execution like this</p>
<p>Input String → Process Each Character → Apply Logic → Return New String</p>
</blockquote>
<h2>What are polyfills?</h2>
<p>Polyfills are a custom implementation of the built-in functions. It is mostly used to create the same functionality that built-in functions offer.</p>
<h3>Why Developers Write Polyfills?</h3>
<ul>
<li><p>Provide support for new methods in older browsers</p>
</li>
<li><p>Understanding internal logic</p>
</li>
<li><p>To practice the built-in methods logic by creating them of their own</p>
</li>
</ul>
<h3>Polyfill Examples</h3>
<p>Let's implement some polyfills for string methods</p>
<ol>
<li><p><strong>string.toLowerCase()</strong><br />Here I will be writing a custom polyfill for toLowerCase.</p>
<pre><code class="language-javascript">if(!String.prototype.toLowerCase){
    String.prototype.toLowerCase = function () {
        let result = "";

        // this refer to string on which method is called
        for (let char of this) {
            const code = char.charCodeAt(0);

            // a-z → A-Z
            if (code &gt;= 97 &amp;&amp; code &lt;= 122) {
                result += String.fromCharCode(code - 32);
            } else {
                result += char;
            }
        }

        return result;
    };
}
</code></pre>
<p>This will only work if the browser doesn't support <code>string.toLowerCase</code>, it will use the polyfill <code>toLowerCase</code></p>
</li>
<li><p><code>string.includes</code></p>
<pre><code class="language-javascript">if(!String.prototype.includes){
    String.prototype.myIncludes = function(searchString) {
        return this.indexOf(searchString) !== -1;
    };
}
</code></pre>
</li>
</ol>
<h2>Common String Interview Questions</h2>
<p>If you're preparing for interviews, these are must-practice:</p>
<ol>
<li><p>Reverse a String function without using built-in methods<br />Logic: Iterate over the string and append the new string with each character in an order so that the last character comes first.</p>
</li>
<li><p>Check Palindrome<br />Logic: Reverse and create a new string. Check if both strings are equal or not.</p>
</li>
<li><p>Count Characters<br />Logic: Use a "Map" or an object to store counts as you iterate through the string.</p>
</li>
<li><p>Anagram Detection: Do two strings contain the same characters?<br />Logic: Sort both strings and compare them.</p>
</li>
</ol>
<h2>Why Understanding Built-in Behavior Matters</h2>
<p>Most developers stop at using methods. But in an interview, the interviewer tests:</p>
<ul>
<li><p>How things work internally</p>
</li>
<li><p>Your problem-solving ability</p>
</li>
<li><p>Your understanding of edge cases</p>
</li>
</ul>
<p>Understanding internals helps you in writing better code, debugging faster, and performing well in interviews.</p>
<p>Example questions:</p>
<ol>
<li><p>How does slice() differ from substring()?</p>
</li>
<li><p>Why are strings immutable?</p>
</li>
<li><p>How would you optimize a string search?</p>
</li>
</ol>
<h2>Conclusion</h2>
<p>If you want to stand out as a developer:</p>
<p>Don’t just use methods — understand them, practice writing polyfills, and solve real interview problems.</p>
<p>That’s where real growth happens.</p>
<p>Follow the series to learn more about Javascript.</p>
]]></content:encoded></item><item><title><![CDATA[Map and Set in JavaScript]]></title><description><![CDATA[While working in Javascript, you have mostly worked with objects and arrays. But there are some limitations when used for large data or applying complex operations.
Problems in Objects

Object must ha]]></description><link>https://blog.ashishkumarsaini.dev/map-and-set-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/map-and-set-in-javascript</guid><category><![CDATA[map in js]]></category><category><![CDATA[set in js]]></category><category><![CDATA[map and set in javascript]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Tue, 21 Apr 2026 19:21:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/32af7866-67cb-4028-936b-d40e94dd3d44.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>While working in Javascript, you have mostly worked with objects and arrays. But there are some limitations when used for large data or applying complex operations.</p>
<h2>Problems in Objects</h2>
<ul>
<li><p>Object must have a key as a string. If you use a number, it will automatically be used as a string.</p>
</li>
<li><p>Objects inherit properties from their prototypes. For example: Object.<em>keys</em> is a predefined property that should not be used as a key. This may lead to unexpected bugs.</p>
</li>
<li><p>You cannot directly iterate over the object's values/keys. You have to use object.keys() or object.entries() to do iteration.</p>
</li>
<li><p>Order of insertion is not maintained.</p>
</li>
</ul>
<h2>Problems with Arrays</h2>
<ul>
<li><p>Removing a specific value from an array requires another iteration to find the position of the value in the array.</p>
</li>
<li><p>The array might have duplicate values. In some cases the developer doesn't want to insert duplicate values into the array. To achieve the same, they need to iterate over the whole array to check if the value already exists.</p>
</li>
</ul>
<h2>Understanding Map and Set</h2>
<h3>What is Map?</h3>
<p>Map is a built-in datatype in Javascript. It is used to store key-value pairs. It is like an object with some extra powers.</p>
<ol>
<li><p>Key can be of any type (string, number, array...)</p>
</li>
<li><p>Key should be unique</p>
</li>
<li><p>Maintain insertion order. This means if you iterate over a map, it will be the same order in which they are inserted.</p>
</li>
</ol>
<p><strong>Map Methods:</strong></p>
<ol>
<li><p>Insert value,<br />To insert a value in map, use <code>map.set(key, value)</code>.<br />Examples:</p>
<pre><code class="language-javascript">const employee = new Map();

employee.set("id", 101);
employee.set("name", "Rahul");
</code></pre>
</li>
<li><p>Get a value<br />To get a value, use <code>map.get(key)</code></p>
<pre><code class="language-javascript">const employee = new Map();

employee.set("id", 101);
employee.set("name", "Rahul");

const employeeName = employee('name');

console.log(employeeName); // Rahul
</code></pre>
</li>
<li><p>Check if value exisits, use <code>map.has(key)</code>, return boolean state.</p>
<pre><code class="language-javascript">const employee = new Map();

employee.set("id", 101);
employee.set("name", "Rahul");

console.log(employee.has('name'));   // true
console.log(employee.has('salary')); // false
</code></pre>
</li>
<li><p>Delete a value, use <code>map.delete(key)</code></p>
<pre><code class="language-javascript">const employee = new Map();

employee.set("id", 101);
employee.set("name", "Rahul");

employee.delete("id");

console.log(employee.has("id")); // false
</code></pre>
</li>
</ol>
<h2>What is Set?</h2>
<p>A set is also a built-in datatype in Javascript used to store unique values. It is more like an array, but with the power of uniqueness.</p>
<ul>
<li><p>Store unique values</p>
</li>
<li><p>Store only values, not keys</p>
</li>
<li><p>Maintain insertion order</p>
</li>
</ul>
<p><strong>Set methods:</strong></p>
<ol>
<li><p>Insert a value, use <code>set.add(value)</code>.</p>
<pre><code class="language-javascript">const set = new Set();

set.add(42);
set.add(42);
set.add(13);

for (const item of set) {
  console.log(item);
  // Expected output: 42
  // Expected output: 13
}
</code></pre>
</li>
<li><p>Check if the value exists, use <code>set.has(key)</code>, return a boolean state.</p>
<pre><code class="language-javascript">const set = new Set();

set.add(42);
set.add(13);

console.log(set.has(42));   // true
console.log(set.has(40)); // false
</code></pre>
</li>
<li><p>Delete a value, use <code>set.delete(value)</code>, returns a boolean value indicating if the value is deleted successfully.</p>
<pre><code class="language-javascript">const set = new Set();

set.add(42);
set.add(13);

console.log(set.delete(42)); // true
console.log(set.delete(40)); // false

console.log(set) // Set(1) {13}
</code></pre>
</li>
</ol>
<p>Both Map and Set have other methods like <code>values</code>, <code>entries</code>, <code>size</code> and <code>forEach</code> for iteration. Here I have explained to you the necessary methods for insertion and deletion of values.</p>
<h2>Comparison between Map and Object</h2>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Map</th>
<th>Object</th>
</tr>
</thead>
<tbody><tr>
<td>Key Types</td>
<td>Any Type</td>
<td>String only</td>
</tr>
<tr>
<td>Order of values</td>
<td>Maintained</td>
<td>Not guaranteed</td>
</tr>
<tr>
<td>Performance</td>
<td>Optimized for insertion and removal</td>
<td>No optimization</td>
</tr>
<tr>
<td>Iteration</td>
<td>Has in-built methods</td>
<td>Need other methods</td>
</tr>
</tbody></table>
<h2>Comparison between Set and Array</h2>
<table>
<thead>
<tr>
<th>Features</th>
<th>Set</th>
<th>Array</th>
</tr>
</thead>
<tbody><tr>
<td>Unique Values</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td>Maintained Order</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>Search</td>
<td>Faster with <code>has</code> method</td>
<td>Slower with <code>includes</code> method</td>
</tr>
</tbody></table>
<h2>When to Use Map?</h2>
<p>Use Map when:</p>
<ul>
<li><p>You need key-value storage</p>
</li>
<li><p>Keys are not just strings</p>
</li>
<li><p>Frequent add/remove operations</p>
</li>
<li><p>You care about insertion order</p>
</li>
</ul>
<p>Example:</p>
<ul>
<li><p>Caching data</p>
</li>
<li><p>Storing user sessions</p>
</li>
<li><p>Mapping objects to values</p>
</li>
</ul>
<h2>When to Use Set?</h2>
<p>Use Set when:</p>
<ul>
<li><p>You need <strong>unique values</strong></p>
</li>
<li><p>You want to <strong>remove duplicates</strong></p>
</li>
<li><p>Fast lookup is required</p>
</li>
</ul>
<p>Example:</p>
<ul>
<li><p>Unique tags</p>
</li>
<li><p>Removing duplicate IDs</p>
</li>
<li><p>Tracking visited items</p>
</li>
</ul>
<h2>Conclusion</h2>
<ul>
<li><p>Use Map when you need a better version of objects</p>
</li>
<li><p>Use Set when you need uniqueness without extra logic</p>
</li>
<li><p>Avoid forcing everything into Objects &amp; Arrays</p>
</li>
</ul>
<p>Follow Javascript series for more updates 🙂</p>
]]></content:encoded></item><item><title><![CDATA[Template Literals in JavaScript]]></title><description><![CDATA[Before ES6, JavaScript developers used string concatenation with the + operator
const name = "Vishal";

const age = 30;

const message = "My name is " + name + " and I am " + age + " years old.";

con]]></description><link>https://blog.ashishkumarsaini.dev/template-literals-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/template-literals-in-javascript</guid><category><![CDATA[#javascript-template-literals]]></category><category><![CDATA[template literals]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[string interpolation]]></category><category><![CDATA[js strings]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Mon, 20 Apr 2026 20:39:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/e3a23311-00b1-42b2-a179-09b4d039146f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before ES6, JavaScript developers used string concatenation with the + operator</p>
<pre><code class="language-javascript">const name = "Vishal";

const age = 30;

const message = "My name is " + name + " and I am " + age + " years old.";

console.log(message); // My name is Vishal and I am 30 years old.
</code></pre>
<p>But there are various difficulties or problems developers face while performing string concatenations:</p>
<ul>
<li><p>Hard to read strings</p>
</li>
<li><p>String gets too long</p>
</li>
<li><p>Cluttered code</p>
</li>
<li><p>Difficulty in managing dynamic values</p>
</li>
</ul>
<p>As the application grows, it becomes messier and increases the risk of errors.</p>
<p>After ES6, this has been resolved using Template Literals.</p>
<h2>What Are Template Literals?</h2>
<p>Template literals are the modern way to work with string concatenations in JavaScript. They use backticks (<code>``</code> ) instead of quotes (<code>''</code>/<code>""</code>).</p>
<p>Example:</p>
<pre><code class="language-javascript">const name = "Vishal";

const age = 30;

const message = `My name is \({name} and I am \){age} years old.`;

console.log(message); // My name is Vishal and I am 30 years old.
</code></pre>
<p>Use of template literals instead of quotes allows:</p>
<ul>
<li><p>multi-line strings<br />Example:</p>
<pre><code class="language-javascript">const message = `This is a 
                 string to show template literals
                 multiline.`;

console.log(message);
// This is a string to show template literals multiline.
</code></pre>
</li>
<li><p>Embedding variables or operations. Instead of using the + operator, you can inject a variable using ${}.<br />Example:</p>
<pre><code class="language-javascript">const number = 3;
const message = `Square of \({number} is \){ number ** 2 }.`;

console.log(message); // Square of 3 is 9.
</code></pre>
</li>
</ul>
<h2>Benefits of using Template Literals</h2>
<ul>
<li><p>Cleaner and more readable</p>
</li>
<li><p>No need for +</p>
</li>
<li><p>Easier to maintain</p>
</li>
</ul>
<h2>Before vs After (Comparison)</h2>
<table>
<thead>
<tr>
<th>Before (Old way)</th>
<th>After (New Way)</th>
</tr>
</thead>
<tbody><tr>
<td>Concatenation</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>❌ Old Way (Concatenation) const product = "Laptop"; const price = 50000;</p>
<p>const text = "The price of " + product + " is Rs. " + price + "."; ✅ New Way (Template Literals) const text = <code>The price of \({product} is Rs. \){price}.</code>;</p>
<p>👉 Clearly more readable and modern!</p>
<p>📄 Multi-line Strings Made Easy</p>
<p>Before template literals, multi-line strings were awkward:</p>
<p>❌ Old Way const text = "This is line one.\n" + "This is line two."; ✅ Template Literals const text = <code>This is line one. This is line two.</code>;</p>
<p>🎯 No special characters, no concatenation—just write naturally.</p>
<h2>Real-World Use Cases</h2>
<ol>
<li><p>Dynamic Messages const user = "Ashish"; console.log(<code>Welcome back, ${user}!</code>);</p>
</li>
<li><p>HTML Templates (Very Common) const title = "JavaScript Basics";</p>
<pre><code class="language-javascript">const html = `${title}`;
</code></pre>
</li>
<li><p>Logging and Debugging</p>
<pre><code class="language-javascript">const count = 5;

console.log(`Total items: ${count}`); 
</code></pre>
</li>
<li><p>Expressions Inside Strings: You can even run JavaScript inside ${}:</p>
<pre><code class="language-javascript">const a = 5;
const b = 10;

console.log(Sum is ${a + b});
</code></pre>
</li>
</ol>
<h2>Why Template Literals Matter?</h2>
<ul>
<li><p>Improves code readability</p>
</li>
<li><p>Reduces syntax noise</p>
</li>
<li><p>Makes dynamic strings easy to write</p>
</li>
<li><p>Widely used in modern frameworks (React, Node.js)</p>
</li>
</ul>
<h2>Final Thoughts</h2>
<p>Template literals are one of the simplest yet most powerful features in modern JavaScript.</p>
<p>Once you start using them: 👉 You’ll rarely go back to + concatenation.</p>
<p>Check out more blogs and follow our Javascript series to learn more.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Object-Oriented Programming in Javascript]]></title><description><![CDATA[Object-oriented programming is a concept of writing code in which we organize everything around objects.
An object is a combination of

Properties

Methods


Instead of writing separate variables and ]]></description><link>https://blog.ashishkumarsaini.dev/understanding-object-oriented-programming-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/understanding-object-oriented-programming-in-javascript</guid><category><![CDATA[JS OOPS]]></category><category><![CDATA[OOP In JavaScript]]></category><category><![CDATA[js]]></category><category><![CDATA[classes in javascript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 18 Apr 2026 19:04:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/91bfd74e-8923-4d6d-ac4b-24ab93af7d6d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Object-oriented programming is a concept of writing code in which we organize everything around objects.</p>
<p>An object is a combination of</p>
<ol>
<li><p>Properties</p>
</li>
<li><p>Methods</p>
</li>
</ol>
<p>Instead of writing separate variables and functions, we bundle them together.</p>
<h2>Real-World Analogy: Blueprint → Objects</h2>
<p>Let’s understand object-oriented programming with a simple example:</p>
<p>Imagine you are a car manufacturer.</p>
<p>You first create a <strong>blueprint</strong> (design)</p>
<ul>
<li>Then you use that blueprint to create multiple cars</li>
</ul>
<p>👉 In JavaScript:</p>
<ul>
<li><p>Blueprint = <strong>Class</strong></p>
</li>
<li><p>Car = <strong>Object (Instance)</strong></p>
</li>
</ul>
<p>So instead of rewriting code again and again, we define a class once and reuse it.</p>
<hr />
<h2>🧱 What is a Class in JavaScript?</h2>
<p>A <strong>class</strong> is a blueprint used to create objects.</p>
<p>It defines:</p>
<ul>
<li><p>What properties an object will have</p>
</li>
<li><p>What actions it can perform</p>
</li>
</ul>
<h3>Example:</h3>
<pre><code class="language-javascript">class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log(`Hi, my name is ${this.name}`);
  }
}
</code></pre>
<hr />
<h2>🧪 Creating Objects (Instances)</h2>
<p>We use the <code>new</code> keyword to create objects from a class.</p>
<pre><code class="language-javascript">const person1 = new Person("Ashish", 25);
const person2 = new Person("Rahul", 30);

person1.greet(); // Hi, my name is Ashish
person2.greet(); // Hi, my name is Rahul
</code></pre>
<p>👉 Each object:</p>
<ul>
<li><p>Has its own data</p>
</li>
<li><p>Shares the same structure and methods</p>
</li>
</ul>
<hr />
<h2>⚙️ Understanding the Constructor</h2>
<p>The <strong>constructor</strong> is a special method inside a class.</p>
<h3>Key Points:</h3>
<ul>
<li><p>It runs automatically when an object is created</p>
</li>
<li><p>It initializes object properties</p>
</li>
</ul>
<pre><code class="language-javascript">constructor(name, age) {
  this.name = name;
  this.age = age;
}
</code></pre>
<p>👉 <code>this</code> refers to the current object.</p>
<hr />
<h2>🔧 Methods Inside a Class</h2>
<p>Methods define what an object can do.</p>
<pre><code class="language-javascript">greet() {
  console.log(`Hi, my name is ${this.name}`);
}
</code></pre>
<p>👉 Methods are shared across all instances (memory efficient).</p>
<hr />
<h2>🔒 Basic Idea of Encapsulation</h2>
<p>Encapsulation means:</p>
<p>👉 <strong>Keeping data and methods together and controlling access</strong></p>
<h3>Real-world example:</h3>
<p>Think of a car:</p>
<ul>
<li><p>You don’t directly control the engine</p>
</li>
<li><p>You use steering, brakes, accelerator</p>
</li>
</ul>
<p>Same in code:</p>
<ul>
<li><p>Internal data is hidden</p>
</li>
<li><p>Access is controlled via methods</p>
</li>
</ul>
<h3>Simple Example:</h3>
<pre><code class="language-javascript">class BankAccount {
  constructor(balance) {
    this.balance = balance;
  }

  deposit(amount) {
    this.balance += amount;
  }

  getBalance() {
    return this.balance;
  }
}
</code></pre>
<p>👉 We interact using methods instead of directly modifying data.</p>
<hr />
<h2>♻️ Why Use OOP?</h2>
<p>OOP helps you write better code:</p>
<ul>
<li><p>✅ Reusable (write once, use many times)</p>
</li>
<li><p>✅ Organized (structured code)</p>
</li>
<li><p>✅ Scalable (easy to expand)</p>
</li>
<li><p>✅ Maintainable (easy to debug and update)</p>
</li>
</ul>
<hr />
<h2>🧠 Class vs Object (Quick Comparison)</h2>
<table>
<thead>
<tr>
<th>Concept</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td>Class</td>
<td>Blueprint</td>
</tr>
<tr>
<td>Object</td>
<td>Real instance created from class</td>
</tr>
</tbody></table>
<hr />
<h2>🎯 Assignment</h2>
<p>Try this yourself 👇</p>
<h3>Task:</h3>
<p>Create a <code>Student</code> class with:</p>
<ul>
<li><p>Properties: <code>name</code>, <code>age</code></p>
</li>
<li><p>Method: <code>printDetails()</code></p>
</li>
</ul>
<h3>Example Solution:</h3>
<pre><code class="language-javascript">class Student {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  printDetails() {
    console.log(`Name: \({this.name}, Age: \){this.age}`);
  }
}

const student1 = new Student("Aman", 20);
const student2 = new Student("Neha", 22);

student1.printDetails();
student2.printDetails();
</code></pre>
<hr />
<h2>🧩 Visual Understanding (Conceptual)</h2>
<pre><code class="language-plaintext">Class (Blueprint)
      ↓
Create using new
      ↓
Objects (Instances)
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">Car (Class)
  ↓
car1, car2, car3 (Objects)
</code></pre>
<hr />
<h2>📌 Common Mistakes Beginners Make</h2>
<p>❌ Forgetting <code>new</code> keyword ❌ Not using <code>this</code> properly ❌ Thinking each object has separate methods (they are shared) ❌ Confusing class with object</p>
<hr />
<h2>🧠 Final Thoughts</h2>
<p>OOP is not just a concept—it’s a <strong>way of thinking</strong>.</p>
<p>Once you understand:</p>
<ul>
<li><p>Class</p>
</li>
<li><p>Object</p>
</li>
<li><p>Constructor</p>
</li>
<li><p>Methods</p>
</li>
</ul>
<p>You can build real-world applications much more easily 🚀</p>
<hr />
<p>Happy Coding! 💻</p>
]]></content:encoded></item><item><title><![CDATA[Array Flatten in Javascript]]></title><description><![CDATA[You have read in the previous blog on datatypes that an array is a non-primitive data type that can contain various data types.
But have you ever wondered what would happen if an array contained anoth]]></description><link>https://blog.ashishkumarsaini.dev/array-flatten-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/array-flatten-in-javascript</guid><category><![CDATA[flatten array]]></category><category><![CDATA[array js]]></category><category><![CDATA[array method js]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Thu, 26 Mar 2026 19:29:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/638f3690-8db6-46aa-a628-326d881b16a2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have read in the previous blog on datatypes that an array is a non-primitive data type that can contain various data types.</p>
<p>But have you ever wondered what would happen if an array contained another array? How are we going to handle this?</p>
<p>Understanding nested arrays and handling operations on them is an important skill, especially for problem-solving and is usually asked in interviews as well.</p>
<h2>What are nested arrays?</h2>
<p>If an array contains a nested array, it is called a nested array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const nestedArray = [1, 2, 3, [4, 5, 6], 7, [8, [9, 10]]];
</code></pre>
<p>The above example might be confusing to see. Let me break it down to see multiple array properly.</p>
<pre><code class="language-javascript">const nestedArray = [
    1,
    2,
    3,
    [4, 5, 6],
    7,
    [
        8, 
        [9, 10]
    ]
]
</code></pre>
<p>Now the values on each index can be seen clearly.</p>
<p>Values with respective index:</p>
<ul>
<li><p><code>0</code> -&gt; <code>1</code> (<code>number</code>)</p>
</li>
<li><p><code>1</code> -&gt; <code>2</code> (<code>number</code>)</p>
</li>
<li><p><code>2</code> -&gt; <code>3</code> (<code>number</code>)</p>
</li>
<li><p><code>3</code> -&gt; <code>[4, 5, 6]</code> (<code>array</code>)</p>
</li>
<li><p><code>4</code> -&gt; <code>7</code> (<code>number</code>)</p>
</li>
<li><p><code>5</code> -&gt; <code>[8, [9, 10]]</code> (<code>nested array</code>)</p>
</li>
</ul>
<h2>Why is flattening an array used?</h2>
<p>Flattening an array means converting a multidimensional array to a single-dimensional array.</p>
<ul>
<li><p>Extracting values from all nested arrays</p>
</li>
<li><p>Arrange them in a single array</p>
</li>
</ul>
<p>This is an important concept needed when:</p>
<ol>
<li><p>Easier data processing</p>
</li>
<li><p>Useful in APIs and transforming data</p>
</li>
<li><p>Common in real-world scenarios (e.g., comments, categories with products)</p>
</li>
</ol>
<p>Example:</p>
<pre><code class="language-javascript">const categories = [
    ["p1", "p2", "p3"],
    ["p4", "p5"]
];
</code></pre>
<p>After flattening:</p>
<pre><code class="language-javascript">const products = ["p1", "p2", "p3", "p4", "p5"];
</code></pre>
<h2>Different approaches to flatten arrays</h2>
<p>There are multiple ways to flatten an array:</p>
<h3>Using in-build flat() method</h3>
<p>An array has an in-built method <code>flat()</code>. This is the most common and simple approach.</p>
<pre><code class="language-javascript">const array = [1, 2, [3, 4], [5, 6]];

const flatArr = arr.flat(Infinity);

console.log(flatArr); // [1, 2, 3, 4, 5, 6, 7]
</code></pre>
<h3>Using Recursion</h3>
<p>Recursion is a way to call the same function repeatedly.</p>
<pre><code class="language-javascript">const array = [1, 2, [3, 4], [5, 6]];

function flattenArray(arr) {
    let result = [];

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

    return result; 
};

console.log(flattenArray([1, [2, [3, 4], 5]])); // [1, 2, 3, 4, 5]
</code></pre>
<h3>Using reduce()</h3>
<pre><code class="language-javascript">const array = [1, 2, [3, 4], [5, 6]];

const flattenArray = (arr) =&gt; {
    return arr.reduce((acc, item) =&gt; {
        if (Array.isArray(item)) {
            return acc.concat(flattenArray(item));
        }
        
        return acc.concat(item); 
    }, []); 
};

console.log(flattenArray([1, [2, [3, 4]]])); // [1, 2, 3, 4, 5]
</code></pre>
<h2>Common Interview Scenarios</h2>
<p>You may be asked:</p>
<ol>
<li><p>Flatten only one level arr.flat(1);</p>
</li>
<li><p>Flatten up to depth n</p>
</li>
<li><p>Don’t use built-in methods. Use recursion or a stack approach.</p>
</li>
</ol>
<p>Try to practice in any Javascript code editor.</p>
<h2>Conclusion</h2>
<p>Flattening arrays is a fundamental concept in JavaScript that helps you:</p>
<ul>
<li><p>Work with complex data structures</p>
</li>
<li><p>Improve problem-solving skills</p>
</li>
<li><p>Prepare for coding interviews</p>
</li>
</ul>
<p>Start with <code>flat()</code> for simplicity, but master recursion for interviews.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Object in JS]]></title><description><![CDATA[When you start learning Javascript, array helps you to store the list of data. But is there a possibility of storing structured information like details of an employee?

name

age

salary


That’s whe]]></description><link>https://blog.ashishkumarsaini.dev/understanding-object-in-js</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/understanding-object-in-js</guid><category><![CDATA[JS Objects]]></category><category><![CDATA[Objects]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Mon, 23 Mar 2026 04:49:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/4eed3e81-4cd9-4e0e-971b-6db3668b0272.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When you start learning Javascript, array helps you to store the list of data. But is there a possibility of storing structured information like details of an employee?</p>
<ol>
<li><p>name</p>
</li>
<li><p>age</p>
</li>
<li><p>salary</p>
</li>
</ol>
<p>That’s where objects come in.</p>
<h2>What Are Objects?</h2>
<p>An object is a collection of data stored in key-value pairs.</p>
<p>Think of it like a real-world entity.</p>
<p>Example: A person has:</p>
<ul>
<li><p>name</p>
</li>
<li><p>age</p>
</li>
<li><p>city</p>
</li>
</ul>
<p>In JavaScript, we represent this using an object:</p>
<pre><code class="language-javascript">const person = {
  name: "Ashish",
  age: 25,
  city: "Delhi"
};
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>name</code>, <code>age</code>, <code>city</code> are keys</p>
</li>
<li><p><code>"Ashish"</code>, <code>25</code>, <code>"Delhi"</code> are their values</p>
</li>
</ul>
<h2>Why Do We Need Objects?</h2>
<p>Arrays store data using indexes:</p>
<pre><code class="language-javascript">const user = ["Ashish", 25, "Delhi"];
</code></pre>
<p>But this is confusing. What if I don't know on which index the value actually exists?</p>
<p>Objects solve this by using keys:</p>
<pre><code class="language-javascript">person.name
</code></pre>
<p>You can directly access the value by using its key name.</p>
<h2>Creating Objects</h2>
<p>You can create an object using curly braces <code>{}</code>:</p>
<pre><code class="language-javascript">const student = {
  name: "John",
  age: 20,
  course: "BCA"
};
</code></pre>
<h2>Accessing Properties</h2>
<h3>1. Dot Notation</h3>
<p>The object values can be accessed using . (<code>dot</code>) notation:</p>
<pre><code class="language-javascript">console.log(student.name); // John
</code></pre>
<h3>2. Bracket Notation</h3>
<p>The object values can also be accessed using [] (bracket) notation. Inside the bracket, the key name will be specified as a string.</p>
<pre><code class="language-javascript">console.log(student["age"]); // 20
</code></pre>
<h2>Dot notation vs Bracket notation</h2>
<ul>
<li><p>Dot notation → simple and common</p>
</li>
<li><p>Bracket notation → useful when the key is dynamic</p>
</li>
</ul>
<pre><code class="language-javascript">const key = "course";
console.log(student.course) // BCA
console.log(student[key]);  // BCA
</code></pre>
<h2>Updating Object Properties</h2>
<p>Updating object value is simple and uses only dots. Just specify the . and keyname with the assignment operator and value</p>
<pre><code class="language-javascript">student.age = 21;
console.log(student.age); // 21
</code></pre>
<p>Breakdown:</p>
<ul>
<li><p><code>age</code> -&gt; key</p>
</li>
<li><p><code>=</code> -&gt; assignment operator</p>
</li>
<li><p><code>21</code> -&gt; value</p>
</li>
</ul>
<h2>Adding New Properties</h2>
<p>New properties can also be added using the same approach for updating the object.</p>
<pre><code class="language-javascript">student.city = "Mumbai";

console.log(student);
</code></pre>
<p>If the city doesn't exisits in object, it will add new property. Otherwise update exisiting.</p>
<h2>Deleting Properties</h2>
<p>Object properties can be deleted using delete keyword following with object property name.</p>
<pre><code class="language-javascript">delete student.course;

console.log(student);
</code></pre>
<h2>Looping Through Object Keys</h2>
<p>To loop through an object, we use <code>for...in</code>:</p>
<pre><code class="language-javascript">for (let key in student) {
  console.log(key, student[key]);
}

// Output:
// name Rahul
// age 21
// city Mumbai
</code></pre>
<h2>Array vs Object (Simple Comparison)</h2>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Array</th>
<th>Object</th>
</tr>
</thead>
<tbody><tr>
<td>Structure</td>
<td>Ordered list</td>
<td>Key-value pairs</td>
</tr>
<tr>
<td>Access</td>
<td>Index (0, 1, 2)</td>
<td>Key (name, age)</td>
</tr>
<tr>
<td>Use Case</td>
<td>List of items</td>
<td>Structured data</td>
</tr>
<tr>
<td>Example</td>
<td><code>["a", "b"]</code></td>
<td><code>{ name: "Ashish" }</code></td>
</tr>
</tbody></table>
<h2>Visual Representation (Mental Model)</h2>
<p>Think of an object like a labeled box:</p>
<pre><code class="language-plaintext">person = {
  name → "Ashish"
  age  → 25
  city → "Delhi"
}
</code></pre>
<p>Each value is stored with a label (key).</p>
<h2>Assignment (Practice)</h2>
<p>Create a student object and perform the following:</p>
<ol>
<li><p>Create an object named "employee"</p>
</li>
<li><p>Add name, id, and salary fields</p>
</li>
<li><p>Update the salary of the employee object.</p>
</li>
<li><p>Loop through the employee object to print all properties.</p>
</li>
</ol>
<blockquote>
<p>Practice by converting real-life things (car, phone, user profile) into objects.</p>
</blockquote>
<h2>Conclusion</h2>
<p>Objects are one of the most important concepts in JavaScript.</p>
<p>They help you:</p>
<ul>
<li><p>Organize data in key-value format</p>
</li>
<li><p>Make code more readable</p>
</li>
<li><p>Represent real-world entities</p>
</li>
</ul>
<p>Once you’re comfortable with objects, you’ll find it much easier to work with APIs, JSON data, and real applications.  </p>
<p>Follow and learn more about Javascript!</p>
]]></content:encoded></item><item><title><![CDATA[Arrow Functions in JavaScript (Beginner-Friendly Guide)]]></title><description><![CDATA[Why arrow functions?
Before arrow functions, writing a function felt like writing duplicate code again and again.
Function Before Arrow Functions:
function add(a, b) {
  return a + b;
}

Arrow functio]]></description><link>https://blog.ashishkumarsaini.dev/arrow-functions-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/arrow-functions-in-javascript</guid><category><![CDATA[js-arrow]]></category><category><![CDATA[js-arrow-functions]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Mon, 23 Mar 2026 04:16:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/df9b52f8-3678-415d-8585-0dac364068c0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Why arrow functions?</h2>
<p>Before arrow functions, writing a function felt like writing duplicate code again and again.</p>
<p>Function Before Arrow Functions:</p>
<pre><code class="language-javascript">function add(a, b) {
  return a + b;
}
</code></pre>
<p>Arrow function syntax:</p>
<pre><code class="language-javascript">const add = (a, b) =&gt; a + b;
</code></pre>
<p>Benefits of using arrow functions:</p>
<ol>
<li><p>Clear Syntax</p>
</li>
<li><p>Easier to read</p>
</li>
<li><p>Less Code than normal functions</p>
</li>
</ol>
<p>That's why you can see arrow functions are widely used in modern Javascript.</p>
<h2>What Are Arrow Functions?</h2>
<p>Arrow functions were introduced in ES6 (ES2015) to make code easier and more readable. It is a shorter way of writing functions.</p>
<h3>Basic Arrow Function Syntax</h3>
<pre><code class="language-javascript">const functionName = (parameters) =&gt; {
    // write function logic here  
};
</code></pre>
<p>Example:</p>
<pre><code class="language-javascript">const greet = () =&gt; {
  console.log("Hello!");
};
</code></pre>
<h3>Arrow Function with One Parameter</h3>
<p>If there is only one parameter, you can skip the parentheses.</p>
<pre><code class="language-javascript">const square = num =&gt; {
  return num * num;
};
</code></pre>
<h3>Arrow Function with Multiple Parameters</h3>
<p>If there are <strong>multiple parameters</strong>, parentheses are required.</p>
<pre><code class="language-javascript">const add = (a, b) =&gt; {
  return a + b;
};
</code></pre>
<h2>Implicit Return vs Explicit Return</h2>
<h3>Explicit Return (using <code>return</code>)</h3>
<p>Explicit return in arrow functions means it uses the return keyword inside the function body to return the final result. It is used when the function's body requires multiple statements to calculate the result.</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; {
  return a * b;
};
</code></pre>
<h3>Implicit Return (no <code>return</code> keyword)</h3>
<p>The function result can also be returned without the return keyword by removing the function curly braces. This approach will only be applicable where the function will calculate the value in a single statement.</p>
<pre><code class="language-javascript">const multiply = (a, b) =&gt; a * b;
</code></pre>
<h2>Converting Normal Function → Arrow Function</h2>
<p>Normal Function:</p>
<pre><code class="language-javascript">function greet(name) {
  return "Hello " + name;
}
</code></pre>
<p>Arrow Function:</p>
<pre><code class="language-javascript">const greet = name =&gt; "Hello " + name;
</code></pre>
<h2>Arrow Function vs Normal Function</h2>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Normal Function</th>
<th>Arrow Function</th>
</tr>
</thead>
<tbody><tr>
<td>Syntax</td>
<td>Longer</td>
<td>Shorter</td>
</tr>
<tr>
<td><code>this</code></td>
<td>Own <code>this</code></td>
<td>Inherits <code>this</code></td>
</tr>
<tr>
<td>Use Case</td>
<td>General-purpose</td>
<td>Short functions, callbacks</td>
</tr>
</tbody></table>
<blockquote>
<p>For beginners: Use arrow functions for short and simple tasks</p>
</blockquote>
<h2>Simple Examples</h2>
<ul>
<li>Greeting</li>
</ul>
<pre><code class="language-javascript">const greet = name =&gt; "Hello " + name;
</code></pre>
<ul>
<li>Addition</li>
</ul>
<pre><code class="language-javascript">const add = (a, b) =&gt; a + b;
</code></pre>
<ul>
<li>Square</li>
</ul>
<pre><code class="language-javascript">const square = num =&gt; num * num;
</code></pre>
<p>Using an Arrow Function with <code>map()</code></p>
<pre><code class="language-javascript">const numbers = [1, 2, 3, 4];

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

console.log(squares); // [1, 4, 9, 16]
</code></pre>
<h2>Assignment</h2>
<p>Try these on your own 👇</p>
<ol>
<li><p>Write a normal function to calculate the square of a number</p>
</li>
<li><p>Rewrite it using an arrow function</p>
</li>
<li><p>Create an arrow function that checks if a number is even or odd</p>
</li>
<li><p>Use an arrow function inside <code>map()</code> on an array</p>
</li>
</ol>
<h2>Arrow Function Breakdown</h2>
<pre><code class="language-javascript">const add = (a, b) =&gt; a + b;
</code></pre>
<ul>
<li><p><code>const add</code> → function name</p>
</li>
<li><p><code>(a, b)</code> → parameters</p>
</li>
<li><p><code>=&gt;</code> → arrow syntax</p>
</li>
<li><p><code>a + b</code> → returned value</p>
</li>
</ul>
<h2>Conclusion</h2>
<ul>
<li><p>Arrow functions make your code.</p>
</li>
<li><p>Cleaner</p>
</li>
<li><p>Shorter</p>
</li>
<li><p>More modern</p>
</li>
</ul>
<p>Follow the series for more blogs!</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Function Declaration vs Function Expression: What’s the Difference?]]></title><description><![CDATA[While you start writing programs for real world problems, you might have notices that there are many actions which need to be perform multiple times. For that you might have write duplicate code at se]]></description><link>https://blog.ashishkumarsaini.dev/javascript-function</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/javascript-function</guid><category><![CDATA[js functions]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 21 Mar 2026 13:07:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/a22dc3df-d503-467f-b716-28b45d731478.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>While you start writing programs for real world problems, you might have notices that there are many actions which need to be perform multiple times. For that you might have write duplicate code at separate places in the code.</p>
<p>That’s where functions come in.</p>
<h2>What are functions? Why we need functions?</h2>
<p>Functions are a piece of code written that can perform a specific task. There are a code blocks which can be reusable at multiple places.</p>
<p>Instead of writing same logic to separate places you can it inside a function and use it where ever you need it.</p>
<h3>Real life analogy</h3>
<p>Imagine a coffee machine ☕️</p>
<p>Actions perform in a coffee machine:</p>
<ol>
<li><p>Press the button</p>
</li>
<li><p>Grinding</p>
</li>
<li><p>Brewing</p>
</li>
<li><p>Filtering</p>
</li>
<li><p>Gives coffee</p>
</li>
</ol>
<p>These are all the separate methods done by the coffee machine.</p>
<p>Examples: Without function:</p>
<pre><code class="language-javascript">const sum1 = 1 + 2; // 3
const sum2 = 2 + 3; // 5
const sum3 = 3 + 4; // 7
const sum4 = 4 + 5; // 9
</code></pre>
<p>You can see we have the write the logic to add the number multiple times. Instead of this we can write a function sum which can return the sum of two number. We just had to provide the two numbers to the functions.</p>
<p>Examples: With function:</p>
<pre><code class="language-javascript">function sum (number1, number2){
    return number1 + number2;
}

const sum1 = sum(1, 2); // 3
const sum2 = sum(2, 3); // 5
const sum2 = sum(3, 4); // 7
const sum2 = sum(4, 5); // 9
</code></pre>
<h2>How to create functions?</h2>
<p>We can create functions by different ways:</p>
<ol>
<li><p>Function Declaration Syntax</p>
</li>
<li><p>Function Expression Syntax</p>
</li>
</ol>
<p>Let's discuss them one by one:</p>
<h2>Function Declaration Syntax</h2>
<p>This is the most common way of creating the functions:</p>
<pre><code class="language-javascript">function sum (number1, number2) {
    return number1 + number2
}
</code></pre>
<p>Key points:</p>
<ol>
<li><p><code>function</code> keyword</p>
</li>
<li><p>name of the functions (<code>sum</code>)</p>
</li>
<li><p>Can be called anywhere (explained more later in this blog)</p>
</li>
</ol>
<h2>Function Expression Syntax</h2>
<p>In this approach, a function is stored in a variable:</p>
<pre><code class="language-javascript">const sum = function (number1, number2) {
    return number1 + number2
}
</code></pre>
<p>Key points:</p>
<ol>
<li><p>Function is declared using <code>function</code> keyword.</p>
</li>
<li><p>Function has no name.</p>
</li>
<li><p>Function reference is stored in a variable. A variable should have a name.</p>
</li>
<li><p>Can be called using the variables. In this case, you can call <code>sum()</code> as it stores the reference of the function. Ideally, the function is called</p>
</li>
</ol>
<h3>Declaration vs Expression (Side-by-Side)</h3>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Function Declaration</th>
<th>Function Expression</th>
</tr>
</thead>
<tbody><tr>
<td>Syntax</td>
<td><code>function add() {}</code></td>
<td><code>const add = function() {}</code></td>
</tr>
<tr>
<td>Hoisting</td>
<td>✅ Fully hoisted</td>
<td>❌ Not fully hoisted</td>
</tr>
<tr>
<td>Usage before definition</td>
<td>✅ Works</td>
<td>❌ Error</td>
</tr>
<tr>
<td>Common use</td>
<td>General functions</td>
<td>Callbacks, dynamic logic</td>
</tr>
</tbody></table>
<h2>Hoisting in Functions</h2>
<p>Let's first understand what hoisting is:</p>
<p>Hoisting means: javascript moves declarations to the top before execution.</p>
<p>Example:</p>
<pre><code class="language-javascript">console.log(number1); // undefined

var number1 = 10;
</code></pre>
<p>You might be wondering that <code>console.log(number1)</code> should give an error instead of printing <code>undefined</code>. In Javascript, this is possible because of the concept of <strong>hoisting.</strong></p>
<p>Now try to run the logic below in the browser console dev tool or by creating a JS file and running it using <code>node &lt;filename.js&gt;</code>.</p>
<pre><code class="language-javascript">console.log(number2);
// ReferenceError: Cannot access 'number2' before initialization

const number2 = 20;
</code></pre>
<pre><code class="language-javascript">console.log(number3);
// ReferenceError: Cannot access 'number3' before initialization


const number3 = 30;
</code></pre>
<p>Now, you can see the error while executing this code.</p>
<p>Same applicable on the function.</p>
<p>Hoisting works in declaration syntax:</p>
<pre><code class="language-javascript">const result = sum(1, 2);
console.log(result); // 3

function sum (number1, number2){
    return number1 + number2;
}
</code></pre>
<p>Hoisting doesn't work in declaration syntax:</p>
<pre><code class="language-javascript">const result = sum(1, 2);
console.log(result);
// ReferenceError: Cannot access 'sum' before initialization

const sum = function (number1, number2){
    return number1 + number2;
}
</code></pre>
<h2>When to Use What?</h2>
<h3>Use Function Declaration when:</h3>
<ul>
<li><p>You want simple, reusable functions</p>
</li>
<li><p>You need to call it anywhere in your code</p>
</li>
<li><p>You want a cleaner structure</p>
</li>
</ul>
<h3>Use Function Expression when:</h3>
<ul>
<li><p>You’re passing functions as arguments (callbacks)</p>
</li>
<li><p>You want more control over execution</p>
</li>
<li><p>You’re working with modern patterns (like arrow functions) (Arrow functions we can study in the next blog)</p>
</li>
</ul>
<h2>Execution flow of function call</h2>
<p>You can also read about Javascript code execution in detail in the blog "<strong>Understanding JavaScript Global &amp; Local Execution Context".</strong></p>
<p>For functions, we can understand it stepwise. When a JS code is been executed:</p>
<ol>
<li><p>Javascript scans all the code</p>
</li>
<li><p>Hoist function declaration on top</p>
</li>
<li><p>Start execution line by line</p>
</li>
<li><p>When executing the code, if the function called is hoisted, it will execute that function.</p>
</li>
</ol>
<h2>Assignment (Try It Yourself)</h2>
<ol>
<li><p>Write a function declaration that multiplies two numbers and returns the result.</p>
</li>
<li><p>Write the same logic using a function expression approach.</p>
</li>
<li><p>Call both the functions and try to re-run the logic by updating the values passed to the variable.</p>
</li>
<li><p>Call both the functions before they are defined and try to observe the output (error/result).</p>
</li>
</ol>
<h2>Conclusion</h2>
<p>Functions are the building blocks of any program. You should know that the functions are used for:</p>
<ol>
<li><p>Reusability</p>
</li>
<li><p>Combining Logic</p>
</li>
<li><p>Make code clean and readable</p>
</li>
</ol>
<p>Follow my Javacript series to learn more!</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Array Methods Every Beginner Should Know]]></title><description><![CDATA[When working with JavaScript, arrays are everywhere. They store lists of items like numbers, names, tasks, or products. But storing data is just the beginning. We often need to add items, remove items]]></description><link>https://blog.ashishkumarsaini.dev/javascript-array-methods</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/javascript-array-methods</guid><category><![CDATA[jsarraymethods]]></category><category><![CDATA[jsarray]]></category><category><![CDATA[js-basic]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Tue, 17 Mar 2026 20:13:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/69fab99d-9ef7-4cd9-b701-04105d88ebf6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When working with JavaScript, arrays are everywhere. They store lists of items like numbers, names, tasks, or products. But storing data is just the beginning. We often need to add items, remove items, change values, or filter data.</p>
<p>JavaScript has built-in array methods that simplify these tasks.</p>
<p>In this article, we will explore some of the most useful array methods with simple examples:</p>
<ul>
<li><p>push() and pop()</p>
</li>
<li><p>shift() and unshift()</p>
</li>
<li><p>map()</p>
</li>
<li><p>filter()</p>
</li>
<li><p>reduce()</p>
</li>
<li><p>forEach()</p>
</li>
</ul>
<p>You can try all examples directly in your browser console or Node.js.</p>
<p>Lets first understand the methods which are used to add or remove the data in an array:</p>
<h2>push()</h2>
<p>The push() method adds a new element to the end of an array.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana"];

const newLength = fruits.push("Mango");

console.log(newLength) // 3
console.log(fruits); // ["Apple","Banana","Mango"]
</code></pre>
<p>It returns the updated length of array.</p>
<p>Push is generally used when adding a new item to a list, such as adding a task to a to-do list.</p>
<h2>pop()</h2>
<p>The pop() is used to remove the last element from the array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const items = ["Shoe", "Tshirt", "Trouser"];

const popItem = items.pop();

console.log(popItem); // 'Trouser'
console.log(items);   // ["Shoe", "Tshirt"]
</code></pre>
<p>It returns the element that is removed.</p>
<h2>shift()</h2>
<p>The shift() method removes the first element of an array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const items = ["Shoe", "Tshirt", "Trouser"];

const shiftItem = items.shift();

console.log(shiftItem); // "Shoe"
console.log(items);     // ["Tshirt", "Trouser"]
</code></pre>
<p>It returns the item which is removed. This works same as Queues in real life</p>
<h2>unshift()</h2>
<p>The unshift() method adds an item to the start of the array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const items = ["Shoe", "Tshirt", "Trouser"];

const popItem = items.unshift("Shirt");

console.log(popItem); // 4
console.log(items);   // [ 'Shirt', 'Shoe', 'Tshirt', 'Trouser' ]
</code></pre>
<p>It returns the new length of the array.</p>
<p>Let's understand the methods that are used to perform iteration (loop) on an array</p>
<h2>forEach()</h2>
<p>forEach() is used to perform an action on each element of an array.</p>
<p>It accepts a callback function that accepts three arguments, provided by forEach itself.</p>
<ul>
<li><p>value: element of array</p>
</li>
<li><p>index: position of element in array</p>
</li>
<li><p>array: complete array</p>
</li>
</ul>
<p>forEach() runs a function for every item in the array.</p>
<p>Example:</p>
<pre><code class="language-javascript">const numbers = [1, 2, 3]

numbers.forEach((num) =&gt; {
    console.log(num);
});

Output:
1
2
3
</code></pre>
<h2>Traditional Loop vs forEach()</h2>
<p>for loop:</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3];

for (let i = 0; i &lt; numbers.length; i++) {
    console.log(numbers[i]);
}
</code></pre>
<p>vs</p>
<p>forEach:</p>
<pre><code class="language-javascript">let numbers = [1, 2, 3];

numbers.forEach(function(num) { 
    console.log(num); 
});
</code></pre>
<p>As we can see in the above example, forEach is more cleaner and easier to read and use.</p>
<h2>map()</h2>
<p>map() creates a new array by updating each element based on the logic inside the callback.</p>
<blockquote>
<p>Assume map() to be turning a crate of fruit into a crate of juices.</p>
<p>The number of juice will remain same as the number of fruits.</p>
</blockquote>
<p>It accepts a callback function that accepts three arguments, provided by map itself.</p>
<ul>
<li><p>value: element of array</p>
</li>
<li><p>index: position of element in array</p>
</li>
<li><p>array: complete array</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">const numbers = [1, 2, 3];

const doubledNumbers = numbers.map((num) =&gt; {
    return num * 2;
});

console.log(doubledNumbers);

Output: [2, 4, 6] // updated values

console.log(numbers);

Output: [1, 2, 3] // remains same
</code></pre>
<p>map() returns an updated elements array. Also, it doesn't update the original array.</p>
<h2>filter()</h2>
<p>filter() creates a new array that only includes elements that satisfy the condition inside the callback function.</p>
<p>It accepts a callback function that accepts three arguments, provided by filter itself.</p>
<ul>
<li><p>value: element of array</p>
</li>
<li><p>index: position of element in array</p>
</li>
<li><p>array: complete array</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">const numbers = [3, 7, 10, 2];

const filteredNumbers = numbers.filter((num) =&gt; {
    if(num &gt; 5){
        return true;
    }
    
    return false;
});

console.log(filtersNumbers);

Output: [7, 10]
</code></pre>
<p>So, returned array only includes those values for which callback return true.</p>
<h3>How filter() work?</h3>
<p>Here:</p>
<ul>
<li><p>For 3, the callback returns false. <code>filteredNumbers</code> doesn't contain 3</p>
</li>
<li><p>For 7, the callback returns true. <code>filteredNumbers</code> contain 7</p>
</li>
<li><p>For 10, the callback returns true. <code>filteredNumbers</code> contain 10</p>
</li>
<li><p>For 2, the callback returns false. <code>filteredNumbers</code> doesn't contain 2</p>
</li>
</ul>
<h2>reduce()</h2>
<p>reduce() combines all values of an array into a single value.</p>
<blockquote>
<p>Reduce is like combining flour, eggs, and sugar to bake one single cake.</p>
</blockquote>
<p>Common use cases include:</p>
<ul>
<li><p>total sum</p>
</li>
<li><p>calculating totals</p>
</li>
<li><p>combining data</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">let numbers = [5, 10, 20];

let total = numbers.reduce((accumulator, value) =&gt; {
 return accumulator + value; 
}, 0);

console.log(total);

Output: 35
</code></pre>
<p>Returns the single value after the final calculation.</p>
<h3>How reduce() works?</h3>
<p>Sometimes, reduce is very confusing for beginners.</p>
<table>
<thead>
<tr>
<th>value</th>
<th>accumulator</th>
<th>calculation</th>
<th>initialValue</th>
</tr>
</thead>
<tbody><tr>
<td>5</td>
<td>0</td>
<td>0 + 5 = 5</td>
<td>5</td>
</tr>
<tr>
<td>10</td>
<td>5</td>
<td>5 + 10 = 15</td>
<td>15</td>
</tr>
<tr>
<td>20</td>
<td>15</td>
<td>15 + 20 = 35</td>
<td>35</td>
</tr>
</tbody></table>
<p>Visual Idea for reduce()<br />[5, 10, 15]</p>
<p>Step 1 → 0 + 5 = 5<br />Step 2 → 5 + 10 = 15<br />Step 3 → 15 + 15 = 30</p>
<p>Final Result = 30</p>
<h2>Assignment for Practice</h2>
<p>Try this in your browser console.</p>
<ul>
<li><p>Try map()</p>
<ol>
<li><p>Create an array</p>
</li>
<li><p>Double each number using map()</p>
</li>
<li><p>Console the output and observe by updating the array.</p>
</li>
</ol>
</li>
<li><p>Try filter()</p>
<ol>
<li><p>Apply filter() method on map() output</p>
</li>
<li><p>Filter numbers greater than 10</p>
</li>
</ol>
</li>
<li><p>Try reduce()</p>
<ol>
<li><p>Create an array</p>
</li>
<li><p>Add those numbers using reduce() method.</p>
</li>
<li><p>Check the output and retry after updating the values and number of values in array.</p>
</li>
</ol>
</li>
</ul>
<h2>Final Thoughts</h2>
<p>Array methods make JavaScript more powerful and readable.</p>
<p>Instead of writing long loops, you can use:</p>
<ul>
<li><p>map() to change data</p>
</li>
<li><p>filter() to select data</p>
</li>
<li><p>reduce() to combine data</p>
</li>
<li><p>forEach() to loop through items</p>
</li>
</ul>
<p>These methods are commonly used in modern JavaScript, React, and backend development.</p>
<p>The best way to learn them is simple: open your console and experiment with them.</p>
<p>Follow Javascript Series to learn more!</p>
]]></content:encoded></item><item><title><![CDATA[JS Internals: Understanding JavaScript Global & Local Execution Context]]></title><description><![CDATA[Let’s first look at a real-world scenario before jumping into JavaScript.
Imagine a wooden furniture factory that manufactures different types of furniture. To better understand the process, let’s see]]></description><link>https://blog.ashishkumarsaini.dev/javascript-global-local-execution-context</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/javascript-global-local-execution-context</guid><category><![CDATA[js exection]]></category><category><![CDATA[Global execution context]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 14 Mar 2026 22:57:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/5221eff6-eb6d-47d7-9c34-c4b20750b041.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let’s first look at a real-world scenario before jumping into JavaScript.</p>
<p>Imagine a wooden furniture factory that manufactures different types of furniture. To better understand the process, let’s see how the factory works internally.</p>
<p>The factory uses several types of wood. For simplicity, let’s assume the following types are used:</p>
<ol>
<li><p>Sagwan</p>
</li>
<li><p>Mango</p>
</li>
<li><p>Sheesham</p>
</li>
</ol>
<p>Inside the factory, the work is divided into multiple departments</p>
<ol>
<li><p>Cutting</p>
</li>
<li><p>Framing</p>
</li>
<li><p>Polishing</p>
</li>
<li><p>Cushion</p>
</li>
<li><p>Quality Assurance</p>
</li>
</ol>
<p>There is a centralized execution chain of the factory on which the departments work, and each department performs its task in a specific order in the execution chain.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/be9c78b8-ba05-4b5d-999c-892d1d9f56fe.png" alt="" style="display:block;margin:0 auto" />

<p>The entire factory has a central board on which it is mentioned:</p>
<ul>
<li><p>The order of departments working inside the factory</p>
</li>
<li><p>What needs to be done</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/e8194020-7e32-41e3-99c2-442a7515babe.png" alt="" style="display:block;margin:0 auto" />

<p>Inside the department, there will definitely be so many works which are working one by one for their individual task. So, each department also has its own board (or blackboard) where two things are written:</p>
<ul>
<li><p>The order of individual tasks to be done inside the department</p>
</li>
<li><p>The actual tasks that need to be performed in that department</p>
</li>
</ul>
<img alt="" style="display:block;margin:0 auto" />

<p>There is also a manager in the factory whose job is to:</p>
<ul>
<li><p>Monitor the progress of the work</p>
</li>
<li><p>Ensure that each department performs its task in the correct order</p>
</li>
</ul>
<p>Let's combine the diagrams to see the full factory view:</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/903ce76a-744f-4da8-8638-503ee2df075c.png" alt="" style="display:block;margin:0 auto" />

<p>Now the factory receives an order to build a wooden sofa with Sagwan wood.</p>
<p>Steps:</p>
<ol>
<li><p>The very first step is to analyze the wood that has been received.</p>
</li>
<li><p>On the central factory blackboard:</p>
<ul>
<li><p>What to be done: Build a sofa with a specific size mentioned</p>
</li>
<li><p>Order of work done: Cutting -&gt; Framing -&gt; Polishing -&gt; Cushion -&gt; QA</p>
</li>
</ul>
</li>
<li><p>Wood comes to the Cutting department. On the Cutting department blackboard:</p>
<ul>
<li><p>What to be done: Cut the wood into a smaller size as mentioned</p>
</li>
<li><p>Order of work: Cut big wood logs -&gt; Cutting into smaller chunks</p>
</li>
</ul>
</li>
<li><p>Chunks of wood come to the Framing department. On the Framing department blackboard:</p>
<ol>
<li><p>What to be done: Frame the received pieces of wood into the given size</p>
</li>
<li><p>Order of work: Smoothen the wood -&gt; Frame into the size of the sofa -&gt; Finishing</p>
</li>
</ol>
</li>
<li><p>A framed sofa comes to the Polishing department. On the Polishing department blackboard:</p>
<ol>
<li><p>What to be done: Polish the received sofa frame</p>
</li>
<li><p>Order of work: Apply polish -&gt; Rubbing</p>
</li>
</ol>
</li>
<li><p>A polished sofa comes to the Cushion department. On the Cushion department blackboard:</p>
<ol>
<li><p>What to be done: Apply a cushion on the sofa frame</p>
</li>
<li><p>Order of work: Cutting cushion -&gt; Stitching and pasting</p>
</li>
</ol>
</li>
<li><p>A final piece comes to the QA department. On the QA department blackboard:</p>
<ol>
<li><p>What to be done: Check the quality and overall sofa</p>
</li>
<li><p>Order of work: Checking the quality</p>
</li>
</ol>
</li>
</ol>
<p>All of these steps are done under the supervision of the manager and if any process fails in between, the manager can ask the department to do the work again properly.</p>
<p>Things to remember:</p>
<ol>
<li><p>The tasks done are executed on the execution chain. The execution chain is inside the factory</p>
</li>
<li><p>There are some sub-tasks inside the department, which are inside the department. But the space allotted to the department is inside the factory, So those subtasks are also belong to the factory.</p>
</li>
</ol>
<p>Javascript program execution works the same way. To understand this, let's replace a few terms with Javascript terminology.</p>
<img alt="" style="display:block;margin:0 auto" />

<p>Here,</p>
<ul>
<li><p>Wood types -&gt; Data types</p>
</li>
<li><p>Factory -&gt; Global Execution Context</p>
</li>
<li><p>Global Execution has two phases:</p>
<ul>
<li><p>Code Phase / Thread Phase</p>
</li>
<li><p>Memory Phase</p>
</li>
</ul>
</li>
<li><p>Departments -&gt; Functions, Functions has its own Local Execution Context, which further has two phases:</p>
<ul>
<li><p>Code Phase / Thread Phase</p>
</li>
<li><p>Memory Phase</p>
</li>
</ul>
</li>
<li><p>Manager -&gt; Call Stack, who is responsible for maintaining the order of execution of the functions.</p>
</li>
</ul>
<p><strong>So, whenever a JS code has been executed:</strong></p>
<ol>
<li><p>A global execution context is created (also known as the Creation Phase).</p>
</li>
<li><p>Declare the variables and store the definition of functions inside the Memory of the Global Execution Context (also known as Memory Phase).</p>
</li>
<li><p>Now the execution of code starts line by line, which checks the current value of the variables in the memory and reads the definitions of the functions from the memory (also known as Code Phase).</p>
</li>
<li><p>If there is any function in the code:</p>
<ol>
<li><p>Create the Local Execution Context for the function.</p>
</li>
<li><p>Declare the variables in Local Execution Context (also known as Memory Phase for Local Context).</p>
</li>
<li><p>Execute the code of the function line by line.</p>
</li>
<li><p>Once all the code inside the function is executed completely, it returns the value to the Global Context</p>
</li>
</ol>
</li>
<li><p>Global Execution Context executes the remaining code until all the code is executed.</p>
</li>
</ol>
<p><strong>Let's take an example to understand the flow:</strong></p>
<p>Here is a small code snippet:</p>
<pre><code class="language-javascript">var value1 = 10;
var value2 = 20;

function sum(sumNum1, sumNum2, sumNum3) {
    return sumNum1 + sumNum2 + sumNum3;
}

function calculate(calcNum1, calcNum2) {
  	var calcNum3 = 30;
    var total = sum(calcNum1, calcNum2, calcNum3);
    return total;
}

var result = calculate(value1, value2);
console.log(result);
</code></pre>
<p>Steps in which JS code is executed:</p>
<h3><strong>Global Execution context (Factory)</strong></h3>
<ol>
<li><p><strong>Creation Phase</strong><br />Global Execution Context is created<br />(<em>Blackboard for the factory is ready</em>)  </p>
<p>global is assigned to <code>this</code> (Global can vary depending on the environment in which the code is running. In the browser, it will be a window object.)</p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Memory Phase</strong>: Variable and Function Definition get stored in Global Memory<br />(<em>What to be done, the size, and the material of the sofa are now mentioned on the blackboard</em>)  </p>
<p><code>value1</code> is declared in memory with a value <code>undefined</code><br /><code>value2</code> is declared in memory with a value <code>undefined</code><br />The declaration of the <code>sum</code> function is stored in memory.<br />The declaration of the <code>calculate</code> function is stored in memory.<br /><code>result</code> is declared in the memory with a value <code>undefined</code></p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: undefined                                    |
| value2: undefined                                    |
| sum: fn()                                            |
| calculate: fn()                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Execution Phase</strong>: Execution of code line by line. Execution is done by the JS engine on main thread.<br />(<em>Sofa building process starts now</em>)  </p>
<p>The value of <code>value1</code> is initialized as <code>10</code>.<br />The value of <code>value2</code> is initialized as <code>20</code>.<br />The <code>calculate</code> function is called, so a new <strong>Local Execution Context</strong> is created and pushed onto the <strong>Call Stack</strong>.</p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
<ol>
<li><p><strong>Creation Phase:</strong> Local Execution Context is created for calculate<br />(<em>Blackboard for the Department is ready</em>)  </p>
<p><code>calcNum1</code> is declared in memory with a value <code>10</code><br /><code>calcNum2</code> is declared in memory with a value <code>20</code></p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| Local Execution Context Memory for calculate()       |
| ---------------------------------------------------- |
| | this: window                                     | |
| | calcNum1: 10                                     | |
| | calcNum2: 20                                     | |
| | total: undefined                                 | |
| ---------------------------------------------------- |
|                                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Memory Phase</strong>: Variable and Function Definition get stored in Local Memory<br />(<em>What to be done and the used things are now mentioned on the department blackboard</em>)  </p>
<p><code>calcNum3</code> is declared in memory with a value <code>undefined</code><br /><code>total</code> is declared in memory with a value <code>undefined</code></p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| Local Execution Context Memory for calculate()       |
| ---------------------------------------------------- |
| | this: window                                     | |
| | calcNum1: 10                                     | |
| | calcNum2: 20                                     | |
| | calcNum3: undefined                              | |
| | total: undefined                                 | |
| ---------------------------------------------------- |
|                                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Execution Phase</strong>: Execution inside <code>calculate</code> function. Execution of code line by line on main thread.  </p>
<p>The value of <code>calcNum3</code> is initialized as <code>30</code>.<br />The <code>sum</code> function is called, so a new <strong>Local Execution Context</strong> is created and pushed onto the <strong>Call Stack</strong>.</p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| Local Execution Context Memory for calculate()       |
| ---------------------------------------------------- |
| | this: window                                     | |
| | calcNum1: 10                                     | |
| | calcNum2: 20                                     | |
| | calcNum3: undefined                              | |
| | total: undefined                                 | |
| ---------------------------------------------------- |
|                                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
<h3>Local Execution Context (Departments)</h3>
<ol>
<li><p><strong>Creation Phase:</strong> Local Execution Context is created for sum<br />(<em>Blackboard for the Sub-Department is ready</em>)  </p>
<p><code>sumNum1</code> is declared in memory with a value <code>10</code><br /><code>sumNum2</code> is declared in memory with a value <code>20</code><br /><code>sumNum3</code> is declared in memory with a value <code>30</code></p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| Local Execution Context Memory for calculate()       |
| ---------------------------------------------------- |
| | this: window                                     | |
| | calcNum1: 10                                     | |
| | calcNum2: 20                                     | |
| | calcNum3: undefined                              | |
| | total: undefined                                 | |
| |                                                  | |
| | Local Execution Context Memory for sum()         | |
| | ________________________________________________ | |
| | | this: window                                 | | |
| | | sumNum1: 10                                  | | |
| | | sumNum2: 20                                  | | |
| | | sumNum3: 30                                  | | |
| | ------------------------------------------------ | |
| ---------------------------------------------------- |
|                                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Memory Phase:</strong> SInce there is no variable value needs to be assigned to memory. Nothing will happen for sum function in this phase.</p>
</li>
<li><p><strong>Execution Phase:</strong> Sum of 3 variables has been returned by sum function.</p>
</li>
<li><p>The execution context for <strong>sum</strong> is now destroyed.</p>
</li>
</ol>
</li>
<li><p><strong>Execution Phase</strong>: Back to execution of calculate function<br />The value of <code>total</code> is now been updated to <code>60</code>  </p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| Local Execution Context Memory for calculate()       |
| ---------------------------------------------------- |
| | this: window                                     | |
| | calcNum1: 10                                     | |
| | calcNum2: 20                                     | |
| | calcNum3: undefined                              | |
| | total: 60                                        | |
| ---------------------------------------------------- |
|                                                      |
| result: undefined                                    |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Execution Phase</strong>: The value of <code>total</code> is now been returned and the Local Context for <code>calculate</code> is now destroyed.</p>
</li>
</ol>
</li>
<li><p><strong>Execution Phase</strong>: Back to execution of global context<br />The value of <code>result</code> is now been updated to <code>60</code>  </p>
<pre><code class="language-javascript">Global Execution Context Memory
________________________________________________________
| window: global object                                |
| this: window                                         |
|                                                      |
| value1: 10                                           |
| value2: 20                                           |
| sum: fn()                                            |
| calculate: fn()                                      |
|                                                      |
| result: 60                                           |
--------------------------------------------------------
</code></pre>
</li>
<li><p><strong>Execution Phase</strong>: console.log reads result from memory and prints <code>60</code></p>
</li>
</ol>
<h2>Call Stack (Manager)</h2>
<p>The Call Stack works like a stack of tasks.</p>
<p>When a function is called, its execution context is pushed onto the stack.</p>
<p>When the function finishes execution, it is popped from the stack.</p>
<h2>Single thread</h2>
<p>You have heard about that Javascript is single thread language.</p>
<p>That means:</p>
<ul>
<li><p>Global code runs on main thread</p>
</li>
<li><p>When execution of code contains a function</p>
<ul>
<li><p>A local context is created</p>
</li>
<li><p>That context is pushed into Call stack</p>
</li>
<li><p>The main thread now start executing the function logic</p>
</li>
<li><p>After execution, the local context is removed and destroyed</p>
</li>
</ul>
</li>
<li><p>No other thread is created while execution other than main thread.</p>
</li>
</ul>
<blockquote>
<p>Function create execution context, not threads</p>
</blockquote>
<h2>Assignment for practice</h2>
<p>Install Node.js (runtime environment) and VSCode (code editor)</p>
<p>Open VSCode, create a file <code>practice.js</code> and copy the above code into that file.</p>
<p>Click on Terminal -&gt; New Terminal from the menu bar on top.</p>
<p>From select terminal, selected "Javascript Debug Terminal".</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/f152b8e4-c03e-48e7-b6e8-f8cc73a8bd74.png" alt="" style="display:block;margin:0 auto" />

<p>Add breakpoints by clicking on the gutter (the space). Red dot indicate that the breakpoint is added on that line.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/2c07ed69-2207-49a9-81d2-81c59179f0a8.png" alt="" style="display:block;margin:0 auto" />

<p>Now, run <code>node practice.js</code> . Make sure you are in the same folder inside the terminal.</p>
<p>Try to play around with the next breakpoint button and observe the values of the context section.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/a46f40b4-49f1-415d-8ccf-10f6e9622b47.png" alt="" style="display:block;margin:0 auto" />

<h2>Conclusion</h2>
<p>JavaScript executes code using Execution Contexts and the Call Stack.</p>
<p>The Global Execution Context runs first, and every function call creates a new Local Execution Context.</p>
<p>These contexts are managed by the Call Stack to ensure that code executes in the correct order.  </p>
<p>Follow the series to learn more about Javascript.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Arrays in JavaScript]]></title><description><![CDATA[When we start learning programming, we usually store values in variables.
let fruit1 = "Apple";
let fruit2 = "Banana";
let fruit3 = "Mango";

This works fine for a few values.But what if we need to st]]></description><link>https://blog.ashishkumarsaini.dev/understanding-arrays-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/understanding-arrays-in-javascript</guid><category><![CDATA[jsarray]]></category><category><![CDATA[js array basics]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 14 Mar 2026 18:23:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/523a92db-2219-41bf-95b7-80c1cd442132.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning programming, we usually store values in variables.</p>
<pre><code class="language-javascript">let fruit1 = "Apple";
let fruit2 = "Banana";
let fruit3 = "Mango";
</code></pre>
<p>This works fine for a few values.<br />But what if we need to store 20 fruits? 100 student marks? 1000 tasks?</p>
<p>Creating separate variables for each value becomes messy and hard to manage.</p>
<p>This is where arrays help us.</p>
<h2>What is an Array?</h2>
<p>An array is a collection of data elements that can be of the same or different types. In an array, the individual elements of data are referred to as elements.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];
</code></pre>
<h2>Why Do We Need Arrays?</h2>
<p>Arrays help us when we want to store multiple values together.</p>
<p>Common examples:</p>
<ul>
<li><p>List of fruits</p>
</li>
<li><p>Student marks</p>
</li>
<li><p>Shopping list</p>
</li>
<li><p>Tasks in a to-do list</p>
</li>
<li><p>Comments on a post</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-javascript">let marks = [78, 85, 92, 67, 88];
</code></pre>
<p>Instead of 5 variables, we store everything in one array.</p>
<h2>How to Create an Array</h2>
<p>In JavaScript, arrays can be created using multiple ways:</p>
<ol>
<li>square brackets <code>[]</code> (beginner-friendly)</li>
</ol>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];
let numbers = [10, 20, 30, 40];
let data = ["Ashish", 22, true];
</code></pre>
<ol>
<li>Using the <code>Array</code> Constructor. You can also use the <code>new Array()</code> constructor.</li>
</ol>
<ul>
<li>Empty Array</li>
</ul>
<pre><code class="language-javascript">const emptyArrayConstructor = new Array();
</code></pre>
<ul>
<li>Array with initial values</li>
</ul>
<pre><code class="language-javascript">const fruitsConstructor = new Array("apple", "banana", "cherry");
</code></pre>
<ul>
<li>Array with a specified length: If a single number is passed, it creates an array with that number of empty slots, not a single-element array.</li>
</ul>
<pre><code class="language-javascript">const newArray = new Array(3); 
// Creates an array with 3 empty slots, not [3]
// But accessing newArray[0] gives undefined.
</code></pre>
<ul>
<li><code>Array.of()</code><strong>:</strong> The <code>Array.of()</code> static method creates a new <code>Array</code> instance from a variable number of arguments, regardless of the number or type of the arguments.</li>
</ul>
<pre><code class="language-javascript">const singleNumberArray = Array.of(8); // Creates [8]
const multipleElementsArray = Array.of(1, 2, 3); // Creates [1, 2, 3]
</code></pre>
<ul>
<li><code>Array.from()</code><strong>:</strong> The <code>Array.from()</code> static method creates a new, shallow-copied <code>Array</code> instance from an iterable or array-like object.</li>
</ul>
<pre><code class="language-javascript">// Create an array from a string
const fromString = Array.from("word"); // Creates ["w", "o", "r", "d"]

// Create an array with sequential numbers
const range = Array.from({ length: 5 }, (v, i) =&gt; i); // Creates [0, 1, 2, 3, 4]
</code></pre>
<h3>Understanding Array Index</h3>
<p>Every element in an array has a position number called an index.</p>
<p>Array indexing starts from 0.</p>
<p>Example:</p>
<pre><code class="language-javascript">const arr = ['Apple', 'Banana', 'Mango'];


Index:   0        1        2
        ----------------------
Array:  Apple   Banana   Mango
</code></pre>
<h2>Accessing Array Elements</h2>
<p>If we want a specific element of an array we can access it by its index using square brackets.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];


console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana
console.log(fruits[2]); // Mango
</code></pre>
<p>So,</p>
<ul>
<li><p><code>fruits[0]</code> is the first element</p>
</li>
<li><p><code>fruits[1]</code> is the second element</p>
</li>
<li><p><code>fruits[2]</code> is the third element</p>
</li>
</ul>
<h2>Updating Array Elements</h2>
<p>We can use the index of the element to update the array.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];

fruits[1] = "Orange";

console.log(fruits); // ["Apple", "Orange", "Mango"]
</code></pre>
<p>In this case we replaced <code>Banana</code> with <code>Orange</code>.</p>
<h2>Array Length Property</h2>
<p>Every array has a built-in property called <code>length</code>. This property tells us how many elements there are inside of the array.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];

console.log(fruits.length); // 3
</code></pre>
<h2>Looping Through an Array</h2>
<p>If we don't want to manually print each element, we can use a loop.</p>
<p>Example:</p>
<pre><code class="language-javascript">let fruits = ["Apple", "Banana", "Mango"];

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

// Output:
// Apple
// Banana
// Mango
</code></pre>
<p>Explanation:</p>
<ul>
<li><p>Start at index <code>0</code></p>
</li>
<li><p>Continue until <code>fruits.length</code></p>
</li>
<li><p>Print each element.</p>
</li>
</ul>
<p>This allows us to easily work with arrays of any size.</p>
<h2>Visualizing an Array</h2>
<p>You can think of an array like boxes placed next to each other.</p>
<pre><code class="language-javascript">Index →   0        1        2
        ----------------------
Value →  Apple   Banana   Mango
</code></pre>
<p>Or like memory blocks:</p>
<pre><code class="language-plaintext">[0] → Apple
[1] → Banana
[2] → Mango
</code></pre>
<p>Each box has:</p>
<ul>
<li><p>a position (index)</p>
</li>
<li><p>a value</p>
</li>
</ul>
<h2>Assignment</h2>
<p>Try solving the following exercises:</p>
<ul>
<li><p>Define an array of 5 of your favourite movies</p>
</li>
<li><p>Print the first and the last movies</p>
</li>
<li><p>Update the second movie in the array and print the array</p>
</li>
<li><p>Use a for loop to print all the movies</p>
</li>
</ul>
<h2><strong>Final Thoughts</strong></h2>
<p>Arrays are one of the most important data structures in JavaScript.</p>
<p>They allow us to:</p>
<ul>
<li><p>store a collection of data</p>
</li>
<li><p>access that collection using an index</p>
</li>
<li><p>alter that collection</p>
</li>
<li><p>Easily iterate through that collection</p>
</li>
</ul>
<p>After learning the basics, you can learn to use the various array methods. Learning the basics will help you understand the array methods more easily. Master the basics first, and your future learning will be easier!</p>
<p>Follow the JS series to learn more about Javascript.</p>
]]></content:encoded></item><item><title><![CDATA[Control Flow in JavaScript: If, Else, and Switch Explained]]></title><description><![CDATA[Everyday you made so many decisions without thinking of them. You going to office, if it is raining, you think of carrying an umbrella, other you leave it at home. When you check your exam results, yo]]></description><link>https://blog.ashishkumarsaini.dev/control-flow-in-javascript</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/control-flow-in-javascript</guid><category><![CDATA[javascript control flow]]></category><category><![CDATA[js-if-else]]></category><category><![CDATA[js-switch]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 14 Mar 2026 07:18:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/f1ce6a35-269f-4cc3-8b36-3f5ce318dd59.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Everyday you made so many decisions without thinking of them. You going to office, if it is raining, you think of carrying an umbrella, other you leave it at home. When you check your exam results, you think: <em>"<em>If I scored above 90, I passed with distinction. If I scored between 70 and 90, I just passed. Otherwise, I need to study harder.</em>"</em></p>
<p>These are called conditional decisions.</p>
<p>Programming works the same way.</p>
<p>In programming, control flow refers to the order in which your program executes instructions. By default, code runs line by line, top to bottom. But real programs need to make decisions, repeat actions, and skip steps based on conditions. That's where control flow structures come in.</p>
<p>In this blog, we will cover the most fundamental of condition programming using:</p>
<ul>
<li><p>if</p>
</li>
<li><p>else if</p>
</li>
<li><p>else</p>
</li>
<li><p>switch</p>
</li>
</ul>
<h2>What is control flow?</h2>
<p>Control flow is a mechanism to handle the execution of code lines. It determines which lines of code, in what order and under which conditions.</p>
<p>Without control flow, programming is just a code flow in a single direction. Using control flow gives a different path to the code flow. Usually, all programs/software need control flow as each program has different flows to handle.</p>
<pre><code class="language-markdown">Line 1 -&gt; Line 2 -&gt; Line 3 -&gt; Line 4 -&gt; Line 5 -&gt; Line 6
</code></pre>
<p>With control flow:</p>
<pre><code class="language-markdown">Line 1 -&gt; Line 2 -&gt; Line 3 -&gt; if   -&gt; Line 4
                              else -&gt; Line 5 -&gt; Line 6
</code></pre>
<h2>Understanding control flow statements</h2>
<h3>If statement</h3>
<p>Imagine you are at a ticket counter. The rule is, "if a person is less than 18, you are not allowed to buy a ticket." You are only allowed if you are 18 or older.</p>
<p>There is no other action, it's either you can buy or not allowed to buy.</p>
<p>Code version:</p>
<p>The <code>if</code> statement works exactly like that. It checks a condition, and <strong>only if the condition is true</strong>, it executes the block of code inside the curly braces.</p>
<pre><code class="language-javascript">const age = 15;

if(age &gt;= 18){
    console.log("You are allowed to buy the ticket");
}

console.log("Program ends!")
</code></pre>
<p>When <code>age</code> is 15, the condition <code>age &gt;= 18</code> is <strong>false</strong>, so the <code>console</code> inside the <code>if</code> block is skipped entirely. The program jumps straight to the next line after the closing brace.</p>
<p>How It Runs Step by Step</p>
<ol>
<li><p>The program reaches the <code>if</code> statement.</p>
</li>
<li><p>It evaluates the condition inside the parentheses.</p>
</li>
<li><p>If the condition is true, it enters the block <code>{ ... }</code> and runs the code inside.</p>
</li>
<li><p>If the condition is false, it skips the block entirely.</p>
</li>
<li><p>Execution continues with whatever comes after the closing <code>}</code>. (<code>Program ends!</code> )</p>
</li>
</ol>
<h3>If-else</h3>
<h3>The Real-Life Version</h3>
<p>Now imagine there is an election going on in your city. So, if you age is 18 or above, you can vote. Otherwise, you cannot. Here we can see there are two flows. Either you vote in the election or not.</p>
<p>Code Version</p>
<pre><code class="language-javascript">const age = 20;

if(age &gt;= 20) {
    console.log("You are eligible for voting");
}
else {
    console.log("You are not eligible for voting");
}

console.log("Program ends!")
</code></pre>
<p>Try to run the above code snippet in your browser console or in any online Javascript compiler.</p>
<p>In the previous example, we have seen the condition inside <code>if (condition)</code> does not fulfill. <code>(false)</code> , "Program ends!" prints out. But here, it will go into the else block.</p>
<h3>Else-if</h3>
<p>In real life or in programming, there might be more than two outcomes. Consider a grading system:</p>
<ul>
<li><p>90 and above → Grade A</p>
</li>
<li><p>75 to 89 → Grade B</p>
</li>
<li><p>60 to 74 → Grade C</p>
</li>
<li><p>35 to 59 → Grade D</p>
</li>
<li><p>Below 35 → Fail</p>
</li>
</ul>
<p>That's five possible outcomes. You need to check multiple conditions in sequence, and execute the block that matches the first true condition. This is called an <code>else if</code> <strong>ladder</strong>.</p>
<pre><code class="language-javascript">const marks = 82;

if (marks &gt;= 90) {
    console.log("A");
} else if (marks &gt;= 75) {
    console.log("B");
} else if (marks &gt;= 60) {
    console.log("C");
} else if (marks &gt;= 35) {
    console.log("D");
} else {
    console.log("Fail");
}
</code></pre>
<h3>Else</h3>
<p>Else is used for the last case, if all the <code>if</code> or <code>else if</code> conditions will not be fulfilled. In the above code example, you can see we are printing "Fail" as it is the last option in the programming flow.</p>
<h3>Switch</h3>
<p>Imagine you're writing a program: "Enter 1 for Monday, 2 for Tuesday, 3 for Wednesday..." You have one variable (the user's choice), and many exact values to compare it against. Using a long <code>else if</code> ladder for this works, but it's repetitive and harder to read.</p>
<p>The <code>switch</code> statement was used exactly for this scenario. It takes a single expression, compares it against multiple fixed values, and jumps directly to the matching one.</p>
<p>Example:</p>
<pre><code class="language-javascript">const day = 3;

switch (day) {
    case 1:
        console.log("Monday");
    case 2:
        console.log("Tuesday");
    case 3:
        console.log("Wednesday");
    case 4:
        console.log("Thursday");
    case 5:
        console.log("Friday");
    case 6:
        console.log("Saturday");
    case 7:
        console.log("Sunday");
    default:
        console.log("Invalid day number.");
}
</code></pre>
<p>Try to run this program in the browser console or Javascript compiler.</p>
<p>Have you noticed the problem? What is the output of the above program?  </p>
<p>Monday<br />Tuesday<br />Wednesday<br />Thursday<br />Friday<br />Saturday<br />Sunday<br />Invalid day number.  </p>
<p>Have you wondered why all the days get printed? Here, what helps is the <code>break</code> keyword.</p>
<h3>Break</h3>
<p>The <code>break</code> statement tells the program: *"*You're done with this case, exit the switch now." If you forgot to use break, just like the above example, the program will continuously execute all the cases until it gets the break.</p>
<p>Let's see the same example with <code>break</code> statment:</p>
<pre><code class="language-javascript">const day = 6;

switch (day) {
    case 1:
        console.log("Monday");
        break;
    case 2:
        console.log("Tuesday");
        break;
    case 3:
        console.log("Wednesday");
        break;
    case 4:
        console.log("Thursday");
        break;
    case 5:
        console.log("Friday");
        break;
    case 6:
        console.log("Saturday");
        break;
    case 7:
        console.log("Sunday");
        break;
    default:
        console.log("Invalid day number.");
}
</code></pre>
<p>Now, try to run the program with multiple values of days. You will find that it was printing only the valid day. In this case, value of day is 6, so it will print "Saturday".</p>
<p>Change the value of day to 10 or "10", and observe the change in the result.</p>
<h2>Assignment: Practice These Yourself</h2>
<p>The best way to understand control flow is to write code. Here are two exercises:</p>
<h3>Assignment 1 — Positive, Negative, or Zero</h3>
<p>Write a program that checks an integer and prints whether it is positive, negative, or zero.</p>
<blockquote>
<p>Hint: Use an <code>if-else</code> ladder</p>
</blockquote>
<p>Example output:</p>
<pre><code class="language-plaintext">const intNum = 10;
Result: The number is positive.

const intNum = -3;
Result: The number is negative.

const intNum = 0;
Result: The number is zero.
</code></pre>
<hr />
<h3>Assignment 2 — Day of the Week</h3>
<p>Write a program for a vending machine using <code>switch</code>. Create a variable item_name and check the cases for the item_name.</p>
<p>Cases:</p>
<ul>
<li><p>When <code>item_name</code> is "coffee", print "Dispensing Coffee"</p>
</li>
<li><p>When <code>item_name</code> is "tea", print "Dispensing Tea"</p>
</li>
<li><p>When <code>item_name</code> is "cookie", print "Dispensing Cookie"</p>
</li>
<li><p>Invalid case, print "Invalid Item Name"</p>
</li>
</ul>
<blockquote>
<p>Use switch with break statement</p>
</blockquote>
<h2>Conclusion</h2>
<p>Programming is just teaching computers to make decisions like humans. Control flow is a necessary part of programming, as a program will have different flows that need to be controlled using these statements.</p>
<p>Follow this series to learn more about Javascript!</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Variables and Data Types in JavaScript]]></title><description><![CDATA[Let's imagine you and your friends are moving to a city for your new job. Both of you have packed the necessary items that would be needed initially in the new city. You have packed your bags with lab]]></description><link>https://blog.ashishkumarsaini.dev/js-variables-and-datatypes</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/js-variables-and-datatypes</guid><category><![CDATA[js data type]]></category><category><![CDATA[js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[js datatypes]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Wed, 11 Mar 2026 21:18:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/12dcd61e-377e-43a2-9d63-a2d9d9dd496f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let's imagine you and your friends are moving to a city for your new job. Both of you have packed the necessary items that would be needed initially in the new city. You have packed your bags with labels, keeping in mind which item is in which bag. However, your friend has just mixed up all the things and thrown them into the bags. On your first day of the job, both of you start getting ready in the morning to reach the office on time.</p>
<p>Now, what will happen? Your friend won't remember which bag the required item is in. If he had labeled everything, it wouldn't be a mess for him.</p>
<p>So, think of a JavaScript variable like a box used to store things in real life.</p>
<h2>How to declare the variables?</h2>
<p>Javascript has three keywords used to declare variables. These are:</p>
<ol>
<li><p>let</p>
</li>
<li><p>const</p>
</li>
<li><p>var</p>
</li>
</ol>
<h3>Declaring a variable with let keyword</h3>
<p>let is used to declare variables whose value might change later.</p>
<p>Example:</p>
<pre><code class="language-javascript">let count = 10;

console.log(count); // 10

count = 20;

console.log(count) // 20
</code></pre>
<p>In the above example, the value of <code>count</code> the variable changes from 10 to 20.</p>
<h3>Declaring a variable with the const keyword</h3>
<p>const is used to declare such variables, whose value is initialized once at the time of declaration and cannot be changed later.</p>
<p>Example:</p>
<pre><code class="language-javascript">const count = 10;

console.log(count); // 10

count = 20; // Error: Uncaught SyntaxError: 
            // Identifier 'count' has already been declared
</code></pre>
<p>Before using const, make sure that the value of the variable will not change.</p>
<h3>Declaring a variable with the var keyword</h3>
<p>var is an old way of declaring variables, which has been replaced in modern JavaScript by let and const.</p>
<pre><code class="language-javascript">var count = 10;

console.log(count); // 10

count = 20;

console.log(count) // 20
</code></pre>
<p>The value can also be initialized/updated later as seen in the above example.</p>
<h3>Rules for variable names</h3>
<ul>
<li>Should start with a letter, <code>_</code> or <code>$</code> . Cannot start with a number.</li>
</ul>
<pre><code class="language-javascript">const name = "Ashish";
const $age = 20;
const $gender = 'M';

const 1age = 10; ❌
</code></pre>
<ul>
<li>Cannot Contain Spaces</li>
</ul>
<pre><code class="language-javascript">const first name = "Ashish"; ❌
</code></pre>
<ul>
<li>Only Letters, Numbers, <code>_</code>, and <code>$</code> Allowed</li>
</ul>
<pre><code class="language-javascript">const first_name = "Ashish";
const profileLink1 = 'https://www.ashishkumarsaini.dev';

const profileLink-2 = 'https://linkedin.com/in/devaksaini/'; ❌
</code></pre>
<ul>
<li><p>Cannot use reserved JavaScript keywords</p>
</li>
<li><p>Case sensitive</p>
</li>
</ul>
<pre><code class="language-javascript">const value = 10;
const valuE = 20;
const VALUE = 30;

console.log(value); // 10
console.log(valuE); // 20
console.log(VALUE); // 30
</code></pre>
<h2>What are datatypes?</h2>
<p>We understand that there are boxes to store something, which we call variables. But what are we going to store in that box?</p>
<p>Imagine you have a box where you store something, like apples.</p>
<ul>
<li><p>The box → is the variable</p>
</li>
<li><p>The label on the box → is the variable name</p>
</li>
<li><p>The item inside the box → is the value</p>
</li>
</ul>
<p>Here, apple is a datatype. Similarly, we can store multiple types of things in the boxes.</p>
<p>In JS, we call them datatypes.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696877fccb285855f0758646/78bdfbfd-ff61-415f-bf22-f9d2e987e68d.png" alt="" style="display:block;margin:0 auto" />

<p>There are two types of datatypes:</p>
<ol>
<li><p>Primitive Datatypes</p>
</li>
<li><p>Non-primitive Datatypes</p>
</li>
</ol>
<h3>Primitive Datatypes</h3>
<p>Think of a primitive data type as simple values stored inside the variable. Primitive datatypes are immutable, meaning their value can be replaced but not changed directly.</p>
<blockquote>
<p><em>Note: You might get confused here about the immutability of the datatype.</em></p>
<p><em>Here we are talking about the immutability of datatype not variable. Variable themselves are mutable.</em></p>
<p><em>You cannot alter the number 5 to make it 6. Instead you replace the value of variable containing 5 to 6.</em></p>
<pre><code class="language-javascript">let a = 'apple'; // the value 'apple' will always 
                 // be 'apple'. datatype is immutable
a = 'orange';    // new value 'orange' re-assign to 
                 // variable. variable is mutable
</code></pre>
</blockquote>
<p>There are multiple primitive datatypes:</p>
<h3>Number</h3>
<p>Used to store <strong>numeric values</strong> (integers or decimals).</p>
<pre><code class="language-javascript">const count1 = 10;
const count2 = 2.5;
const count2 = -10;

console.log(count1); // output: 10
console.log(count2); // output: 2.5
console.log(count2); // output: -10

console.log(typeof count1); // 'number'
</code></pre>
<h3>String</h3>
<p>User to store text values.</p>
<pre><code class="language-javascript">const text1 = 'Hey, this is a text';
const text2 = `2 + 3 = ${2+3}`; // template literals

console.log(text1); // output: 'Hey, this is a text'
console.log(text2); // output: '2 + 3 = 5'

console.log(typeof text1); // 'string'
</code></pre>
<h3>Boolean</h3>
<p>Use to store true or false.</p>
<pre><code class="language-javascript">const isRegistered = true;
const isLoggedIn = false;

console.log(isRegistered); // output: true
console.log(isLoggedIn); // output: false

console.log(typeof isRegistered); // 'boolean'
</code></pre>
<h3>BigInt</h3>
<p>Used to store large numbers beyond the number limits. Adding <code>n</code> to an integer literal makes it BigInt. It is used to represent numbers larger than <code>Number.MAX_SAFE_INTEGER</code><br /><code>(2^53 − 1 → 9007199254740991).</code></p>
<pre><code class="language-javascript">const count = 123456n;

console.log(count); // 123456n

console.log(typeof count); // 'bigint'
</code></pre>
<h3>Undefined</h3>
<p>Undefined is defined as having no value.</p>
<pre><code class="language-javascript">let sum;

console.log(sum); // output: undefined

console.log(typeof sum); // 'boolean'
</code></pre>
<h3>Null</h3>
<p>Null is defined as having an empty value.</p>
<pre><code class="language-javascript">let count = null;

console.log(count); // output: null

console.log(typeof count); // 'object'
</code></pre>
<h2>What is the scope in JS?</h2>
<p>Scope defines where a variable can be accessed in a program.</p>
<p>Real World Analogy:</p>
<ul>
<li><p>Some things are placed inside each room of your house.</p>
</li>
<li><p>Some things are placed in the common area of all rooms.</p>
</li>
</ul>
<p>Types of scope:</p>
<ol>
<li><p>Block scope (<code>let</code> and <code>const</code>): Variables that are declared in any block or we can say inside any <code>{}</code> (curly braces).</p>
</li>
<li><p>Function scope: Variables declared inside a function can only be used inside that function.</p>
</li>
<li><p>Global Scope: Variable which are declared outside of a block or function scope. It will be accessible to all functions and blocks.</p>
</li>
</ol>
<pre><code class="language-markdown">_________________________________________________________________
| const name = 'Pankaj';  // global variable                    |
| const age = 25;         // global variable                    |
|                                                               |
| if(age == 25) {                                               |
|                                                               |
| ---------Block Scope-----------------                         |
| |                                    |                        |
| | const isSubscriber = true;         | isSubscriber will only |
| | console.log(isSubscriber); // true | accessible inside this |
| |                                    | block                  |
| |                                    |                        |
| | console.log(name); // Pankaj       | name is accessible.    |
| |                                    | as global variable.    |
| --------------------------------------                        |
|                                                               |
| }                                                             |
|                                                               |
|                                                               |
| function sum() {                                              |
|                                                               |
| -------Function Scope-----------------                        |
| |                                    |                        |
| | const isVerified = false;          | isVerified will only   |        
| | console.log(isVerified); // false  | accessible inside this |
| |                                    | function               |
| |                                    |                        |
| | console.log(age); // 25            | age is accessible.     |
| |                                    | as global variable     |
| --------------------------------------                        |
|                                                               |
| }                                                             |
|                                                               |
|                                                               |
| console.log(name); // Pankaj                                  |
| console.log(age); // 25                                       | 
|                                                               |                                              
| console.log(isSubscriber); ❌ Uncaught ReferenceError:        |
|                               isSubscriber is not defined     |
| console.log(isVerified);   ❌ Uncaught ReferenceError:        |
|                               isVerified is not defined       |
|                                                               |
-----------------------------------------------------------------
</code></pre>
<p><strong>Variables and Datatypes</strong> are the fundamental topics to learn before starting learning any language. Understanding and practicing the topics that we have covered in this blog will help you with further topics.</p>
<p>Assignment for practice:</p>
<p>Open the console in the devtools of any browser by right-clicking on any page (in most of the browsers, ex: Chrome) and selecting the Inspect option.</p>
<p>Try to create the variables mentioned below:</p>
<ol>
<li><p>name</p>
</li>
<li><p>age</p>
</li>
<li><p>isStudent</p>
</li>
</ol>
<p>Try to play around using let, var, and const to declare variables and changing the declared type from var -&gt; let, let -&gt; const, and observe the behaviour changes of each declaration type.</p>
<p>Also, try to put them in a block and access those variables outside the block to see the errors in real-time.</p>
<p>Follow this series to learn more about Javascript!</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Operators]]></title><description><![CDATA[When we start learning JS, after variables, we first encounter the operators. When some variables are declared, you need to perform some operations on those variables. Operators help to do some calcul]]></description><link>https://blog.ashishkumarsaini.dev/javascript-operators</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/javascript-operators</guid><category><![CDATA[Js operators]]></category><category><![CDATA[#Beginner Js]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sun, 22 Feb 2026 21:29:38 GMT</pubDate><enclosure url="https://cloudmate-test.s3.us-east-1.amazonaws.com/uploads/covers/696877fccb285855f0758646/10f09c86-f4eb-4161-b306-8af41a3b77ef.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we start learning JS, after variables, we first encounter the operators. When some variables are declared, you need to perform some operations on those variables. Operators help to do some calculations, comparisons, or make decisions on variables.</p>
<p>In this blog, we will understand operators with simple examples.</p>
<h2>What are Operators?</h2>
<p>Operators are nothing but the symbols that perform operations. Let's take an example:</p>
<pre><code class="language-javascript">const a = 10;
const b = 20;

const c = a + b;

console.log(c); // 30
</code></pre>
<p>Here, <code>+</code> is the operator.</p>
<h2>What are Operands?</h2>
<p>Variables on which operation is done, are called operands.</p>
<pre><code class="language-javascript">const a = 10;
const b = 20;

const c = a + b;
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>a</code> is left operand</p>
</li>
<li><p><code>b</code> is right operand</p>
</li>
</ul>
<h3>Types of Operators</h3>
<p>In JS, there are multiple types of operators, but we will cover the basic, mandatory operators in this blog.</p>
<ol>
<li><p>Arithmetic operators (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>)</p>
</li>
<li><p>Comparison operators (<code>==</code>, <code>===</code>, <code>!=</code>, <code>&gt;</code>, <code>&lt;</code> , <code>&gt;=</code>, <code>&lt;=</code> )</p>
</li>
<li><p>Logical operators (<code>&amp;&amp;</code>, <code>||</code>, <code>!</code>)</p>
</li>
<li><p>Assignment operators (<code>=</code>, <code>+=</code>, <code>-=</code>)</p>
</li>
</ol>
<p>Let's understand them one by one:</p>
<h2>Arithmetic Operators</h2>
<p>These are used for basic mathematical operations.</p>
<table style="min-width:248px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="width:173px"></col></colgroup><tbody><tr><th><p>Operator</p></th><th><p>Meaning</p></th><th><p>Expression</p></th><th><p>Result</p></th></tr><tr><td><p>+</p></td><td><p>Addition</p></td><td><p>9 + 3</p></td><td><p>12</p></td></tr><tr><td><p>-</p></td><td><p>Substraction</p></td><td><p>9 - 3</p></td><td><p>6</p></td></tr><tr><td><p>*</p></td><td><p>Multiplication</p></td><td><p>9 * 3</p></td><td><p>27</p></td></tr><tr><td><p>/</p></td><td><p>Division</p></td><td><p>9 / 3</p></td><td><p>3</p></td></tr><tr><td><p>%</p></td><td><p>Remainder</p></td><td><p>10 % 3</p></td><td><p>1</p></td></tr></tbody></table>

<h2>Comparison operators</h2>
<p>These operators are used for comparison between two values and return a Boolean (true/false) value.</p>
<table style="min-width:100px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><th><p>Operator</p></th><th><p>Meaning</p></th><th><p>Expression</p></th><th><p>Example</p></th></tr><tr><td><p>==</p></td><td><p>Equals (loose comparison)</p></td><td><p>"5" == 5</p></td><td><p>true</p></td></tr><tr><td><p>===</p></td><td><p>Equals (strict comparison)</p></td><td><p>"5" === 5</p></td><td><p>false</p></td></tr><tr><td><p>!=</p></td><td><p>Not equal (loose comparison)</p></td><td><p>"5" != 5</p></td><td><p>false</p></td></tr><tr><td><p>!==</p></td><td><p>Not equal (strict comparison)</p></td><td><p>"5" !== 5</p></td><td><p>true</p></td></tr><tr><td><p>&lt;</p></td><td><p>Less than</p></td><td><p>5 &lt; 10<br />5 &lt; 5</p></td><td><p>true<br />false</p></td></tr><tr><td><p>&lt;=</p></td><td><p>Less than or equal to</p></td><td><p>5 &lt;= 10<br />5 &lt;= 5</p></td><td><p>true<br />true</p></td></tr><tr><td><p>&gt;</p></td><td><p>Greater than</p></td><td><p>5 &gt; 2<br />5 &gt; 5</p></td><td><p>true<br />false</p></td></tr><tr><td><p>&gt;=</p></td><td><p>Greater than or equal to</p></td><td><p>5 &gt;= 2<br />5 &gt;= 5</p></td><td><p>true<br />true</p></td></tr></tbody></table>

<p>Understanding loose and strict comparison is very important.</p>
<p>Why <code>"5" == 5</code> gives a result of <code>true</code>?</p>
<p>When there is <code>==</code> operator, JS first converts the value to the same type before comparison.</p>
<p>Which means "5" (string) is first converted to 5 (number) and then <code>5 == 5</code> comparison gives <code>true</code> result.</p>
<p>Whereas in <code>===</code> strict comparison, JS does not change the type of both left and right operands and compares both the type and value.</p>
<p>On the left side, there is a string operand and on the right side, there is a number operand. That's why in a strict case it will give a <code>false</code> result.</p>
<h2>Logical operators</h2>
<p>These operators help in combining the conditions.</p>
<ul>
<li><p><strong>&amp;&amp;</strong><br />This is also known as AND operator.  </p>
<p><strong>Truthy Table</strong></p>
<table style="min-width:100px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><th><p>A</p></th><th><p>B</p></th><th><p>Expression</p></th><th><p>Result</p></th></tr><tr><td><p>true</p></td><td><p>true</p></td><td><p>true &amp;&amp; true</p></td><td><p>true</p></td></tr><tr><td><p>false</p></td><td><p>true</p></td><td><p>false &amp;&amp; true</p></td><td><p>false</p></td></tr><tr><td><p>true</p></td><td><p>false</p></td><td><p>true &amp;&amp; false</p></td><td><p>false</p></td></tr><tr><td><p>false</p></td><td><p>false</p></td><td><p>false &amp;&amp; false</p></td><td><p>false</p></td></tr></tbody></table>

<p>By analysing the truthy table, we can see that even if one side of expression is false, the final result is false. In order to get true, both side values should be true.</p>
</li>
<li><p><code>||</code><br />This is also known as OR operator  </p>
<p><strong>Truthy Table</strong></p>
<table style="min-width:100px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><th><p>A</p></th><th><p>B</p></th><th><p>Expression</p></th><th><p>Result</p></th></tr><tr><td><p>true</p></td><td><p>true</p></td><td><p>true || true</p></td><td><p>true</p></td></tr><tr><td><p>false</p></td><td><p>true</p></td><td><p>false || true</p></td><td><p>true</p></td></tr><tr><td><p>true</p></td><td><p>false</p></td><td><p>true || false</p></td><td><p>true</p></td></tr><tr><td><p>false</p></td><td><p>false</p></td><td><p>false || false</p></td><td><p>false</p></td></tr></tbody></table>

<p>Here we can see that if either side of the operator is true, the final result will be true. Only in the case of both sides of values to being false gives the false result.</p>
</li>
<li><p><strong>!</strong><br />This is known as the NOT operator. As the name suggests, it reverses the given value.  </p>
<p><strong>Truthy Table</strong></p>
<table style="min-width:75px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><th><p>A</p></th><th><p>Expression</p></th><th><p>Result</p></th></tr><tr><td><p>true</p></td><td><p>!true</p></td><td><p>false</p></td></tr><tr><td><p>false</p></td><td><p>!false</p></td><td><p>true</p></td></tr></tbody></table></li>
</ul>
<h2>Assignment Operators</h2>
<p>These operators are used to assign values to variables.</p>
<ul>
<li><strong>=</strong><br />This is known as assign operator. It is used to assign a value to a variable.</li>
</ul>
<pre><code class="language-javascript">let a;

a = 10;

console.log(a); // prints 10
</code></pre>
<ul>
<li><strong>+=</strong><br />This is known as Add and assign operator</li>
</ul>
<pre><code class="language-javascript">let a;

a = 10;

console.log(a); // prints 10

a += 5; // Adding 5 to a variable value and assing back

console.log(a) // prints 15
</code></pre>
<ul>
<li><strong>-=</strong><br />This is known as the Subtract and assign operator</li>
</ul>
<pre><code class="language-javascript">let a;

a = 10;

console.log(a); // prints 10

a -= 5; // Subtracy 5 from the variable value and assing back

console.log(a) // prints 5
</code></pre>
<h3></h3>
<p>Final thoughts</p>
<p>JavaScript operators are the building blocks of logic and calculations in your code. Mastering these will make your JavaScript journey much easier.  </p>
<p>To learn JS from fundamentals to advanced, follow this series <a href="https://blog.ashishkumarsaini.dev/series/javascript-for-beginners">https://blog.ashishkumarsaini.dev/series/javascript-for-beginners</a></p>
]]></content:encoded></item><item><title><![CDATA[CSS Selectors 101: Targeting Elements with Precision]]></title><description><![CDATA[Why CSS Selectors Are Needed
HTML creates elements, but CSS needs a way to choose which elements to style.
CSS selectors are the “targeting system” of CSS.
Without selectors:

CSS wouldn’t know where to apply styles

Every rule would apply to everyth...]]></description><link>https://blog.ashishkumarsaini.dev/css-selectors-101</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/css-selectors-101</guid><category><![CDATA[css selectors]]></category><category><![CDATA[css_selector]]></category><category><![CDATA[css selectors and positions]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sun, 01 Feb 2026 15:36:06 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-why-css-selectors-are-needed">Why CSS Selectors Are Needed</h2>
<p>HTML creates <strong>elements</strong>, but CSS needs a way to <strong>choose which elements to style</strong>.</p>
<p><strong>CSS selectors are the “targeting system” of CSS</strong>.</p>
<p>Without selectors:</p>
<ul>
<li><p>CSS wouldn’t know <strong>where</strong> to apply styles</p>
</li>
<li><p>Every rule would apply to everything (chaos 😄)</p>
</li>
</ul>
<h3 id="heading-real-world-analogy-addressing-people">Real-World Analogy (Addressing People)</h3>
<p>Think of sending messages:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Selector</td><td>Real-world meaning</td></tr>
</thead>
<tbody>
<tr>
<td>Element</td><td>“Hey everyone wearing a T-shirt”</td></tr>
<tr>
<td>Class</td><td>“Hey everyone in Team Blue”</td></tr>
<tr>
<td>ID</td><td>“Hey Rahul (only one person)”</td></tr>
</tbody>
</table>
</div><p>CSS works the same way — selectors help you <strong>pick exactly who should receive the styles</strong>.</p>
<h2 id="heading-element-selector">Element Selector</h2>
<p>The <strong>simplest selector</strong> — targets <strong>all elements of a given type</strong>.</p>
<h3 id="heading-syntax">Syntax</h3>
<pre><code class="lang-xml">p {
  color: blue;
}
</code></pre>
<h3 id="heading-what-it-targets">What it targets</h3>
<p><strong>All</strong> <code>&lt;p&gt;</code> elements on the page</p>
<h3 id="heading-before-after-example">Before / After Example</h3>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>CSS is fun<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><strong>Result</strong></p>
<ul>
<li>Both paragraphs turn <strong>blue</strong></li>
</ul>
<p>Use element selectors when:</p>
<ul>
<li><p>You want a <strong>global style</strong></p>
</li>
<li><p>Example: all <code>p</code>, <code>h1</code>, <code>button</code></p>
</li>
</ul>
<h2 id="heading-class-selector">Class Selector</h2>
<p>A <strong>class selector</strong> targets elements with a specific class name.</p>
<h3 id="heading-syntax-1">Syntax</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.highlight</span> {
  <span class="hljs-attribute">background-color</span>: yellow;
}
</code></pre>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"highlight"</span>&gt;</span>Important text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Normal text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-what-it-targets-1">What it targets</h3>
<p>Only elements with <code>class="highlight"</code></p>
<p>Key points:</p>
<ul>
<li><p>Classes are <strong>reusable</strong></p>
</li>
<li><p>Multiple elements can share the same class</p>
</li>
</ul>
<p>Think of it as style, everyone who belongs to this group</p>
<h3 id="heading-id-selector">ID Selector</h3>
<p>An <strong>ID selector</strong> targets <strong>one unique element</strong>.</p>
<h3 id="heading-syntax-2">Syntax</h3>
<pre><code class="lang-css"><span class="hljs-selector-id">#main-title</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">32px</span>;
}
</code></pre>
<h3 id="heading-html-1">HTML</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"main-title"</span>&gt;</span>Welcome<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<h3 id="heading-what-it-targets-2">What it targets</h3>
<p>Only the element with <code>id="main-title"</code></p>
<p>Rules of ID:</p>
<ul>
<li><p>Must be <strong>unique</strong></p>
</li>
<li><p>Use for <strong>important, single elements</strong></p>
</li>
<li><p>Example: headers, layouts, root containers</p>
</li>
</ul>
<h2 id="heading-group-selectors">Group Selectors</h2>
<p>Group selectors let you <strong>apply the same style to multiple selectors</strong>.</p>
<h3 id="heading-syntax-3">Syntax</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span>, <span class="hljs-selector-tag">h2</span>, <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-family</span>: Arial;
}
</code></pre>
<h3 id="heading-what-it-means">What it means</h3>
<p>Apply the same style to <strong>all h1, h2, and p elements</strong></p>
<p>Why useful?</p>
<ul>
<li><p>Avoid repetition</p>
</li>
<li><p>Cleaner, shorter CSS</p>
</li>
</ul>
<h2 id="heading-descendant-selectors">Descendant Selectors</h2>
<p>Descendant selectors target elements <strong>inside other elements</strong>.</p>
<h3 id="heading-syntax-4">Syntax</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">color</span>: green;
}
</code></pre>
<h3 id="heading-html-2">HTML</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This will be green<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This will NOT be green<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-what-it-means-1">What it means</h3>
<p>“Style <code>&lt;p&gt;</code> only if it is <strong>inside a</strong> <code>&lt;div&gt;</code>”</p>
<p>This is how CSS understands <strong>structure and hierarchy</strong>.</p>
<h2 id="heading-basic-selector-priority-very-high-level">Basic Selector Priority (Very High Level)</h2>
<p>When multiple selectors target the same element, CSS follows <strong>priority</strong> (specificity).</p>
<h3 id="heading-simple-order-for-beginners">Simple order (for beginners)</h3>
<pre><code class="lang-xml">Element <span class="hljs-tag">&lt; <span class="hljs-attr">Class</span> &lt; <span class="hljs-attr">ID</span></span>
</code></pre>
<h3 id="heading-example">Example</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">color</span>: red;
}

<span class="hljs-selector-class">.text</span> {
  <span class="hljs-attribute">color</span>: blue;
}

<span class="hljs-selector-id">#unique</span> {
  <span class="hljs-attribute">color</span>: green;
}
</code></pre>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"unique"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Hello<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Final color: <strong>green</strong> (ID wins)</p>
<p>Don’t memorize formulas yet — just remember, <strong>More specific selector = higher priority.</strong></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>CSS selectors are the <strong>foundation of all styling in CSS</strong>. They define <em>what</em> gets styled before you even think about <em>how</em> it looks. From simple element selectors to more targeted class and ID selectors, every CSS rule begins with choosing the right elements.</p>
<p>By understanding selectors as <strong>ways to address elements</strong>—just like calling out people by role, group, or name—you build a strong mental model of how CSS works behind the scenes. Starting with element selectors, moving to classes, and then IDs helps you write <strong>clean, predictable, and maintainable CSS</strong>.</p>
<p>Once selectors are clear, advanced topics like layouts, animations, and responsive design become much easier. Master selectors first, and the rest of CSS will feel far less overwhelming.</p>
]]></content:encoded></item><item><title><![CDATA[Emmet for HTML: A Beginner’s Guide to Writing Faster Markup]]></title><description><![CDATA[What is Emmet?
Emmet is a shorthand syntax that expands into full HTML code.
Instead of writing long HTML tags manually, you just write the shorthand and you code editor (in this blog we are using VS code) automatically converts the shorthand into th...]]></description><link>https://blog.ashishkumarsaini.dev/emmet-for-beginners</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/emmet-for-beginners</guid><category><![CDATA[learn-emmet]]></category><category><![CDATA[Emmet]]></category><category><![CDATA[html emmet]]></category><category><![CDATA[emmet for html, vscode emmet]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sun, 01 Feb 2026 10:19:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769892330239/2c336378-95e8-4992-af23-a2c9b989f08c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-emmet">What is Emmet?</h2>
<p>Emmet is a shorthand syntax that expands into full HTML code.</p>
<p>Instead of writing long HTML tags manually, you just write the shorthand and you code editor (in this blog we are using VS code) automatically converts the shorthand into the full html code.</p>
<p>In one line, Emmet lets you think in structure, not syntax.</p>
<p>You describe what you want, and Emmet writes it for you.</p>
<h2 id="heading-understanding-the-real-pain-point-why-writing-html-feels-slow">Understanding the real pain point ( why writing HTML feels slow)</h2>
<p>Imagine you want to create a simple card layout.</p>
<h3 id="heading-without-emmet-manual-html">Without Emmet (Manual HTML)</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Description text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Read more<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>You had to:</p>
<ul>
<li><p>Type every tag</p>
</li>
<li><p>Close every tag</p>
</li>
<li><p>Indent manually</p>
</li>
<li><p>Ensure structure is correct</p>
</li>
</ul>
<p>Now imagine doing this 20 times a day.</p>
<p>That’s where Emmet comes in picture. Same thing in emmet:</p>
<pre><code class="lang-xml">div.card&gt;h2+p+a
</code></pre>
<p>Press <strong>Tab / Enter</strong> →</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>You typed 18 characters instead of 150+.</p>
<h2 id="heading-why-emmet-is-extremely-helpful-for-html-beginners">Why Emmet Is Extremely Helpful for HTML Beginners</h2>
<p>For beginners, Emmet:</p>
<ul>
<li><p>Reduces typing fatigue</p>
</li>
<li><p>Prevents missing closing tags</p>
</li>
<li><p>Forces you to think in HTML structure</p>
</li>
<li><p>Makes nesting obvious</p>
</li>
<li><p>Improves learning speed</p>
</li>
</ul>
<h2 id="heading-how-emmet-works-inside-code-editors">How Emmet Works Inside Code Editors</h2>
<p>Emmet is built into most modern editors (VS Code recommended).</p>
<p>How it works:</p>
<ol>
<li><p>You type an Emmet abbreviation</p>
</li>
<li><p>The editor recognizes it</p>
</li>
<li><p>You press <strong>Tab</strong> or <strong>Enter</strong></p>
</li>
<li><p>HTML code is generated instantly</p>
</li>
</ol>
<h2 id="heading-emmet-is-a-shortcut-language">Emmet Is a Shortcut Language</h2>
<p>Emmet uses symbols to represent HTML relationships.</p>
<h3 id="heading-core-symbols-you-must-know">Core Symbols You Must Know</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Symbol</td><td>Meaning</td><td>Think of it as</td></tr>
</thead>
<tbody>
<tr>
<td><code>&gt;</code></td><td>Child</td><td>“inside”</td></tr>
<tr>
<td><code>+</code></td><td>Sibling</td><td>“next to”</td></tr>
<tr>
<td><code>*</code></td><td>Repeat</td><td>“multiple copies”</td></tr>
<tr>
<td><code>.</code></td><td>Class</td><td>CSS class</td></tr>
<tr>
<td><code>#</code></td><td>ID</td><td>Unique identifier</td></tr>
<tr>
<td><code>[]</code></td><td>Attributes</td><td>Extra info</td></tr>
</tbody>
</table>
</div><p>These symbols are <strong>enough for daily work</strong>.</p>
<h2 id="heading-creating-html-elements-using-emmet">Creating HTML Elements Using Emmet</h2>
<h3 id="heading-single-element">Single Element</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">p
</code></pre>
<p><strong>HTML Output</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-heading-example">Heading Example</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">h1
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>This works for <code>h1</code> to <code>h6</code>.</p>
<h2 id="heading-adding-classes-ids-and-attributes">Adding Classes, IDs, and Attributes</h2>
<h3 id="heading-adding-a-class">Adding a Class (<code>.</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">div.container
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-adding-an-id">Adding an ID (<code>#</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">section#hero
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"hero"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<h3 id="heading-adding-multiple-classes">Adding Multiple Classes</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">div.card.shadow.rounded
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card shadow rounded"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-adding-attributes">Adding Attributes (<code>[]</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">a[href="https://example.com"]
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://example.com"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<h3 id="heading-image-example">Image Example</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">img[src="photo.jpg" alt="profile photo"]
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"photo.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"profile photo"</span>&gt;</span>
</code></pre>
<h2 id="heading-creating-nested-elements-parent-child">Creating Nested Elements (Parent → Child)</h2>
<p>This is where Emmet shines.</p>
<h3 id="heading-basic-nesting-gt">Basic Nesting (<code>&gt;</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">div&gt;p
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-parent-with-multiple-children">Parent With Multiple Children (<code>+</code>)</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">div&gt;h1+p+button
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h2 id="heading-repeating-elements-using-multiplication">Repeating Elements Using Multiplication (<code>*</code>)</h2>
<h3 id="heading-list-example">List Example</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">ul&gt;li*3
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<h3 id="heading-cards-example">Cards Example</h3>
<p><strong>Emmet</strong></p>
<pre><code class="lang-xml">div.card*4
</code></pre>
<p><strong>HTML</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h2 id="heading-combining-nesting-repetition-real-layout">Combining Nesting + Repetition (Real Layout)</h2>
<h3 id="heading-emmet">Emmet</h3>
<pre><code class="lang-xml">ul&gt;li.item*3&gt;a
</code></pre>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>This is real-world HTML, generated in seconds.</p>
<h2 id="heading-generating-full-html-boilerplate">Generating Full HTML Boilerplate</h2>
<p>Instead of Writing This Manually</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-just-type-this">Just Type This 👇</h3>
<pre><code class="lang-xml">!
</code></pre>
<p>or</p>
<pre><code class="lang-xml">html:5
</code></pre>
<p>Press Enter → 🎉<br />Complete boilerplate generated.</p>
<p>This is one of the <strong>most used Emmet shortcuts ever</strong>.</p>
<h2 id="heading-side-by-side-emmet-html">Side-by-Side: Emmet → HTML</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Emmet</td><td>Result</td></tr>
</thead>
<tbody>
<tr>
<td><code>p</code></td><td><code>&lt;p&gt;&lt;/p&gt;</code></td></tr>
<tr>
<td><a target="_blank" href="http://div.box"><code>div.box</code></a></td><td><code>&lt;div class="box"&gt;&lt;/div&gt;</code></td></tr>
<tr>
<td><code>section#home</code></td><td><code>&lt;section id="home"&gt;&lt;/section&gt;</code></td></tr>
<tr>
<td><code>ul&gt;li*3</code></td><td>3 list items</td></tr>
<tr>
<td><code>div&gt;h1+p</code></td><td>Nested structure</td></tr>
</tbody>
</table>
</div><h2 id="heading-emmet-tips-for-beginner">Emmet tips for Beginner</h2>
<ul>
<li><p>Learn HTML first, Emmet second</p>
</li>
<li><p>Use Emmet for daily patterns</p>
</li>
<li><p>Don’t memorize everything</p>
</li>
<li><p>Practice after every example</p>
</li>
<li><p>Emmet is optional, but life-changing</p>
</li>
</ul>
<h2 id="heading-final-thought">Final Thought</h2>
<p>Emmet doesn’t replace HTML knowledge.<br />It <strong>amplifies it</strong>.</p>
<p>Once Emmet becomes muscle memory:</p>
<ul>
<li><p>Writing HTML feels instant</p>
</li>
<li><p>Layout building becomes fun</p>
</li>
<li><p>Your speed increases naturally</p>
</li>
</ul>
<p>HTML teaches structure. Emmet removes friction.</p>
]]></content:encoded></item><item><title><![CDATA[HTML Basics – Understanding the Structure of a Webpage]]></title><description><![CDATA[What is HTML and Why Do We Use It?
HTML (HyperText Markup Language) is the standard language used to create web pages.
When you open any website, the basic structure of that page is written in HTML. It is also known as the skeleton of any webpage.
Si...]]></description><link>https://blog.ashishkumarsaini.dev/html-basics</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/html-basics</guid><category><![CDATA[HTML5]]></category><category><![CDATA[HTML]]></category><category><![CDATA[basic html]]></category><category><![CDATA[html for beginners]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 31 Jan 2026 20:27:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769883230362/d7a7866b-fcc2-4a26-bbb7-f857768256f5.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-html-and-why-do-we-use-it">What is HTML and Why Do We Use It?</h2>
<p>HTML (HyperText Markup Language) is the standard language used to create web pages.</p>
<p>When you open any website, the basic structure of that page is written in HTML. It is also known as the skeleton of any webpage.</p>
<h3 id="heading-simple-analogy">Simple Analogy</h3>
<p>Think of building a house:</p>
<ul>
<li><p>HTML → Structure of the house (walls, doors, rooms)</p>
</li>
<li><p>CSS → Paint &amp; decoration (colors, design)</p>
</li>
<li><p>JavaScript → Electricity &amp; automation (interaction, behavior)</p>
</li>
</ul>
<p>Without HTML, a browser would not be able to know:</p>
<ul>
<li><p>Which is heading</p>
</li>
<li><p>From where the paragraph starts</p>
</li>
<li><p>Where an image should appear</p>
</li>
<li><p>Cannot differentiate between a link and plain text</p>
</li>
</ul>
<p>HTML gives meaning and structure to content so browsers can display it properly.</p>
<h2 id="heading-what-is-an-html-tag">What is an HTML Tag?</h2>
<p>An HTML tag is a special keyword written inside angle brackets <code>&lt; &gt;</code>.</p>
<p>Example:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>A tag acts like a label or instruction to the browser.</p>
<p>It tells the browser:</p>
<ul>
<li><p>From where the element starts</p>
</li>
<li><p>Where it ends</p>
</li>
<li><p>What type of element is it</p>
</li>
</ul>
<p>Tags themselves are not displayed on the webpage. They only guide the browser on which element and how the element should be displayed.</p>
<h2 id="heading-opening-tag-closing-tag-and-content">Opening Tag, Closing Tag, and Content</h2>
<p>Most HTML tags come in pairs:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Let’s break it down:</p>
<p><strong>Opening Tag:</strong> This is defined as a tag that tells the browser where an element starts.</p>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">p</span>&gt;
</code></pre>
<p><strong>Content:</strong> It is actually the content which comes in between the tags. It is actually displayed on the web page in the browser.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">Hello</span> <span class="hljs-selector-tag">World</span>
</code></pre>
<p><strong>Closing Tag:</strong> This tells the browser that this is the end of the element. The <strong>forward slash</strong> <code>/</code> is what makes it a closing tag.</p>
<pre><code class="lang-css">&lt;/<span class="hljs-selector-tag">p</span>&gt;
</code></pre>
<p>Closing tag is very important as the browser might get confused that till where the content is and mix other tags, which leads to incorrect and mixed layout issues.</p>
<h2 id="heading-what-is-an-html-element">What is an HTML Element?</h2>
<p>This is where beginners often get confused.</p>
<h3 id="heading-tag-vs-element">Tag vs Element</h3>
<p><strong>Tag</strong> → Only the keyword inside brackets<br /><strong>Element</strong> → The <strong>entire structure,</strong> including opening tag, content, and closing tag.</p>
<p>Example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769889485624/6e270b84-be90-4d18-a271-7519177222ff.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><code>&lt;p&gt;</code> = Opening Tag</p>
</li>
<li><p><code>&lt;/p&gt;</code> = Closing Tag</p>
</li>
<li><p><code>&lt;p&gt;Hello world&lt;/p&gt;</code> = <strong>Element</strong></p>
</li>
</ul>
<p>So an element is a complete unit, while a tag is just a part of it.</p>
<p>In the real world analogy, imagine a box:</p>
<ul>
<li><p>Opening tag → opening the box</p>
</li>
<li><p>Content → items inside the box</p>
</li>
<li><p>Closing tag → closing the box</p>
</li>
<li><p>Entire box → element</p>
</li>
</ul>
<h2 id="heading-self-closing-void-elements">Self-Closing (Void) Elements</h2>
<p>Some HTML elements do not wrap any content, so they do not need closing tags.</p>
<p>Examples:</p>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">img</span> <span class="hljs-selector-tag">src</span>="<span class="hljs-selector-tag">photo</span><span class="hljs-selector-class">.jpg</span>"&gt;
&lt;<span class="hljs-selector-tag">br</span>&gt;
&lt;<span class="hljs-selector-tag">hr</span>&gt;
&lt;<span class="hljs-selector-tag">input</span> <span class="hljs-selector-tag">type</span>="<span class="hljs-selector-tag">text</span>"&gt;
</code></pre>
<p>These are called Void Elements.</p>
<h3 id="heading-why-they-exist">Why They Exist</h3>
<p>They perform single actions, such as:</p>
<ul>
<li><p>Displaying an image</p>
</li>
<li><p>Creating a line break</p>
</li>
<li><p>Drawing a horizontal line</p>
</li>
<li><p>Creating an input field</p>
</li>
</ul>
<p>These tags do not have content to wrap, that’s why there is no requirement of closing tag.</p>
<h2 id="heading-block-level-vs-inline-elements">Block-Level vs Inline Elements</h2>
<p>HTML elements are mainly divided into two layout categories.</p>
<h3 id="heading-block-level-elements">Block-Level Elements</h3>
<p>Characteristics of block-level elements:</p>
<ul>
<li><p>Take the full width of the screen</p>
</li>
<li><p>Always start on a new line</p>
</li>
<li><p>Used to build a structure</p>
</li>
</ul>
<p>Examples:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>Visually, it will look like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-attr">[Heading          ]</span>
<span class="hljs-selector-attr">[Paragraph        ]</span>
<span class="hljs-selector-attr">[Another Paragraph]</span>
</code></pre>
<p>Even if the content is small, block elements occupy the entire row.</p>
<h3 id="heading-inline-elements">Inline Elements</h3>
<p>Characteristics:</p>
<ul>
<li><p>Take only the required width</p>
</li>
<li><p>Do not start on a new line</p>
</li>
<li><p>Used inside text</p>
</li>
</ul>
<p>Examples:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span>
</code></pre>
<p>Visually, it will look like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">This</span> <span class="hljs-selector-tag">is</span> <span class="hljs-selector-tag">a</span> <span class="hljs-selector-attr">[link]</span> <span class="hljs-selector-tag">inside</span> <span class="hljs-selector-tag">a</span> <span class="hljs-selector-tag">sentence</span>.
</code></pre>
<p>Inline elements flow within text, like words in a paragraph.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769891087968/e26eb2e8-36aa-4d52-8cb3-9cc4aa6f1142.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-commonly-used-html-tags">Commonly Used HTML Tags</h2>
<p>Here are the tags beginners should learn first:</p>
<h3 id="heading-headings">Headings</h3>
<p>Used for titles and structure.<br /><code>h1</code> is the largest, <code>h6</code> is the smallest.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Main Title<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Sub Title<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
</code></pre>
<h3 id="heading-paragraph">Paragraph</h3>
<p>Used for writing a paragraph. Denoted by <code>p</code></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-link">Link</h3>
<p>Also known as an anchor tag.<br />It has href attribute that specifies the URL to navigate when clicked.<br />It also has a target attribute used for opening the page in the same browser tab or another tab. It accepts:</p>
<ul>
<li><p><code>_blank</code> → for a new tab</p>
</li>
<li><p><code>_self</code> → for the same tab</p>
</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://example.com"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>Visit Site<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>Creates clickable links.</p>
<h3 id="heading-image">Image</h3>
<p>Use to display images. It has attributes:</p>
<ul>
<li><p>src → source path of the image</p>
</li>
<li><p>alt → until the image gets loaded, it will show the alt text. Useful for accessibility readers</p>
</li>
<li><p>width → for providing a fixed width to the image</p>
</li>
<li><p>height → for providing a fixed height of the image</p>
</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"photo.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"A photo"</span>&gt;</span>
</code></pre>
<h3 id="heading-div-container">Div (Container)</h3>
<p>It is used to wrap any content/tag inside it. It is also known as a wrapper. It is also used to group sections.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Content<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-span-inline-container">Span (Inline Container)</h3>
<p>It is used to render the text, but not like <code>p</code> tag. It doesn’t take full space and also not create a new link for the elements.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Highlighted text<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
<h3 id="heading-lists">Lists</h3>
<p>As the name suggests, it is used to display the lists.</p>
<ol>
<li><p><strong>Ordered lists:</strong> This is used when the order of the items should be displayed. It is done for the semantic purpose. <code>ol</code> tag is used to display an ordered list.</p>
<p> <code>li</code> means list item.</p>
</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ol</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>

Output:

1. Item 1
2. Item 2
</code></pre>
<ol start="2">
<li>Unordered list: This is used when the order of the items doesn’t matter. <code>ul</code> tag is used to display an ordered list.</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>

Output:

* Item 1
* Item 2
</code></pre>
<h3 id="heading-line-break">Line Break</h3>
<p>This is a self-closing tag used to create a new line. Syntax define as <code>&lt;br&gt;</code></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Text 1<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Text 1<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>

Output:

Text 1

Text 2
</code></pre>
<h3 id="heading-horizontal-rule">Horizontal Rule</h3>
<p>This is a self-closing tag used to separate the two contents by displaying a horizontal line. Syntax define as <code>&lt;hr&gt;</code></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Text 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Text 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

Output:

Text 1
-----------------------------------------------------------------
Text 2
</code></pre>
<h2 id="heading-inspect-html">Inspect HTML</h2>
<p>One of the best ways to learn HTML is to see it in real websites.</p>
<h3 id="heading-how-to-inspect">How to Inspect</h3>
<ol>
<li><p>Open any webpage</p>
</li>
<li><p>Right-click → Inspect</p>
</li>
<li><p>Go to the Elements tab</p>
</li>
<li><p>You’ll see live HTML</p>
</li>
</ol>
<p>You can even:</p>
<ul>
<li><p>Edit text</p>
</li>
<li><p>Change colors</p>
</li>
<li><p>Delete elements temporarily</p>
</li>
</ul>
<p>This helps you to understand structure visually.</p>
<h2 id="heading-ia"> </h2>
<p>Final Thoughts</p>
<p>HTML is not programming, it is markup.<br />You are not telling the computer how to think, you are telling the browser how to structure content.</p>
<p>Once HTML is clear, learning CSS and JavaScript becomes much easier because you already understand the foundation of the webpage.</p>
]]></content:encoded></item><item><title><![CDATA[How a Browser Works: A Beginner-Friendly Guide]]></title><description><![CDATA[You have surely worked with the browser every day to access web content but have you ever wonder how the browser works internally?

You type website domain/url in the address bar

You hit enter

and boom, a webpage is displayed


In less than a secon...]]></description><link>https://blog.ashishkumarsaini.dev/beginners-guide-to-browser</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/beginners-guide-to-browser</guid><category><![CDATA[browser]]></category><category><![CDATA[CSSOM Tree]]></category><category><![CDATA[html-parsing]]></category><category><![CDATA[HTML]]></category><category><![CDATA[CSS]]></category><category><![CDATA[browser-rendering]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Sat, 31 Jan 2026 17:43:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769881413519/b8cdb85f-981b-4586-bc5b-70206cd9e6a0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have surely worked with the browser every day to access web content but have you ever wonder how the browser works internally?</p>
<ul>
<li><p>You type website domain/url in the address bar</p>
</li>
<li><p>You hit enter</p>
</li>
<li><p>and boom, a webpage is displayed</p>
</li>
</ul>
<p>In less than a second, a browser has perform a dozens of tasks to display a single webpage.</p>
<p>Assume browser like a factory, when you just told what I need and there are multiple factory workers/machine working together and create a product for you.<br />Browser works the same.</p>
<h3 id="heading-what-happen-you-type-a-url-and-press-enter">What happen you type a URL and press Enter?</h3>
<p>When Enter is pressed:</p>
<ol>
<li><p>Checks in cache:</p>
<p> Browser checks if it already access this site earlier. This check is just to get the IP address of the hosted server</p>
</li>
<li><p>DNS lookup:</p>
<p> If the IP is not available in cache, it request to DNS to get the IP.</p>
</li>
<li><p>TCP connection:</p>
<p> Once the DNS provide the IP, browser start establishing a connection with the server.</p>
</li>
<li><p>Server responds with files.</p>
</li>
<li><p>Browser does its calculations and display the webpage content which comes from the server.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769854280019/c14efe1e-6b24-4417-8562-f8257ca90839.png" alt class="image--center mx-auto" /></p>
<p>In this blog, we mainly focus on the calculations done by the browser from getting data from the server to display page to the viewer.</p>
<h2 id="heading-main-parts-of-a-browser-high-level-overview">Main parts of a browser (high-level overview)</h2>
<p>Browser is not a single program but a team of mini programs working together. Let’s first understand the overview of browser components.</p>
<ul>
<li><p><strong>User Interface:</strong></p>
<p>  It belongs to the component of browser which is visible directly for the interaction with the browser. It include everything expect where the website is displayed. Examples:</p>
<ul>
<li><p>Address bar</p>
</li>
<li><p>Back/forward buttons</p>
</li>
<li><p>Bookmark menu</p>
</li>
<li><p>Settings</p>
</li>
<li><p>Tabs</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769853123219/2aab32fe-c904-489b-9e1f-6ed81b192725.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Browser Engine</strong></p>
<p>  The browser engine is also called the brain/core of the browser. It act as a middleman between the User Interface and the Rendering Engine.</p>
<p>  It receives commands from the browser User Interface and give instructions to the Rendering Engine to do some operations.</p>
</li>
<li><p><strong>Rendering Engine</strong></p>
<p>  It is responsible for displaying the requested content on the screen. It parses the HTML (Hypertext Markup Language) and CSS (Cascading Style Sheet), and combine them to build. We will discuss more about this in details in further sections</p>
</li>
<li><p><strong>Networking Layer</strong></p>
<p>  This component handles all network communications and HTTP requests. It manages DNS lookups (translating URL to IP addresses), handles TCP/IP connections, and fetches resources (HTML, images, CSS) from servers</p>
</li>
<li><p><strong>JavaScript Interpreter</strong></p>
<p>  It is a engine that parses and executes JavaScript code. It interprets, compiles, and runs JavaScript to add interactivity to web pages</p>
</li>
<li><p><strong>Disk API</strong></p>
<p>  As name suggests, it is used to store data in storage which a browser/web page needed. There are multiple components in browser data storage such as Cookies, LocalStorage, SessionStorage, IndexDB, and file system access.</p>
</li>
</ul>
<h3 id="heading-browser-engine-vs-rendering-engine">Browser Engine vs Rendering Engine</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Browser Engine</strong></td><td><strong>Rendering Engine</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Handlers actions between the UI and the rendering engine.</td><td>Parse the request HTML and CSS content and display on the screen</td></tr>
<tr>
<td>Manage task like networking, security and overall rendering process</td><td>Manage creating DOM, CSSOM, frame tree, repaints and painting process</td></tr>
<tr>
<td>Examples: Chromium, Servo</td><td>Example: Blink (Chrome), Webkit (Safari)</td></tr>
</tbody>
</table>
</div><h2 id="heading-how-browser-download-html-css-and-js-files">How browser download HTML, CSS and JS files?</h2>
<ol>
<li><p>The process begins with when a user enters the URL in address bar and press Enter.</p>
</li>
<li><p>Browser perform a DNS look to find the servers IP’s address.</p>
</li>
<li><p>Once browser get the IP, it sends a HTTP GET request to the server.</p>
</li>
<li><p>Browser Networking Layer create a connection for the data transfer.</p>
</li>
<li><p>Now, the browser start receiving the HTML data, the browser engine instructs rendering engine to start parsing the HTML data and build the DOM (Document Object Model)</p>
</li>
<li><p>As it parses the HTML, it founds the tag referencing to the external JS/CSS file links such as <code>&lt;link&gt;</code> or <code>&lt;script&gt;</code></p>
</li>
<li><p>Browser again sends the HTTP request to the corresponding servers of the link for the CSS and JS.</p>
<ul>
<li><p>Once the CSS file is downloaded, the rendering engine starts parsing the CSS and generate a CSSOM (CSS Object Model). Until the CSSOM is created, browser stops rendering the HTML, to avoid rendering the page incorrectly and repaint.</p>
</li>
<li><p>Once JS file is downloaded, the JS Interpreter start compiling the JS downloaded and execute it. By default, the browser stops the parsing of HTML and CSS, but you can change the behaviour by using <code>async/defer</code> attribute in the <code>script</code> tag.</p>
<p>  If you want not to block the CSS and HTML parsing until the JS file get download, use <code>defer</code> otherwise use <code>async</code></p>
</li>
</ul>
</li>
<li><p>Now when all the necessary files has been downloaded, the rendering engine combines the DOM and CSSOM and with all other processing like frame constructor and reflow, it paints and display the web content on the browser.</p>
</li>
</ol>
<h3 id="heading-structural-flow-of-rendering-engine">Structural flow of Rendering Engine</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769858244412/b579f579-9802-4d41-9367-9ccefe6125a0.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-parsing">Parsing</h2>
<h3 id="heading-html-parsing-html-dom-creation">HTML parsing (HTML → DOM creation)</h3>
<p>When the browser receives an HTML file, it first understand the structure instead of directly jump into displaying the content on screen.</p>
<p>Let’s first understand what parsing is?</p>
<p><strong>Parsing</strong> is a way of reading the code, understanding the structure and breaking it into pieces.</p>
<p>In real world analogy, it is same like reading an english sentence from a book, understanding and separating the noun, pronoun, verb and adjectives. A HTML is look like this:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>This is a heading<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Hey, It's me<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>Here, <code>body</code> and <code>div</code> is a container for <code>h1</code> and <code>p</code> tag.</p>
<p>After parsing, the browser creates a tree like structure called Document Object Model (DOM).</p>
<pre><code class="lang-plaintext">      body
      / \
 strong  div
          / \
         h1  p
</code></pre>
<p>It cannot be visualise but in the browser backend, the structure is almost like the above.</p>
<h3 id="heading-css-parsing-cssom-creating">CSS Parsing (CSSOM creating)</h3>
<p>While the HTML builds structure, CSS builds the rules for styling.</p>
<p>Example CSS:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span> { <span class="hljs-attribute">color</span>: blue; }
<span class="hljs-selector-tag">p</span> { <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>; }
</code></pre>
<p>The browser parse CSS by breaking it into the selectors and properties.</p>
<p>This become another tree like structure which called as CSSOM, but instead of elements it stores styling instructions.</p>
<h3 id="heading-dom-cssom-render-tree">DOM + CSSOM → Render Tree</h3>
<p>Now the browser rendering engine has</p>
<ul>
<li><p>Structure (DOM)</p>
</li>
<li><p>Style rules (CSSOM)</p>
</li>
</ul>
<p>It combines them into a render tree. Render tree is something which contains only visible elements and their final styles.</p>
<p>So, in case if the element has <code>display: none</code>, it will not appear in the render tree.</p>
<h2 id="heading-frame-tree-reflow">Frame Tree / Reflow</h2>
<p>Now the browser figures out where everything goes.</p>
<p>It calculates:</p>
<ul>
<li><p>Width</p>
</li>
<li><p>Height</p>
</li>
<li><p>Position</p>
</li>
<li><p>Margins</p>
</li>
<li><p>Padding</p>
</li>
<li><p>Screen size responsiveness</p>
</li>
</ul>
<p>This step is called Layout or Reflow.</p>
<p>Layout changes when window resizes, font load, DOM changes</p>
<h2 id="heading-painting">Painting</h2>
<p>After layout, the browser starts adding visuals:</p>
<ul>
<li><p>Colors</p>
</li>
<li><p>Fonts</p>
</li>
<li><p>Borders</p>
</li>
<li><p>Shadows</p>
</li>
<li><p>Images</p>
</li>
</ul>
<p>At this stage, elements become visually rich but still exist in layers.</p>
<h2 id="heading-display">Display</h2>
<p>At this step the user actually sees the content on the page.</p>
<ul>
<li><p>Layers are merged</p>
</li>
<li><p>Pixels are sent to the screen</p>
</li>
</ul>
<h2 id="heading-conslusion">Conslusion</h2>
<ul>
<li><p>HTML → DOM (Structure)</p>
</li>
<li><p>CSS → CSSOM (Style Rules)</p>
</li>
<li><p>DOM + CSSOM → Render Tree (Visible Elements)</p>
</li>
<li><p>Render Tree → Layout (Measure &amp; Position)</p>
</li>
<li><p>Layout → Paint (Add Colors &amp; Fonts)</p>
</li>
<li><p>Paint → Display (Pixels on Screen)</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Getting Started with cURL]]></title><description><![CDATA[To understand cURL, we should first take a look at what a server is. A server is a powerful computer, software, or virtual machine designed to store, manage, and deliver data, services, or resources to other computers—known as clients—over a network....]]></description><link>https://blog.ashishkumarsaini.dev/getting-started-with-curl</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/getting-started-with-curl</guid><category><![CDATA[curl]]></category><category><![CDATA[cURL for beginner]]></category><category><![CDATA[curl-command]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Fri, 30 Jan 2026 23:08:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769814405138/d8f3013c-08e8-4806-bdfb-3a649b818f0b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To understand cURL, we should first take a look at what a server is. A server is a powerful computer, software, or virtual machine designed to store, manage, and deliver data, services, or resources to other computers—known as clients—over a network. A server will</p>
<ul>
<li><p>stays online 24/7</p>
</li>
<li><p>listens on a port</p>
</li>
<li><p>waits for requests</p>
</li>
<li><p>sends back responses</p>
</li>
</ul>
<p>In a real-world analogy, a server is like a shop counter:</p>
<ul>
<li><p>You (client) ask something from the shopkeeper</p>
</li>
<li><p>The shopkeeper checks</p>
</li>
<li><p>The shopkeeper gives you the thing that you have requested</p>
</li>
</ul>
<p>The internet is just millions of such conversations happening per second.</p>
<h2 id="heading-problems-before-curl-existed">Problems before cURL existed</h2>
<p>To connect to the server, you really need some heavy software like Postman, browsers or you have to write a program.</p>
<p>But what if you just want to:</p>
<ul>
<li><p>Check if a server is alive</p>
</li>
<li><p>see raw response</p>
</li>
<li><p>debug quickly</p>
</li>
</ul>
<p>Then cURL came into the picture to solve the problem of displaying raw data on terminals.</p>
<h2 id="heading-what-is-curl">What is cURL?</h2>
<p>cURL is a tool that allows you to talk to the servers directly from the terminal.</p>
<p>It sends a request to the server same like a browser. The only difference is it doesn’t have any formatting, no UI and no hiddings.</p>
<ul>
<li><p>Browser → need buttons/ui to connect to servers</p>
</li>
<li><p>cURL → uses terminal commands to connect to the servers</p>
</li>
</ul>
<p>It shows raw responses from the servers.</p>
<h3 id="heading-why-programmers-need-curl">Why programmers need cURL</h3>
<p>Both frontend and backend developers need cURL for various purposes:</p>
<p>Backend developers use cURL to:</p>
<ul>
<li><p>Test endpoints before the frontend exists</p>
</li>
<li><p>Debug production APIs</p>
</li>
<li><p>Validate request/response format</p>
</li>
<li><p>Reproduce bugs</p>
</li>
<li><p>Check authentication</p>
</li>
</ul>
<p>cURL sits <strong>between you and the server</strong>:</p>
<ul>
<li><p>Frontend devs use it to test APIs</p>
</li>
<li><p>Backend devs use it to debug endpoints</p>
</li>
<li><p>DevOps uses it to check server health</p>
</li>
</ul>
<h2 id="heading-your-first-request-what-actually-happens">Your first request — what actually happens</h2>
<p>Let’s understand what happens when someone sends a request to a server using cURL:</p>
<p>This <strong>looks simple</strong>, but a LOT happens behind the scenes.</p>
<h3 id="heading-step-by-step-breakdown">Step-by-step breakdown</h3>
<ol>
<li><p>DNS lookup</p>
<ul>
<li>abc.com → IP address</li>
</ul>
</li>
<li><p>Connection</p>
<ul>
<li>TCP connection to the server</li>
</ul>
</li>
<li><p>TLS handshake (for HTTPS)</p>
<ul>
<li>secure channel established</li>
</ul>
</li>
<li><p>HTTP request sent to the server.</p>
</li>
<li><p>Server responds</p>
</li>
<li><p>cURL prints the response from the server</p>
</li>
</ol>
<p>Same happen for the Browser in the backend.</p>
<h2 id="heading-understanding-request-and-response-core-idea">Understanding request and response (core idea)</h2>
<p>Whenever cURL talks to a server, two things happen:</p>
<h3 id="heading-request-you-server">Request (You → Server)</h3>
<ul>
<li><p>What do you want?</p>
</li>
<li><p>Where do you want it from?</p>
</li>
<li><p>How do you want it?</p>
</li>
</ul>
<h3 id="heading-response-server-you">Response (Server → You)</h3>
<ul>
<li><p>Status (success or error)</p>
</li>
<li><p>Data (HTML, JSON, text, etc.)</p>
</li>
</ul>
<h2 id="heading-understanding-http-request-and-response">Understanding HTTP Request and Response</h2>
<p>An HTTP request is a text-based message sent by a client to a server, such as loading a webpage (GET) or submitting a form (POST).</p>
<h3 id="heading-key-components-of-an-http-request">Key Components of an HTTP Request</h3>
<ul>
<li><p><strong>Request Method</strong>: Defines the action type</p>
<ol>
<li><p>GET to retrieve</p>
</li>
<li><p>POST to send</p>
</li>
<li><p>PUT to update</p>
</li>
<li><p>DELETE to remove.</p>
</li>
</ol>
</li>
<li><p><strong>Uniform Resource Identifier (URI)</strong>: The path or address of the resource on the server.</p>
</li>
<li><p><strong>HTTP Version</strong>: (e.g., HTTP/1.1 or HTTP/2).</p>
</li>
<li><p><strong>Headers</strong>: Key-value pairs providing information about the client, content type, or cookies.</p>
</li>
<li><p><strong>Body</strong>: Optional content sent with the request (e.g., form data).</p>
</li>
</ul>
<p>An HTTP response is the data a server sends back to a client after receiving a request containing content like HTML, JS, CSS, images, etc.</p>
<h3 id="heading-key-components-of-an-http-response">Key Components of an HTTP Response</h3>
<ul>
<li><p><strong>Status Code</strong>: A 3-digit code indicating the success/failures.</p>
</li>
<li><p><strong>Response Headers</strong>: Metadata providing details about the content, content type (e.g., <code>Content-Type: text/html</code>).</p>
</li>
<li><p><strong>Message Body</strong>: The actual content requested by the client, such as HTML code, an image file, or JSON data.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769813929762/c2131acb-ee2b-4b62-8506-942f4fa0e6db.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-http-response-status-codes">HTTP response status codes:</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Status codes</strong></td><td><strong>What it means</strong></td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><strong>1xx</strong></td><td>Informational, Request received</td><td>101: used in switching protocols</td></tr>
<tr>
<td><strong>2xx</strong></td><td>Success, Action received and accepted</td><td>201: user created successfully</td></tr>
<tr>
<td><strong>3xx</strong></td><td>Redirection, Further action is needed to complete the request</td><td>307: temporary redirects</td></tr>
<tr>
<td><strong>4xx</strong></td><td>Client Error: Request contains bad syntax or cannot be fulfilled</td><td>401: Unauthorized request from client</td></tr>
<tr>
<td><strong>5xx</strong></td><td>Server Error, Server failed to fulfill a valid request</td><td>503: Service unavailable</td></tr>
</tbody>
</table>
</div><h2 id="heading-get-vs-post-requests">GET vs POST requests</h2>
<ul>
<li><p><strong>Use GET for:</strong></p>
<ul>
<li><p>Fetching information, such as viewing a webpage, product data, or search data, etc.</p>
</li>
<li><p>Operations that are "safe" and do not alter the server's state.</p>
</li>
<li><p>Scenarios where users might want to bookmark or share the URL.</p>
</li>
</ul>
</li>
<li><p><strong>Use POST for:</strong></p>
<ul>
<li><p>Submitting sensitive data like passwords, login credentials, or personal information.</p>
</li>
<li><p>Creating or modifying data on the server, such as posting a comment, registering a new user, or adding an item to a shopping cart.</p>
</li>
<li><p>Uploading files.</p>
</li>
<li><p>Sending a large amount of data.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-using-curl-with-apis-what-apis-really-are">Using cURL with APIs (what APIs really are)</h2>
<p>An API <strong>is just a server</strong> that:</p>
<ul>
<li><p>doesn’t return UI</p>
</li>
<li><p>returns structured data (usually JSON)</p>
</li>
</ul>
<p>So when you do:</p>
<pre><code class="lang-powershell"><span class="hljs-built_in">curl</span> -<span class="hljs-literal">-request</span> GET \
  -<span class="hljs-literal">-url</span> <span class="hljs-string">'https://api.freeapi.app/api/v1/public/randomjokes?limit=1&amp;query=sciencepage=1'</span> \
  -<span class="hljs-literal">-header</span> <span class="hljs-string">'accept: application/json'</span>
</code></pre>
<p>You are:</p>
<ul>
<li><p>calling a server endpoint</p>
</li>
<li><p>using HTTP GET request</p>
</li>
<li><p>getting raw data</p>
</li>
</ul>
<pre><code class="lang-powershell">{<span class="hljs-string">"statusCode"</span>:<span class="hljs-number">200</span>,<span class="hljs-string">"data"</span>:{<span class="hljs-string">"page"</span>:<span class="hljs-number">1</span>,<span class="hljs-string">"limit"</span>:<span class="hljs-number">1</span>,<span class="hljs-string">"totalPages"</span>:<span class="hljs-number">0</span>,<span class="hljs-string">"previousPage"</span>:false,
<span class="hljs-string">"nextPage"</span>:false,<span class="hljs-string">"totalItems"</span>:<span class="hljs-number">0</span>,<span class="hljs-string">"currentPageItems"</span>:<span class="hljs-number">0</span>,<span class="hljs-string">"data"</span>:[]},
<span class="hljs-string">"message"</span>:<span class="hljs-string">"Random jokes fetched successfully"</span>,<span class="hljs-string">"success"</span>:true}
</code></pre>
<p>No frontend involved.</p>
]]></content:encoded></item><item><title><![CDATA[TCP Working: 3-Way Handshake & Reliable Communication]]></title><description><![CDATA[When you send some data to another person using the internet, the data won’t be transmitted at once. It transfers in chunks called packets, not the whole data at once.
Now, without the specific rules anyone can send data through any methods or we can...]]></description><link>https://blog.ashishkumarsaini.dev/tcp-working</link><guid isPermaLink="true">https://blog.ashishkumarsaini.dev/tcp-working</guid><category><![CDATA[TCP Handshake]]></category><category><![CDATA[TCP]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Ashish Kumar Saini]]></dc:creator><pubDate>Fri, 30 Jan 2026 18:19:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769797007391/336bd330-db20-4acc-bf9c-0c43d39d24e5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When you send some data to another person using the internet, the data won’t be transmitted at once. It transfers in chunks called packets, not the whole data at once.</p>
<p>Now, without the specific rules anyone can send data through any methods or we can say rules.</p>
<ul>
<li><p>Data can get lost</p>
</li>
<li><p>Data can arrive out of order</p>
</li>
<li><p>Data can be duplicated</p>
</li>
<li><p>Data can get damaged</p>
</li>
<li><p>Your friend won’t know when the complete data is received</p>
</li>
</ul>
<p>Now, TCP came in picture.</p>
<h2 id="heading-what-is-tcp-and-why-is-it-needed">What is TCP and why is it needed?</h2>
<p>TCP stands for Transmission Control Protocol. It is a data transmission protocol in the Transport Layer of the OSI Model.</p>
<p>TCP makes sure that the data is</p>
<ul>
<li><p>Delivered</p>
</li>
<li><p>Delivered in the correct order</p>
</li>
<li><p>Delivered without any duplicates</p>
</li>
<li><p>Delivered without any corruption</p>
</li>
</ul>
<p>That’s why TCP is known for reliable data transfer protocol. Before establishing a connection and sending the data, it builds the connection.</p>
<p>TCP is connection-oriented. The connection orientation approach means that the connection establishment is required to be set up before starting to transfer the data. This protocol uses three way handshaking approach and ensures that the other party is ready to accept and receive the data.</p>
<p>Let’s take an example of a client and a server.</p>
<ul>
<li><p>The Client should first send a message to the server asking, “Are you ready?”</p>
</li>
<li><p>Server responds “Yes, I’m ready“ and sends it back to the client.</p>
</li>
<li><p>Client responds, “Let’s start”.</p>
</li>
</ul>
<p>This process is known as 3-way handshaking.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769639326800/2d45fe84-ab43-49ea-a61d-2bfba20985e6.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-problems-tcp-can-solve">Problems TCP can solve</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Problem</strong></td><td><strong>What TCP Does</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Packet loss</td><td>Retransmits missing data</td></tr>
<tr>
<td>Out-of-order packets</td><td>Reorders them</td></tr>
<tr>
<td>Duplicates</td><td>Removes duplicates</td></tr>
<tr>
<td>Network speed mismatch</td><td>Uses flow control</td></tr>
<tr>
<td>Network congestion</td><td>Slows down sending</td></tr>
<tr>
<td>Data corruption</td><td>Detects &amp; resends</td></tr>
</tbody>
</table>
</div><p>Let’s understand the complete process of connection building, data transferring and then connection closing in detail:</p>
<h3 id="heading-establishing-connection">Establishing connection</h3>
<p>Before sending the data, TCP builds the connections first. TCP uses a process called three-way handshaking, which means it asks for the receiver, waits for the acknowledgement and then sends the data.</p>
<p>Imagine a conversation between two people on a mobile phone:</p>
<p>First: hey! Am I audible?<br />Second: Yes, you are audible. Am I audible too?<br />First: yes, you too. Let’s start.</p>
<p>Only after this, the real conversation will start. So,</p>
<p>Step 1 →</p>
<ul>
<li><p>Sender sends the sequence number as 0 and the ack number as 0.</p>
</li>
<li><p>The Sender says, I want to start a connection.</p>
</li>
</ul>
<p>Step 2 → Receiver sends</p>
<ul>
<li><p>Ack number as 1 (<em>denotes receiver is ready to start the connection</em>)</p>
</li>
<li><p>Sequence number as 0 (<em>means send me data from the start</em>)</p>
</li>
</ul>
<p>Now the receiver acknowledges and is ready to start the connection.</p>
<p>Step 3 → Sender sends</p>
<ul>
<li><p>Ack number as 1 (<em>connection is established</em>)</p>
</li>
<li><p>Sequence number as 1 (<em>let’s start from the first order of the data segment</em>)</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769789590752/dde19cc9-18b2-4215-87b0-cf257b2214fc.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Sequence number → a flag with aunique number that defines the order of the segment of data should be sent by the sender. Ack number → a flag with a unique number that defines the acknowledgement of the data received and the next order of the data segment.</div>
</div>

<h3 id="heading-transfering-data">Transfering Data</h3>
<p>Let’s assume the connection has been established.</p>
<ol>
<li><p><strong>Sender → Receiver</strong> (segment 1)</p>
<ul>
<li><p>Sequence Number: 1</p>
</li>
<li><p>Acknowledge number: 1</p>
</li>
<li><p>Length: 100 bytes (data bytes from 1 to 100)</p>
</li>
</ul>
</li>
</ol>
<p>    Sender says, “Here are bytes 1 to 100”.</p>
<ol start="2">
<li><p><strong>Receiver → Sender</strong>: The receiver accepts the data and returns:</p>
<ul>
<li><p>Sequence Number: 1</p>
</li>
<li><p>Acknowledge number: 101</p>
</li>
</ul>
</li>
</ol>
<p>    The receiver says, “I got the data till 101 bytes”.</p>
<ol start="3">
<li><p><strong>Sender → Reciever</strong> (segment 2)</p>
<ul>
<li><p>Sequence Number: 101</p>
</li>
<li><p>Acknowledge number: 201</p>
</li>
<li><p>Length: 100 bytes (data bytes from 101 to 201)</p>
</li>
</ul>
</li>
</ol>
<p>    Sender says, “Here are bytes 101 to 200”.</p>
<ol start="4">
<li><p><strong>Receiver → Sender</strong>: The receiver accepts the data and returns:</p>
<ul>
<li><p>Sequence Number: 101</p>
</li>
<li><p>Acknowledge number: 201</p>
</li>
</ul>
</li>
</ol>
<p>    The receiver says, “I got the data till 201 bytes”.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769791340900/06b90d4e-ded1-4bd8-96d6-e4678e042f11.png" alt class="image--center mx-auto" /></p>
<p>And the process goes on…</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">When the receiver sends the acknowledgement, the Ack number will always be the order of the next segment of data (Sequence + Length)</div>
</div>

<h3 id="heading-closing-connection">Closing Connection</h3>
<ol>
<li><p><strong>Sender → Receiver</strong></p>
<ul>
<li><p>Sequence Number: 301</p>
</li>
<li><p>Acknowledge number: 401 (but not really required)</p>
</li>
<li><p>FIN: 1</p>
</li>
</ul>
</li>
</ol>
<p>    Sender says, “Here are bytes 301 to 401. I have sent all my data and this is the last set of bytes”.</p>
<ol start="2">
<li><p><strong>Receiver → Sender</strong>: The receiver accepts the data and returns:</p>
<ul>
<li>Acknowledge number: 401</li>
</ul>
</li>
</ol>
<p>    The receiver says, “I got all the data till 401 bytes”.</p>
<ol start="3">
<li><p><strong>Receiver → Sender</strong>:</p>
<ul>
<li><p>FIN: 1</p>
</li>
<li><p>Acknowledge number: 0</p>
</li>
</ul>
</li>
</ol>
<p>    The receiver says, “I’m also closing the connection form my side”.</p>
<ol start="4">
<li><p><strong>Sender → Receiver</strong>: The receiver accepts the data and returns:</p>
<ul>
<li><p>FIN: 1</p>
</li>
<li><p>Acknowledge number: 1</p>
</li>
</ul>
</li>
</ol>
<p>    The receiver says, “Thanks! Acknowledged”.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769796117184/22160c1d-bdda-46b4-a97b-f9eeab6302e6.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-ia"> </h2>
<p>Packet loss and retransmission flow</p>
<p>Now lets break the packet transferring process.</p>
<p>Sender sends:</p>
<ul>
<li><p>Segment X → Seq: 2000, Length: 500</p>
</li>
<li><p>Segment Y → Seq: 2500, Length: 500</p>
</li>
</ul>
<p>But assume that B reaches first, or A has not received, in any case. Receiver checks:</p>
<ul>
<li><p>I have received 2500 - 2999</p>
</li>
<li><p>But 2000 - 2499 is missing</p>
</li>
<li><p>I’m still waiting for byte 2000.</p>
</li>
</ul>
<p>The receiver continuously sends ACK = 200 until it receives the data from 2000 - 2499.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The data transmission in TCP is programmed in such a way that there is very less posibility of data loss. Whether it is on the connection building, data transfer or closing the connection, it asks for the acknowledgment which helps to identify if the data has not been missed by the receiver. This acknowledgement is something that makes it slower than UDP.</p>
<p>That’s why TCP is the protocol that turns an unreliable network into a reliable, ordered, and safe data stream.</p>
]]></content:encoded></item></channel></rss>