<?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[Js Blogs]]></title><description><![CDATA[Js Blogs]]></description><link>https://js-with-abhishek.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/67fe80d2ce22ffd823da1f2d/c0c8d406-1246-4545-b9d7-41feeb106a1a.png</url><title>Js Blogs</title><link>https://js-with-abhishek.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 01:12:38 GMT</lastBuildDate><atom:link href="https://js-with-abhishek.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[JavaScript Modules: Import and Export Explained]]></title><description><![CDATA[Hello readers,
Welcome back to another blog. In the previous blogs, we’ve been learning different JavaScript concepts that make our code cleaner and more powerful. But as your project grows, something]]></description><link>https://js-with-abhishek.hashnode.dev/javascript-modules-import-and-export</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/javascript-modules-import-and-export</guid><category><![CDATA[js]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Fri, 24 Apr 2026 20:00:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/be986b3c-5bde-4d1b-9e9d-b45f15feb9f8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome back to another blog. In the previous blogs, we’ve been learning different JavaScript concepts that make our code cleaner and more powerful. But as your project grows, something <em>even more important</em> comes into play — <strong>code organization</strong>.</p>
<p>If you’ve ever worked on a medium or large project, you know how messy things can get when everything is written in a single file</p>
<p>Today, we’ll fix that problem by understanding <strong>JavaScript Modules</strong> — one of the most important concepts in modern JavaScript.</p>
<h2>The Problem: Unorganized Code</h2>
<p>Let’s say you're building a project like a blog app or e-commerce app.</p>
<p>You might end up with something like this:</p>
<pre><code class="language-plaintext">// utils, API calls, UI logic — everything in one file 

function calculateTotal(price, tax) {
  return price + tax;
}

function fetchProducts() {
  // API logic
}

function renderUI() {
  // UI logic
}
</code></pre>
<h3>Problems with this approach:</h3>
<ul>
<li><p>Hard to read</p>
</li>
<li><p>Difficult to debug</p>
</li>
<li><p>Not reusable</p>
</li>
<li><p>Becomes messy as the project grows</p>
</li>
</ul>
<p>This is where <strong>modules</strong> come into play.</p>
<h2>What are JavaScript Modules?</h2>
<p>A <strong>module</strong> is simply a separate file that contains specific functionality.</p>
<p>Instead of writing everything in one file, we split the code into multiple files.</p>
<p>Example:</p>
<ul>
<li><p><code>math.js</code> → math functions</p>
</li>
<li><p><code>api.js</code> → API calls</p>
</li>
<li><p><code>ui.js</code> → UI logic</p>
</li>
</ul>
<p>This makes your code:</p>
<ul>
<li><p>Cleaner</p>
</li>
<li><p>Easier to manage</p>
</li>
<li><p>Reusable</p>
</li>
</ul>
<h2>Exporting Functions or Values</h2>
<p>To use code from one file in another, we need to <strong>export</strong> it.</p>
<h3>Named Export</h3>
<pre><code class="language-plaintext">// math.js
export function add(a, b) {
  return a + b;
}

export const PI = 3.14;
</code></pre>
<h3>Importing Modules</h3>
<p>Now we can import these into another file:</p>
<pre><code class="language-plaintext">// app.js
import { add, PI } from './math.js';

console.log(add(2, 3)); // 5
console.log(PI); // 3.14
</code></pre>
<p><strong>Notice:</strong></p>
<ul>
<li><p>Curly braces <code>{}</code> are used for named imports</p>
</li>
<li><p>File path is required (<code>./math.js</code>)</p>
</li>
</ul>
<h2>Default vs Named Exports</h2>
<p>This is where many beginners get confused, so let’s break it down simply.</p>
<h3>Default Export (Only One Per File)</h3>
<pre><code class="language-plaintext">// greet.js
export default function greet(name) {
  return `Hello ${name}`;
}
</code></pre>
<p><strong>importing:</strong></p>
<pre><code class="language-plaintext">import greet from './greet.js';

console.log(greet("Abhishek"));
</code></pre>
<p>No <code>{}</code> needed<br />You can rename it while importing</p>
<h2>Why Modules are Important</h2>
<ol>
<li><p>Better Maintainability</p>
</li>
<li><p>Reusablity</p>
</li>
<li><p>Scalability</p>
</li>
<li><p>Team Collaboration</p>
</li>
</ol>
<h3>How Modules Improve Code Structure</h3>
<p>Instead of this:</p>
<pre><code class="language-plaintext">// everything.js
function login() {}
function fetchUser() {}
function renderDashboard() {}
</code></pre>
<p>You can do this:</p>
<pre><code class="language-plaintext">auth.js
api.js
ui.js

// auth.js
export function login() {}

// app.js
import { login } from './auth.js';
</code></pre>
<p>Now the project feels structured like a real-world application.</p>
<div>
<div>💡</div>
<div>Modules work with <code>&lt;script type="module"&gt;</code> in browsers</div>
</div>

<p>That’s it for this blog. This concept might feel simple, but it’s extremely powerful when used in real projects. Start applying it in your projects, and you’ll immediately notice the difference.</p>
<p>I will see you in another interesting and useful blog. Till then...</p>
<p>Stay consistent and keep grinding....</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[The new Keyword in JavaScript]]></title><description><![CDATA[Hello readers,
Welcome to another blog in this JS series. In the previous blog, we explored String Polyfills and common interview methods—basically, how JavaScript works under the hood.
Today, we’re d]]></description><link>https://js-with-abhishek.hashnode.dev/new</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/new</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Fri, 24 Apr 2026 19:30:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/4a04f523-3744-45e8-aa70-d3a9e6d00dcf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in this JS series. In the previous blog, we explored <strong>String Polyfills and common interview methods</strong>—basically, how JavaScript works under the hood.</p>
<p>Today, we’re diving into something that <em>looks simple</em> but confuses a lot of developers: the <code>new</code> keyword</p>
<p>If you've ever written this:</p>
<pre><code class="language-plaintext">const user = new User("Abhishek");
</code></pre>
<p>…and just moved on without thinking much — this blog is for you.</p>
<p>Because under the hood, <strong>a LOT is happening</strong>.</p>
<h2>What does the <code>new</code> keyword actually do?</h2>
<p>Whenever we use <code>new</code> keyword, then it does these 4 things:</p>
<ol>
<li><p>Create a new object</p>
</li>
<li><p>Link it to a constructor function</p>
</li>
<li><p>Set up prototype inheritance</p>
</li>
<li><p>Return that object</p>
</li>
</ol>
<p>But this is just a surface-level. Let's break it properly in depth.</p>
<h2>Constructor functions</h2>
<p>Before understanding <code>new</code>, you need to understand <strong>constructor functions</strong>.</p>
<pre><code class="language-plaintext">function User(name) {
  this.name = name;
}

//now when we do:
const user1 = new User("abhishek"); 
</code></pre>
<p>This function behaves differently from a normal function because of <code>new</code>.</p>
<p>It is exactly the same as this code.</p>
<pre><code class="language-plaintext">class User{
    constructor(name){
      this.name = name;
    }
}
const user1 = new User("abhishek")
</code></pre>
<p>This is the modern JS code using classes.</p>
<h2>What happens when we use <code>new</code>?</h2>
<p>Here is the step-by-step breakdown of what happens when we use <code>new</code> a keyword.</p>
<p>When we do this:</p>
<pre><code class="language-plaintext">const user1 = new User("Abhishek");
</code></pre>
<h3>1. Create an empty object</h3>
<pre><code class="language-plaintext">const obj = {};
</code></pre>
<h3>2. Link prototype</h3>
<pre><code class="language-plaintext">obj.__proto__ = User.prototype;
</code></pre>
<p>Because of this step, methods get shared.</p>
<h3>3. Bind <code>this</code> to this new object</h3>
<pre><code class="language-plaintext">User.call(obj, "Abhishek");
</code></pre>
<p>So inside the constructor:</p>
<pre><code class="language-plaintext">this.name = "Abhishek";
</code></pre>
<h3>4. Return the object</h3>
<pre><code class="language-plaintext">return obj;
</code></pre>
<p>Now, finally, the object is returned unless the constructor explicitly returns another object.</p>
<h2>How <code>new</code> links prototypes</h2>
<pre><code class="language-plaintext">User.prototype.greet = function () {
  console.log(`Hello, ${this.name}`);
};

user1.greet(); //Hello, Abhishek
</code></pre>
<p>How this <code>user1.greet()</code> is working?</p>
<p>This is working because of the prototype chain, because in the second step of <code>new</code>We do prototype linking, so</p>
<p><code>user1.__proto__ === User.prototype</code></p>
<p>And that's why user1 is able to find the greet in User prototype chain.</p>
<h2>Instances created from constructors</h2>
<pre><code class="language-plaintext">const user1 = new User("Abhishek");
const user2 = new User("Agam");
</code></pre>
<p>Here, use1 and user2 are two instances created from a single constructor function. Here are the properties of these instances:</p>
<ul>
<li><p>Both have different data</p>
</li>
<li><p>But these two share the same methods via prototype</p>
</li>
<li><p><code>instanceof</code> <strong>Operator:</strong> You can use the <strong>instanceof</strong> operator to verify if an object was created by a specific constructor.</p>
</li>
</ul>
<h3>To verify, you can do this:</h3>
<pre><code class="language-plaintext">console.log(user1 instanceof User); // true
console.log(user1.__proto__ === User.prototype); // true
</code></pre>
<h2>What if you forget <code>new</code>?</h2>
<pre><code class="language-plaintext">const user1 = User("Abhishek"); //this is classic bug
</code></pre>
<p>In this case:</p>
<ul>
<li><p><code>this</code> points to the global object (or undefined in strict mode)</p>
</li>
<li><p>No object is created</p>
</li>
</ul>
<p><strong>Result:</strong> unexpected behavior</p>
<h2>Some confusing part</h2>
<p>You have also noticed that sometimes you can use Array() with new or without new. Also, the same happens with other built-in methods too.</p>
<p>So, let's understand this in a visual way.</p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/d210a54e-42a8-42b9-8ed8-57285e77f204.png" alt="" style="display:block;margin:0 auto" />

<p>This is for Array() only, but the same thing happens with other built-in methods too, like Object(), Number(), String(), etc.</p>
<h2>TL;DR</h2>
<p>If this is too long to read, then I have a visual diagram that summarizes this blog.</p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/0810bf63-20de-42dd-bc44-14bef1a44fb5.png" alt="" style="display:block;margin:0 auto" />

<p>The <code>new</code> keyword is not just syntax — it’s a <strong>core concept that connects objects, prototypes, and inheritance</strong> in JavaScript.</p>
<p>Once you understand this, a lot of confusing behavior in JS suddenly makes sense.</p>
<p>In the next blog, we’ll move into something equally important:</p>
<p><strong>Modules in JavaScript (import/export)</strong> — how modern JS organizes code.</p>
<p>Till then…</p>
<p>Stay consistent and keep grinding…</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[String Polyfills and Common Interview Methods in JavaScript]]></title><description><![CDATA[Hello readers,
Welcome to another blog in this JS series. In the last blog, I covered Array Flatten in JavaScript and covered how nested structures can be simplified into a single level.
Now, let’s sh]]></description><link>https://js-with-abhishek.hashnode.dev/string-polyfills</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/string-polyfills</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[web dev]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Fri, 24 Apr 2026 10:22:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/b017a296-dd60-475e-8255-0ecf6563dd81.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in this JS series. In the last blog, I covered <strong>Array Flatten in JavaScript</strong> and covered how nested structures can be simplified into a single level.</p>
<p>Now, let’s shift our focus to something that shows up <em>a lot</em> in interviews — <strong>Strings</strong>.</p>
<p>Not just using string methods… but actually understanding <strong>how they work under the hood</strong>.</p>
<p>Because trust me —<br />Writing <code>str.includes()</code> is easy<br />Explaining <em>how it works internally</em> is what gets you hired</p>
<p>So in this blog, we’ll break down:</p>
<ul>
<li><p>What string methods are</p>
</li>
<li><p>Why polyfills matter</p>
</li>
<li><p>How to implement them</p>
</li>
<li><p>Common interview patterns</p>
</li>
</ul>
<p><em><strong>Let’s start</strong></em></p>
<h2>String Methods</h2>
<p>String methods are built-in functions provided by JavaScript to manipulate and work with strings.</p>
<p>For example:</p>
<pre><code class="language-plaintext">const str = "Hello World";

console.log(str.toUpperCase());
console.log(str.includes("World")); 
console.log(str.slice(0, 5));
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/ec760427-8d7f-4953-8b9c-a64fee70cd43.png" alt="" style="display:block;margin:0 auto" />

<p>These methods make our lives easier…</p>
<p>But here’s the real question<br /><strong>Do you know how they actually work internally?</strong></p>
<p>That's what I'm going to cover in this blog.</p>
<h2>Why write Polyfills</h2>
<p>A <strong>polyfill</strong> is basically your own implementation of a built-in method. So, if there are built-in methods already available, then why write your own (polyfills)?</p>
<p>Here are the reasons:</p>
<ol>
<li><p>Interview perspective</p>
</li>
<li><p>For a deeper understanding</p>
</li>
<li><p>Browser compatibility: Earlier, not all browsers supported modern methods. Developers wrote polyfills to ensure consistency.</p>
</li>
</ol>
<p>Now, you know the importance of polyfills. Let's write some polyfills of string methods.</p>
<h2>1. Polyfill for <code>includes()</code></h2>
<h3>Steps:</h3>
<ol>
<li><p>Loop through the main string</p>
</li>
<li><p>At each index, try to match the target string</p>
</li>
<li><p>Compare characters one by one</p>
</li>
<li><p>If all characters match → return <code>true</code></p>
</li>
<li><p>If no match found → return <code>false</code></p>
</li>
</ol>
<pre><code class="language-plaintext">String.prototype.myIncludes = function(searchStr) {
  for (let i = 0; i &lt;= this.length - searchStr.length; i++) {
    let match = true;

    for (let j = 0; j &lt; searchStr.length; j++) {
      if (this[i + j] !== searchStr[j]) {
        match = false;
        break;
      }
    }

    if (match) return true;
  }

  return false;
};

// Usage
console.log("Hello World".myIncludes("World"));
</code></pre>
<h2>2. Polyfill for <code>indexOf()</code></h2>
<h3>Steps:</h3>
<ol>
<li><p>Loop through the string</p>
</li>
<li><p>Try matching a substring at each position</p>
</li>
<li><p>If match found → return index</p>
</li>
<li><p>If not found → return <code>-1</code></p>
</li>
</ol>
<pre><code class="language-plaintext">String.prototype.myIndexOf = function(searchStr) {
  for (let i = 0; i &lt;= this.length - searchStr.length; i++) {
    let match = true;

    for (let j = 0; j &lt; searchStr.length; j++) {
      if (this[i + j] !== searchStr[j]) {
        match = false;
        break;
      }
    }

    // Return index instead of true
    if (match) return i;
  }

  return -1; // not found
};
</code></pre>
<h2>3. Polyfill for <code>startsWith()</code></h2>
<h3>Steps:</h3>
<ol>
<li><p>Check if the search string is longer than the main string</p>
</li>
<li><p>Compare characters from the beginning</p>
</li>
<li><p>If any mismatch → return false</p>
</li>
<li><p>If all match → return true</p>
</li>
</ol>
<pre><code class="language-plaintext">String.prototype.myStartsWith = function(searchStr) {
  // Edge case: search string longer than original
  if (searchStr.length &gt; this.length) return false;

  // Compare from start
  for (let i = 0; i &lt; searchStr.length; i++) {
    if (this[i] !== searchStr[i]) {
      return false; // mismatch
    }
  }

  return true; // all matched
};
</code></pre>
<h2>4. Polyfill for <code>endsWith()</code></h2>
<h3>Steps:</h3>
<ol>
<li><p>Find the starting index from the end</p>
</li>
<li><p>Compare characters from that position</p>
</li>
<li><p>If mismatch → return false</p>
</li>
<li><p>If all match → return true</p>
</li>
</ol>
<pre><code class="language-plaintext">String.prototype.myEndsWith = function(searchStr) {
  // Calculate start index
  let start = this.length - searchStr.length;

  // Edge case: search string longer
  if (start &lt; 0) return false;

  // Compare characters
  for (let i = 0; i &lt; searchStr.length; i++) {
    if (this[start + i] !== searchStr[i]) {
      return false; // mismatch
    }
  }

  return true; // match found
};
</code></pre>
<p>If you have noticed carefully....</p>
<p><code>includes()</code> and <code>indexOf()</code> Use <strong>sliding window logic</strong><br /><code>startsWith()</code> and <code>endsWith()</code> use <strong>direct comparison</strong></p>
<p>This is exactly what interviews want:</p>
<blockquote>
<p>Not just code — but <strong>pattern recognition</strong></p>
</blockquote>
<p>That’s it for this blog. These concepts may look simple, but mastering them will significantly improve your problem-solving skills and interview confidence.</p>
<p>In the next blog, we’ll explore one of the most important and confusing concepts in JavaScript — <strong>the</strong> <code>new</code> <strong>keyword</strong>.</p>
<p>I will see you in another interesting and useful blog. Till then...</p>
<p>Stay consistent and keep grinding....</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Array Flatten in JavaScript]]></title><description><![CDATA[Hello readers,
Welcome to another blog in this JS series. In the previous blogs, I've covered concepts like destructuring, spread/rest, and template literals. Now it’s time to tackle something that lo]]></description><link>https://js-with-abhishek.hashnode.dev/array-flatten</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/array-flatten</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Fri, 24 Apr 2026 09:15:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3325ca83-69d4-41a9-85bd-fe22ffb44190.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in this JS series. In the previous blogs, I've covered concepts like destructuring, spread/rest, and template literals. Now it’s time to tackle something that <em>looks simple but is asked very frequently in interviews</em> — <strong>Array Flattening in JavaScript</strong>.</p>
<p>Array flattening is a simple but very useful concept. There are various ways to flatten a nested array. In this blog, I will cover all those from the perspective of an interview.</p>
<p><em><strong>Let's start the blog.</strong></em></p>
<h2>Nested Arrays</h2>
<p>A <strong>nested array</strong> is simply an array inside another array.</p>
<pre><code class="language-plaintext">const arr = [1, 2, [3, 4], [5, 6]];
</code></pre>
<p>But this can be deeper like this:</p>
<pre><code class="language-plaintext">const arr = [1, [2, [3, [4, 5]]]];
</code></pre>
<p>You can think of it as the layer of boxes inside boxes.</p>
<h2>Why flatten nested arrays?</h2>
<p>Flattening means converting a nested array into a single-level array.</p>
<pre><code class="language-plaintext">//nested array
[1, [2, [3, 4]], 5]

// flatten array - single level
[1, 2, 3, 4, 5]
</code></pre>
<h3>Real-world use cases:</h3>
<ul>
<li><p>API responses (nested JSON data)</p>
</li>
<li><p>Data transformation before rendering UI</p>
</li>
<li><p>Processing deeply nested structures (like comments, categories)</p>
</li>
<li><p>Interview problems (VERY common)</p>
</li>
</ul>
<h2>Ways to flatten arrays</h2>
<p>We can flatten an array in 3 steps only, and those are:</p>
<ol>
<li><p>Traverse every element of the nested array</p>
</li>
<li><p>If the element is an array, then go deeper.</p>
</li>
<li><p>Now, when you find a value, then collect that.</p>
</li>
</ol>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">//nested array
[1, [2, [3, 4]], 5]

steps to make this single level array
Step 1: 1 → add → [1]

Step 2: [2, [3, 4]] → go inside
        2 → add → [1, 2]

        [3, 4] → go inside
        3 → add → [1, 2, 3]
        4 → add → [1, 2, 3, 4]

Step 3: 5 → add → [1, 2, 3, 4, 5]
</code></pre>
<p>Here are the different ways to flatten a nested array.</p>
<h3>1. Using <code>flat()</code></h3>
<p>This is a built-in method in JS used to flatten the array.</p>
<pre><code class="language-plaintext">const arr = [1, [2, [3, 4]]];

arr.flat();      // [1, 2, [3, 4]]
arr.flat(2);     // [1, 2, 3, 4]
arr.flat(Infinity); // fully flattened
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c2f05bf2-3f0e-49d5-9622-e35304513eb9.png" alt="" style="display:block;margin:0 auto" />

<p>This method takes depth as an argument. Default depth is 1, and if you have flattened the array fully, then you can use <code>Infinity</code></p>
<div>
<div>💡</div>
<div>flat() method also removes the empty slots automatically</div>
</div>

<h3>2. Using Recursion</h3>
<p>In the interview, the interviewers expect you to use raw code, not an built-it method.</p>
<p>Here is the recursive way to flatten an array.</p>
<pre><code class="language-plaintext">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;
}
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/fae37403-331a-4a56-9c37-448ce05ae01c.png" alt="" style="display:block;margin:0 auto" />

<p>In this code:</p>
<ul>
<li><p>I have iterated through array</p>
</li>
<li><p>Check → is it an array?</p>
</li>
<li><p>Yes → recursively flatten</p>
</li>
<li><p>No → push to result</p>
</li>
</ul>
<h3>3. Using <code>reduce()</code></h3>
<pre><code class="language-plaintext">function flattenArray(arr) {
  return arr.reduce((acc, curr) =&gt; {
    if (Array.isArray(curr)) {
      return acc.concat(flattenArray(curr));
    }
    return acc.concat(curr);
  }, []);
}
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/386b138b-7432-401e-bf46-a4b6d6fb61ae.png" alt="" style="display:block;margin:0 auto" />

<p>This is the same as the above recursion idea, but cleaner code.</p>
<h3>4. Using Stack</h3>
<p>Recursion is not useful for large arrays. So, you can also use a stack if the array length is large.</p>
<pre><code class="language-plaintext">function flattenArray(arr) {
  const stack = [...arr];
  const result = [];

  while (stack.length) {
    const item = stack.pop();

    if (Array.isArray(item)) {
      stack.push(...item);
    } else {
      result.push(item);
    }
  }

  return result.reverse();
}
</code></pre>
<p>At the end, reversed because the stack is LIFO (last in first out)</p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/69aabd24-151f-425f-85d7-92627721cb14.png" alt="" style="display:block;margin:0 auto" />

<h3>5. Using <code>toString()</code></h3>
<p>This can also flatten a nested array but is not recommended because it converts everything to a string and will also break for objects or booleans inside the array.</p>
<pre><code class="language-plaintext">const arr = [1, [2, [3, 4]]];

const result = arr.toString().split(',').map(Number);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/9351d73e-2676-4f04-9a5b-8db4287c4eb6.png" alt="" style="display:block;margin:0 auto" />

<p>That’s it for this blog. This is one of those concepts that looks easy at first, but once you go deeper, you’ll realize how important it is for interviews and real-world problem-solving. Make sure you don’t just read it—try implementing each approach yourself.</p>
<p>In the next blog, we’ll dive into another interesting JavaScript concept that will level up your understanding even more.</p>
<p>Till then...</p>
<p>Stay consistent and keep grinding....</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Template Literals in JS]]></title><description><![CDATA[Hello readers,
Welcome to another blog in the JS series. Now, I'm covering topics that are going to be used in your code regularly. In the previous blog, I covered the spread vs rest operator in JS.
I]]></description><link>https://js-with-abhishek.hashnode.dev/template-literals</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/template-literals</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Thu, 23 Apr 2026 20:40:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/abcb8aff-c384-4ae8-b989-635937d05979.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in the JS series. Now, I'm covering topics that are going to be used in your code regularly. In the previous blog, I covered the spread vs rest operator in JS.</p>
<p>If you have not read that blog yet, then please go through it. The blog is short, but it is very important to write clean code. Here is the link:</p>
<p><a href="https://js-with-abhishek.hashnode.dev/spread-vs-rest">https://js-with-abhishek.hashnode.dev/spread-vs-rest</a></p>
<p>In this blog, I'm going to cover <strong>Template Literals in JavaScript</strong>.</p>
<p>Trust me, the concept is really easy, but once you start using it, your code will instantly look cleaner and more readable. I will also give you some real-life examples so that you can actually feel the difference.</p>
<p><em><strong>Let's start the blog</strong></em></p>
<h2>Traditional Way of String Concatenation</h2>
<p>Let's create a message that will consist of a string and variables.</p>
<pre><code class="language-plaintext">const name = "Abhishek";
const age = 22;

const message = "My name is " + name + " and I am " + age + " years old.";
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/2dbd9c9f-ead2-4622-91e1-51b7cb67be50.png" alt="" style="display:block;margin:0 auto" />

<p>It works fine... but it doesn't look good. Also, if there are more variables and strings, then it will be hard to read.</p>
<p><strong>For example:</strong></p>
<pre><code class="language-plaintext">const user = "Abhishek";
const email = "abc@gmail.com";
const status = "Active";

const text = "User: " + user + "\n" +
             "Email: " + email + "\n" +
             "Status: " + status;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/130054ee-26d4-4f7e-9dd2-522d52122979.png" alt="" style="display:block;margin:0 auto" />

<p>Problems:</p>
<ul>
<li><p>hard to read</p>
</li>
<li><p>Too many + operators</p>
</li>
<li><p>Easy to miss spaces</p>
</li>
<li><p>Multi-line strings are messy</p>
</li>
</ul>
<p>Now, you understand that this is definitely not a good way. So JS provides Template literals as a solution.</p>
<h2>Template Literals</h2>
<p>Template literals solve all the above-listed problems. Instead of using quotes, we use backticks (<code>`</code> ).</p>
<p>for example</p>
<pre><code class="language-plaintext">const message = `Hello World`;
</code></pre>
<p>This is very simple, but powerful.</p>
<h2>Embedding Variables</h2>
<p>To embed a variable, we use ${} and the variable name inside the braces.</p>
<pre><code class="language-plaintext">const name = "Abhishek";
const age = 22;

const message = `My name is \({name} and I am \){age} years old.`;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/6a8a993a-be1c-478f-91d0-140f5b25033e.png" alt="" style="display:block;margin:0 auto" />

<p>This is easy to read and also looks clean compared to the traditional way.</p>
<h2>Multi-line Strings</h2>
<p>In the traditional way, to change the line you have to write <code>\n</code>, like this:</p>
<pre><code class="language-plaintext">const text = "Line 1\n" +
             "Line 2\n" +
             "Line 3";
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/05e96ef9-f564-4228-8f1a-3f1d3eb7b662.png" alt="" style="display:block;margin:0 auto" />

<p>But in template literals, you just have to enter and write the string in new line. That's it. Not just this, you can also increase the space by giving space between strings.</p>
<p>For example:</p>
<pre><code class="language-plaintext">const text = `
Line 1
Line 2
        Line 3 with spaces 
`;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/f5fd4bc1-14fe-4161-bcdc-f8d55b86a42f.png" alt="" style="display:block;margin:0 auto" />

<h2>JavaScript Inside Strings</h2>
<p>Yes, you can also run JS expressions inside the template literals. Here are some examples:</p>
<pre><code class="language-plaintext">const a = 10;
const b = 20;

const result = `Sum is ${a + b}`;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/95e72138-62b0-4075-8168-efb6fd1e2970.png" alt="" style="display:block;margin:0 auto" />

<pre><code class="language-plaintext">const greet = (name) =&gt; `Hello ${name}`;

const message = `${greet("Abhishek")} 👋`;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/01b43283-ab41-4a6f-b1b4-b2e420335f72.png" alt="" style="display:block;margin:0 auto" />

<h2>Real-Life Use Cases</h2>
<h3>1. API Response</h3>
<pre><code class="language-plaintext">res.send(`User ${user.name} created successfully`);
</code></pre>
<h3>2. Dynamic UI</h3>
<pre><code class="language-plaintext">const heading = `&lt;h1&gt;Welcome ${user.name}&lt;/h1&gt;`;
</code></pre>
<h3>3. Logging</h3>
<pre><code class="language-plaintext">console.log(`Error at \({time}: \){message}`);
</code></pre>
<h3>4. Dynamic URLs</h3>
<pre><code class="language-plaintext">const url = `https://api.example.com/users/${userId}`;
</code></pre>
<p>That’s it for this blog.</p>
<p>Template literals might look like a small feature, but once you start using them, you’ll realize how much cleaner and more readable your code becomes. It removes unnecessary clutter and lets you focus more on logic rather than fixing strings again and again.</p>
<p>I hope this blog helped you understand why template literals are preferred over traditional string concatenation and how they make your code feel more modern and structured.</p>
<p>In the next blog, I’m going to cover <strong>Array Flattening in JavaScript</strong> — another concept that seems simple but is very useful in real-world problems and interviews.</p>
<p>I will see you in another interesting and useful blog. Till then...</p>
<p>Stay consistent and keep grinding....</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Spread vs Rest Operator in JS]]></title><description><![CDATA[Introduciton
Hello readers,
Welcome to another blog in the JS series. Now, a days i'm covering topics which are going to be used in your code regularly. In the previous blog, I covered destructuring i]]></description><link>https://js-with-abhishek.hashnode.dev/spread-vs-rest</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/spread-vs-rest</guid><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Thu, 23 Apr 2026 19:30:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c811040d-8c95-4830-b7d9-c7090d20cb5d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Introduciton</h2>
<p>Hello readers,</p>
<p>Welcome to another blog in the JS series. Now, a days i'm covering topics which are going to be used in your code regularly. In the previous blog, I covered destructuring in JS.</p>
<p>If you have not read that blog yet, then please go through it. The blog is short, but it is very important to write clean code. Here is the link: <a href="https://js-with-abhishek.hashnode.dev/destructuring">https://js-with-abhishek.hashnode.dev/destructuring</a></p>
<p>In this blog, I'm going to cover the spread and rest operator. Both use the same operator (...) but behave differently.</p>
<p>Trust me, the definition is really easy, but the behaviour is a little bit tricky. I will also give you some real-life examples, which will help you to understand the difference between them.</p>
<p><em><strong>Let's start the blog.</strong></em></p>
<h2>What is the spread operator?</h2>
<p>The spread operator spreads (expands) the elements of arrays or objects. That's it.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const arr = [1, 2, 3];

console.log(...arr); 
// 1 2 3
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c4c1fc4a-9411-4a0b-b1a5-74d5e99fb86b.png" alt="" style="display:block;margin:0 auto" />

<p>Here, arr values are expanded because of the spread operator and print. I can also say that:</p>
<blockquote>
<p>Instead of passing the array, I am passing each value individually.</p>
</blockquote>
<h2>Spread with Arrays</h2>
<p>Let's see some real use cases of the spread operator in arrays. This will help you to understand the spread operator in a better way.</p>
<h3>1. Merging the array values into a single array</h3>
<pre><code class="language-plaintext">const arr1 = [1, 2];
const arr2 = [3, 4];

const merged = [...arr1, ...arr2];

console.log(merged);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/948fac59-40f0-443e-bcef-3b9ebf43c501.png" alt="" style="display:block;margin:0 auto" />

<p>Here, we expanded the arr1 and arr2 values into a single merged array.</p>
<h3>2. Copying Arrays</h3>
<pre><code class="language-plaintext">const original = [1, 2, 3];
const copy = [...original];
console.log(copy);
</code></pre>
<p><img src="align=%22center%22" alt="" /></p>
<p>Here, we make a copy of the original by expanding the value of the original array into a copy array. This is a shallow copy (not a reference)</p>
<p>I hope you understood the spread operator use cases with arrays. Let's see how the spread operator works in objects.</p>
<h2>Spread with Objects</h2>
<pre><code class="language-plaintext">const user = { name: "Abhishek", age: 22 };

const updatedUser = {
  ...user,
  age: 23
};

console.log(updatedUser);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/57211a35-4386-4faa-af59-ad1bb17b66fe.png" alt="" style="display:block;margin:0 auto" />

<p>Yes, we can use the spread operator to update the keys. In the above example, user values (key: value) expanded, but there is an age key at the last, so that key overrode the previous one (age: 22)</p>
<p>And the rest of the working of the spread operator is the same as in an array.</p>
<h2>What is Rest Operator?</h2>
<p>Rest collects the values into one variable. That's it.</p>
<p>Here are some examples, which will help you to understand the rest operator.</p>
<h3>1. Rest in Function Parameters</h3>
<pre><code class="language-plaintext">function sum(...numbers) {
    console.log(numbers)    
  return numbers.reduce((acc, curr) =&gt; acc + curr, 0);
}

console.log("sum: ", sum(1, 2, 3, 4))
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/d8e70ea8-d966-48e0-93ec-1283661ec399.png" alt="" style="display:block;margin:0 auto" />

<p>Here, all the arguments passed in the sum function are collected into a single variable numbers, which is an array.</p>
<div>
<div>💡</div>
<div>So, whenever you use the rest operator inside the function's parameters, then those will be converted to an array.</div>
</div>

<h3>2. Rest in Array Destructuring</h3>
<pre><code class="language-plaintext">const [first, ...rest] = [10, 20, 30, 40];

console.log(first); // 10
console.log(rest);  // [20, 30, 40]
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/4e649c27-32b7-45b5-9a9f-074e7c77bb0d.png" alt="" style="display:block;margin:0 auto" />

<p>Here, the first value is separated, and the rest of the values are collected into the rest variable as an array.</p>
<p>This same concept also applies to the rest operator in the function parameter. If you use some variable before using the rest operator, then first those variables will be assigned, and then the rest of the value will be collected into the rest operator variable.</p>
<h3>3. Rest in Object Destructuring</h3>
<pre><code class="language-plaintext">const user = { id: 1, name: "Abhishek", password: "1234" };

const { password, ...safeUser } = user;

console.log(safeUser);
// { id: 1, name: "Abhishek" }
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/4cc131b2-c459-4a37-b0ad-beeb4757ee07.png" alt="" style="display:block;margin:0 auto" />

<p>This is the same as the above example, just the data type is changed. Here, the name is separated, and the rest of the values are collected in the form of an object.</p>
<h2>Spread v/s Rest</h2>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/b020d301-187e-4ec2-9a99-fa9be871d7f5.png" alt="" style="display:block;margin:0 auto" />

<p>That's it for this blog. These concepts are not very vast, but it's important that you use them so that your code is more readable and clean. I hope this blog helps you to understand the difference between the Spread and Rest Operator.</p>
<p>I will see you in another interesting and useful blog. Till then...</p>
<p>Stay consistent and keep grinding....</p>
<p>Peace✌️</p>
]]></content:encoded></item><item><title><![CDATA[Destructuring in Js]]></title><description><![CDATA[Hello readers,
Welcome to another blog in this JS blogs series. From this blog onwards, I'm going to cover those topics that are most used in our daily coding. So, it is very important to learn the pr]]></description><link>https://js-with-abhishek.hashnode.dev/destructuring</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/destructuring</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Thu, 23 Apr 2026 08:37:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/f5504c55-a94a-41dd-8b42-82c3cda303ac.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in this JS blogs series. From this blog onwards, I'm going to cover those topics that are most used in our daily coding. So, it is very important to learn the pros and cons of these concepts along with the tiny nuances.</p>
<p>In this blog, I'm going to cover <code>Destructing</code> in JS. Destructuring is the most used concept that prevents repetitive code. I will cover each and everything about it, so be with me and complete this blog.</p>
<h2>What is Destructuring?</h2>
<p>Destructuring is a way to extract values from arrays or objects and store them in variables.</p>
<p>Instead of manually accessing the values one by one using the array or object, we extract the values and store them into a variable in one place, and later we use them.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const array = [10,20,30]
const [a,b,c] = array;
</code></pre>
<h2>Destructuring Array</h2>
<p>In the above example, I'm destructuring an array. Without the desctructuring this is how our code wil look like:</p>
<pre><code class="language-plaintext">const a = array[0];
const b = array[1];
const c = array[2];  
</code></pre>
<p>Here, I'm repeating the array (variable name) and just tweaking the index to access the values. But with destructuring, I don't need to repeat it; I can extract the values in a single step.</p>
<pre><code class="language-plaintext">const [a,b,c] = array;

// a = first index value
// b = second index value
// c = third index value
</code></pre>
<p>This is the same as the above code, but in a cleaner way because of destructuring.</p>
<p>But here's a question: what if I don't want to use a value? For example, if I don't want to use the first index value, how can I skip it?</p>
<h3>Here is how you can skip values</h3>
<pre><code class="language-plaintext">const array = [10, 20, 30];

const [a, , c] = array;

console.log(a, c); // 10, 30
</code></pre>
<p>Now, you know how you can skip values. But if you accidentally define a variable, then you will get undefined if there is no value in that index.</p>
<pre><code class="language-plaintext">const arr = [10, 20];
const [a,b,c] = arr; //c means 2nd index doesn't exist
console.log(a,b,c) // so you will get undefined
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/95eb9b90-25ae-42ec-a82f-da05e0217848.png" alt="" style="display:block;margin:0 auto" />

<p>To prevent this undefined, you can give a default value in case you are not sure about the value.</p>
<h3>Default values</h3>
<pre><code class="language-plaintext">const arr = [10, 20];

const [a, b, c = 30] = arr;

console.log(a, b, c); // 10 20 30
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/92b5a351-fffb-4699-a436-74aebc4df6fa.png" alt="" style="display:block;margin:0 auto" />

<h2>Destructuring Objects</h2>
<p>Yes, you can also destruct the objects just like the array. In object destructuring, we use curly braces {}, and the variable name should exactly match the keys.</p>
<h3>Without destructuring</h3>
<pre><code class="language-plaintext">const user = {
  name: "Abhishek",
  age: 22
};

const name = user.name;
const age = user.age;
</code></pre>
<p>Here, I'm repeating the user (object name) to each place where I need to access the value.</p>
<p>But in destructuring, just extract the value and use them.</p>
<h3>With destructuring</h3>
<pre><code class="language-plaintext">const user = {
  name: "Abhishek",
  age: 22
};

const { name, age } = user;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/d80e5f3d-17c0-4ef6-80e7-32620a3b9fe1.png" alt="" style="display:block;margin:0 auto" />

<div>
<div>💡</div>
<div>the variable name should be same as the key otherwise you will get undefined.</div>
</div>

<h3>Rename Variables</h3>
<p>If the key is too long and you want to rename, then you can also do this using colon.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const user = {
  name: "Abhishek",
};

const { name: username } = user;

console.log(username); // Abhishek
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/d48c5ff9-bc32-40c4-b66f-d88e25f46cdb.png" alt="" style="display:block;margin:0 auto" />

<h3>Default values in Objects</h3>
<p>In objects, we can also provide default values like in arrays. Just ensure that the variable name doesn't exist in the object as a key; otherwise, the value will be overridden.</p>
<pre><code class="language-plaintext">const user = {
  name: "Abhishek",
};

const { name, age = 18 } = user;

console.log(age); // 18
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c0a3d0e4-1ef4-4852-a630-86d214c31b62.png" alt="" style="display:block;margin:0 auto" />

<h2>Benifits of Destructuring</h2>
<ol>
<li><p>Cleaner code</p>
</li>
<li><p>Better Readability</p>
</li>
<li><p>Faster Development</p>
</li>
</ol>
<p>That's it for this blog. The concept is tiny but very useful, it makes your code cleaner and readable. If you are not using destructuring in you project, then please do.</p>
<p>I will meet you in another blog with such useful concepts. Till then,</p>
<p>Stay consistent &amp; keep grinding.</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Map and Set in Javascript]]></title><description><![CDATA[Hello readers,
Welcome to another blog on JS. In this blog, I'm going to cover the two most useful data types in JS: Map and Set. You can use these as alternatives to objects and arrays to enhance per]]></description><link>https://js-with-abhishek.hashnode.dev/map-and-set</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/map-and-set</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Mon, 20 Apr 2026 12:45:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/fa0d0947-4f83-4be2-b0ce-5b149bbfc875.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog on JS. In this blog, I'm going to cover the two most useful data types in JS: Map and Set. You can use these as alternatives to objects and arrays to enhance performance.</p>
<p>Before diving deep into the Map &amp; Set, let's first know the issues with Objects &amp; Arrays:</p>
<h2>Problems with Objects</h2>
<ol>
<li><p>Keys are only strings or symbols</p>
</li>
<li><p>No order maintained</p>
</li>
<li><p>No optimization at all.</p>
</li>
<li><p>No easy way to get the length.</p>
</li>
</ol>
<pre><code class="language-plaintext">const obj = {};
obj[1] = "Number key";
obj["1"] = "String key";

console.log(obj); // output - { '1': 'String key' }
</code></pre>
<div>
<div>💡</div>
<div>Number (1) got converted to String("1") -- Data overwritten</div>
</div>

<h2>Problems with Arrays</h2>
<ol>
<li><p>Duplicates allowed</p>
</li>
<li><p>Searching is slow</p>
</li>
<li><p>Removing items is inefficient</p>
</li>
</ol>
<pre><code class="language-plaintext">const guests = ["Ranveer", "Ranveer"]; //Duplicates allowed
</code></pre>
<p>If you want a data type that removes these problems, then you should use Map or Set.</p>
<h2>What is a map?</h2>
<p>A map is also like Object which store values in key-value pairs, but with some extra powers.</p>
<p>It solves all the problems I've mentioned above about the Object.</p>
<p>Here is how you can enter values in a map:</p>
<pre><code class="language-plaintext">const mapObj = new Map()

//syntax
mapObj.set(key, value)

//Example
mapObj.set("name", 'abhishek');

//acces the value
mapObj.get(name) //ouput - abhishek
</code></pre>
<p>Here,</p>
<ol>
<li><p>Map is a keyword to define a map object.</p>
</li>
<li><p>mapObj.set() is a function of map to store the key-value pair.</p>
</li>
<li><p>Key &amp; value both can be any data type.</p>
</li>
<li><p>mapObj.get(keyName) to get the value of the key.</p>
</li>
</ol>
<h3>Key features of Map</h3>
<ol>
<li><p>Keys can be any data type</p>
</li>
<li><p>Maintains insertion order</p>
</li>
<li><p>Easy size access (mapObj.size)</p>
</li>
<li><p>Built for frequent updates</p>
</li>
</ol>
<h3>Important points you should know about the map</h3>
<ol>
<li><p>In a map, Objects are stored by reference, not value</p>
<pre><code class="language-plaintext">const map = new Map();

map.set({}, "Object1");
map.set({}, "Object2");

console.log(map.size); // 2
</code></pre>
</li>
<li><p>Iteration is clean and predictable</p>
<pre><code class="language-plaintext">for(let [key, value] of mapObj){
    console.log(key, value);
}
</code></pre>
</li>
</ol>
<h3>What is Set?</h3>
<p>A set is just like an array with extra powers, like:</p>
<ol>
<li><p>No duplicate values allowed</p>
</li>
<li><p>Maintain insertino order</p>
</li>
<li><p>Fast lookup (using has)</p>
</li>
<li><p>No indexing like arrays</p>
</li>
</ol>
<pre><code class="language-plaintext">//initializing a set object
const set = new Set();

//add value
set.add({name: "abhishek"});
set.add({name: "abhishek"});
set.add(1);

//size of this set
set.size // output = 3
</code></pre>
<div>
<div>💡</div>
<div>Objects are stored by reference, not by value, so objects are not considered duplicates even if the key-value pairs are the same.</div>
</div>

<h3>Useful methods</h3>
<pre><code class="language-plaintext">//add method to insert values
set.add(value);

//delete to remove value from set
set.delete(value);

//has to check value is available or not
set.has(value)

//size to get the size of the array
set.size
</code></pre>
<h2>Map vs Object</h2>
<table>
<thead>
<tr>
<th>Features</th>
<th>Map</th>
<th>Object</th>
</tr>
</thead>
<tbody><tr>
<td>Key Types</td>
<td>Any(object, number, etc)</td>
<td>String or Symbol</td>
</tr>
<tr>
<td>Order</td>
<td>Maintained</td>
<td>Not maintained</td>
</tr>
<tr>
<td>Size</td>
<td>map.size</td>
<td>Manual (Object.keys(obj).length</td>
</tr>
<tr>
<td>Performance</td>
<td>Better for frequent operations</td>
<td>Not optimized</td>
</tr>
<tr>
<td>Iteration</td>
<td>Easy</td>
<td>Requires extra methods</td>
</tr>
</tbody></table>
<h2>Set vs Array</h2>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Set</th>
<th>Array</th>
</tr>
</thead>
<tbody><tr>
<td>Duplicate</td>
<td>Not allowed</td>
<td>Allowed</td>
</tr>
<tr>
<td>Search</td>
<td>Fast (using has)</td>
<td>Slower (using includes or indexOf)</td>
</tr>
<tr>
<td>Order</td>
<td>Maintained</td>
<td>Maintained</td>
</tr>
<tr>
<td>Indexing</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody></table>
<h2>When to use Map</h2>
<ul>
<li><p>You need <strong>key-value pairs</strong></p>
</li>
<li><p>Keys are <strong>not just strings</strong></p>
</li>
<li><p>Frequent add/remove operations</p>
</li>
<li><p>Need <strong>ordered data</strong></p>
</li>
</ul>
<h2>When to use Set</h2>
<ul>
<li><p>Removing duplicates</p>
</li>
<li><p>You want unique values only</p>
</li>
<li><p>Fast existence check</p>
</li>
</ul>
<h2>Real-life use case of a map and a set</h2>
<ol>
<li><p>Removing Duplicates (set)</p>
</li>
<li><p>Caching data (map)</p>
</li>
<li><p>Tracking visited items (set)</p>
</li>
</ol>
<p>That's it for this blog. I hope it has clarified any doubts you had about maps and sets. After reading this, you should be able to choose the best data type for your task. I'll see you in another blog.</p>
<p>Until then... Stay consistent &amp; keep grinding</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Error Handling in JavaScript: Try, Catch, Finally]]></title><description><![CDATA[Introduction
Hello readers,
Welcome to another blog. So far, we have delved into callbacks, promises, and async/await in JavaScript. But without error handling, our code is incomplete. We are all fami]]></description><link>https://js-with-abhishek.hashnode.dev/try-catch-finally</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/try-catch-finally</guid><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Mon, 20 Apr 2026 12:28:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/107aacf7-8771-49a7-90db-b0752f756722.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Introduction</h2>
<p>Hello readers,</p>
<p>Welcome to another blog. So far, we have delved into callbacks, promises, and async/await in JavaScript. But without error handling, our code is incomplete. We are all familiar with those annoying errors. So in this blog, I will cover error handling and its methods.</p>
<p>Most people learn error handling like this:</p>
<blockquote>
<p>“Put code in try, handle it in catch, and finally will always run.”</p>
</blockquote>
<p>Sounds simple… but that’s only 10% of the real story.</p>
<p><em><strong>Let’s break it properly.</strong></em></p>
<h3>What is an error?</h3>
<p>In JavaScript, an error is not just “something went wrong”.</p>
<p>It’s a special object that stops normal execution.</p>
<p>Types of common runtime errors:</p>
<ol>
<li><p>ReferenceError → variable not defined</p>
</li>
<li><p>TypeError → wrong operation on a value</p>
</li>
<li><p>SyntaxError → invalid code (caught before execution)</p>
</li>
</ol>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">console.log(user.name); // user is not defined
</code></pre>
<h3>Core Idea: try-catch is NOT for everything</h3>
<p>A common misconception:</p>
<p>“Wrap everything in try-catch.”</p>
<p>Absolutely Wrong.</p>
<p>try...catch only works for:</p>
<ul>
<li>Synchronous runtime errors</li>
</ul>
<p>It does NOT catch:</p>
<ul>
<li><p>Syntax errors (before execution)</p>
</li>
<li><p>Async errors (like setTimeout, promises)</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">try {
    setTimeout(() =&gt; {
        throw new Error("Boom");
      }, 1000);
  } catch (e) {
     console.log("Caught"); //Won't run
  }
</code></pre>
<div>
<div>💡</div>
<div>Why? Because the error happens later, outside the try block.</div>
</div>

<h3>Flow of try-catch-finally</h3>
<p>Let's see the code first:</p>
<pre><code class="language-plaintext">try {
    Execute this block
} catch (err) {
    Runs ONLY if error occurs in try
} finally {
    ALWAYS runs (optional)
}
</code></pre>
<h3>finally runs:</h3>
<ul>
<li><p>after try (if no error)</p>
</li>
<li><p>after catch (if error occurs)</p>
</li>
<li><p>Even if you return inside try or catch, finally still runs</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">function test() {

    try {
        return "from try";
    } finally {
        console.log("finally runs");
    }
}
console.log(test());
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="language-plaintext">from try
finally runs
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3350a5a2-e733-4775-b0c8-e162c84c7ed3.png" alt="" style="display:block;margin:0 auto" />

<h2>Important Nuance:</h2>
<h3>1. Finally, it can override everything</h3>
<p>This is something many devs don’t know:</p>
<pre><code class="language-plaintext">function test() {
    try {
        return "try";

    } finally {
        return "finally";
    }
}

console.log(test());
</code></pre>
<h3>2. catch is Optional (Yes, Really)</h3>
<p>You can use try with only finally:</p>
<p>Example:</p>
<pre><code class="language-plaintext">try{
   console.log("try block")
}finally{
   console.log("final block")
}
</code></pre>
<h3>3. Optional catch parameter (Modern JS)</h3>
<p>You don’t always need the error variable:</p>
<pre><code class="language-plaintext">try {
    riskyCode();
} catch {
    console.log("Something failed");
}
</code></pre>
<h3>4. Throwing Custom Errors (Correct Way)</h3>
<p>Instead of throwing random values:</p>
<pre><code class="language-plaintext">throw "error"; // bad practice
</code></pre>
<p><strong>Use Error:</strong></p>
<pre><code class="language-plaintext">throw new Error("Invalid input");
</code></pre>
<p>You can also customize:</p>
<pre><code class="language-plaintext">class ValidationError extends Error {
    constructor(message) {
        super(message);
        this.name = "ValidationError";
    }
}
</code></pre>
<h2>try-catch vs Promises (Very Important)</h2>
<p>try-catch works with async/await, NOT plain promises.</p>
<p>For example, here, try-catch will not work</p>
<pre><code class="language-plaintext">try {
    fetchData().then(() =&gt; {
        throw new Error("error");
    });
} catch (e) {
    console.log("Not caught");
}
</code></pre>
<p>Here is the correct working code:</p>
<pre><code class="language-plaintext">try {
    await fetchData();
} catch (e) {
    console.log("Caught");
}
</code></pre>
<h2>Nested try-catch</h2>
<pre><code class="language-plaintext">try {
    try {
        throw new Error("Inner error");
    } catch (e) {
        console.log("Handled inner");
    }
} catch (e) {
    console.log("Outer catch");
}
</code></pre>
<p>Once handled, it doesn’t propagate unless rethrown.</p>
<h2>Re-throwing Errors</h2>
<p>We can also throw errors. Throwing errors can be useful when you want to standardize errors and handle them from a single instance.</p>
<pre><code class="language-plaintext">try {
    risky();
} catch (e) {
    console.log("Logging error");
    throw e; // rethrow
}
</code></pre>
<h2>Importance of error handling</h2>
<p><strong>Without proper understanding:</strong></p>
<ul>
<li><p>You think errors are handled… but they’re not</p>
</li>
<li><p>Async bugs slip through</p>
</li>
<li><p>Production crashes silently</p>
</li>
</ul>
<p><strong>With proper understanding:</strong></p>
<ul>
<li><p>You know <strong>where errors are catchable</strong></p>
</li>
<li><p>You avoid false confidence</p>
</li>
<li><p>You build <strong>robust systems</strong></p>
</li>
</ul>
<h2>TLDR;</h2>
<p>Think of it as:</p>
<ul>
<li><p><code>try</code> → “Attempt risky code.”</p>
</li>
<li><p><code>catch</code> → “Handle only sync failures.”</p>
</li>
<li><p><code>finally</code> → “Run cleanup no matter what.”</p>
</li>
</ul>
<p>Don't think of it as a sequence.</p>
<p>That's all for now. I hope you gained a clear understanding of the importance of error handling and the methods to manage errors effectively. Please share your feedback, and I'll see you in another in-depth blog soon.</p>
<p>Until then...</p>
<p>Stay consistent &amp; keep grinding.</p>
<p>Peace✌️</p>
]]></content:encoded></item><item><title><![CDATA[Async/Await in JavaScript]]></title><description><![CDATA[Hello readers,
Welcome to another blog of JS. In the last blogs, we explored callbacks and promises — and honestly… things started getting messyCallbacks gave us callback hell, and promises improved t]]></description><link>https://js-with-abhishek.hashnode.dev/async-await</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/async-await</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Mon, 20 Apr 2026 10:17:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/04f734d4-f123-40e6-b95f-67857ad27ae7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog of JS. In the last blogs, we explored callbacks and promises — and honestly… things started getting messy<br />Callbacks gave us <em>callback hell</em>, and promises improved things… but chaining <code>.then()</code> still felt a bit unnatural.</p>
<p>So today, we’re solving that problem.</p>
<p>Let’s understand <strong>async/await</strong> — the cleanest way to write asynchronous code in JavaScript.</p>
<h2>Why Async/Await?</h2>
<p>Promises were powerful, but:</p>
<ul>
<li><p>Too many <code>.then()</code> chains</p>
</li>
<li><p>Harder to read for beginners</p>
</li>
<li><p>Error handling wasn’t very intuitive</p>
</li>
<li><p>Nested logic still looked confusing</p>
</li>
</ul>
<p>For example:</p>
<pre><code class="language-plaintext">fetchData()
  .then(res =&gt; process(res))
  .then(data =&gt; save(data))
  .catch(err =&gt; console.log(err));
</code></pre>
<p>Looks good... but imagine 10 steps, hard to manage, right?</p>
<p>That's why Async/Await is introduced to make async code:</p>
<ul>
<li><p>Look synchronous</p>
</li>
<li><p>Easier to read</p>
</li>
<li><p>Easier to debug</p>
</li>
</ul>
<div>
<div>💡</div>
<div>Async/await is just <strong>syntactic sugar over promises</strong> — nothing new under the hood.</div>
</div>

<h2>How does async work?</h2>
<p>If you know that the task will be asynchronous, make the function async. To do this, simply write async before the function keyword, or in an arrow function, use the async keyword before the parentheses ().</p>
<p>Example:</p>
<pre><code class="language-plaintext">async function getData() {
  return "Hello";
}

//or in arrow function
const getData = async () =&gt; {
    return "Hello";
}
</code></pre>
<p>And when you make a function async, then the function always returns a <strong>Promise,</strong> so you can also do this**:**</p>
<pre><code class="language-plaintext">getData().then(console.log); // Hello
</code></pre>
<p>Even if you return a normal value → JS wraps it in a promise.</p>
<div>
<div>💡</div>
<div>There is no need to write await inside the async function, but vice versa is not true.</div>
</div>

<h2>Await Keyword</h2>
<p><code>await</code> keyword does only one thing. It pauses execution until a promise resolves.</p>
<pre><code class="language-plaintext">async function fetchUser() {
  const response = await fetch("https://api.com/user");
  const data = await response.json();
  console.log(data);
}
</code></pre>
<p>Here:</p>
<ul>
<li><p>JS <strong>waits</strong> for promise resolution</p>
</li>
<li><p>Then moves to the next line</p>
</li>
<li><p>Code looks synchronous, but is async internally</p>
</li>
</ul>
<div>
<div>💡</div>
<div>Await can be written only inside the async code</div>
</div>

<h2>Error handling in async/await</h2>
<p>With promises, we use catch like this:</p>
<pre><code class="language-plaintext">fetchData()
  .then(res =&gt; res.json())
  .catch(err =&gt; console.log(err));
</code></pre>
<p>But, in async-await code, we use try/catch. Like this:</p>
<pre><code class="language-plaintext">async function getData() {
  try {
    const res = await fetchData();
    const data = await res.json();
    console.log(data);
  } catch (err) {
    console.log(err);
  }
}
</code></pre>
<p>This feels like a normal try/catch—much easier to understand.</p>
<p>I will write a separate blog on handling errors, so don't worry. Just follow me to get notifications.</p>
<h2>Async/Await vs Promises</h2>
<table>
<thead>
<tr>
<th>Features</th>
<th>Promises</th>
<th>Async/Await</th>
</tr>
</thead>
<tbody><tr>
<td>Syntax</td>
<td><code>.then()</code> chaining</td>
<td>Cleaner, synchronous style</td>
</tr>
<tr>
<td>Readability</td>
<td>Medium</td>
<td>High</td>
</tr>
<tr>
<td>Error Handling</td>
<td><code>.catch()</code></td>
<td><code>try/catch</code></td>
</tr>
<tr>
<td>Debugging</td>
<td>Harder</td>
<td>Easier</td>
</tr>
<tr>
<td>Learning Curve</td>
<td>Moderate</td>
<td>Beginner-friendly</td>
</tr>
</tbody></table>
<div>
<div>💡</div>
<div>Internally, both use Promises, so feel free to use promise methods like all, any, race, etc.</div>
</div>

<h2>Examples of Promise &amp; async/await</h2>
<p>I hope everything is clear so far, but if you still have any doubts, here is a real-life example. Write them yourself and try to understand the flow.</p>
<h3>Ordering Food</h3>
<p><strong>Promises Way:</strong></p>
<pre><code class="language-plaintext">orderFood()
  .then(cookFood)
  .then(serveFood)
  .then(eatFood)
  .catch(handleError);
</code></pre>
<p><strong>Async/Await Way:</strong></p>
<pre><code class="language-plaintext">async function enjoyFood() {
  try {
    const order = await orderFood();
    const cooked = await cookFood(order);
    const served = await serveFood(cooked);
    await eatFood(served);
  } catch (err) {
    handleError(err);
  }
}
</code></pre>
<h2>When Should You Use Async/Await?</h2>
<ul>
<li><p>You want clean, readable code</p>
</li>
<li><p>You have sequential async steps</p>
</li>
<li><p>You need better error handling</p>
</li>
<li><p>You want code that looks synchronous</p>
</li>
</ul>
<p><strong>Avoid or be careful when:</strong></p>
<ul>
<li><p>You need parallel execution → use <code>Promise.all</code></p>
</li>
<li><p>In very small one-liners → promises are fine</p>
</li>
</ul>
<p>That's it for this blog. I hope async/await, which is nothing but syntactical sugar now, makes sense to you. Now, you have completed this journey:</p>
<p>Callbacks → Promises → Async/Await</p>
<p>And honestly…<br />Async/await is where things finally start to <em>feel natural</em>.</p>
<p>In the next blog, we can dive deeper into handling the error in JS.</p>
<p>Until then...</p>
<p>Stay consistent and keep grinding.</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Promises Explained for beginners]]></title><description><![CDATA[Hello readers,
Welcome back to another blog. In the last blog, we talked about callbacks - why they exist and the problems they bring (callback hell, pyramid of doom, dependency chaos).
If you haven't]]></description><link>https://js-with-abhishek.hashnode.dev/promise</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/promise</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 19 Apr 2026 23:48:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/22f6b3ae-f6ba-4064-9954-bab98ccfbb68.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome back to another blog. In the last blog, we talked about callbacks - why they exist and the problems they bring (callback hell, pyramid of doom, dependency chaos).</p>
<p>If you haven't read that yet, read here:</p>
<p><a href="https://js-with-abhishek.hashnode.dev/callbacks">https://js-with-abhishek.hashnode.dev/callbacks</a></p>
<p><strong>Now think about this</strong></p>
<ul>
<li><p>What if we could handle async code <strong>in a cleaner way</strong>?</p>
</li>
<li><p>What if we could avoid deeply nested callbacks?</p>
</li>
<li><p>What if our code looked more like <strong>normal step-by-step logic</strong>?</p>
</li>
</ul>
<p>That’s where <strong>Promises</strong> come in.</p>
<h2>What Problem Do Promises Solve?</h2>
<p>Let’s recall the classic callback problem:</p>
<pre><code class="language-plaintext">orderFood(function(order) {
  makePayment(order, function(payment) {
    deliverFood(payment, function(delivery) {
      console.log("Delivered:", delivery);
    });
  });
});
</code></pre>
<p>This creates:</p>
<ul>
<li><p>Nested structure (callback hell)</p>
</li>
<li><p>Hard to read</p>
</li>
<li><p>Hard to debug</p>
</li>
<li><p>Error handling becomes messy</p>
</li>
</ul>
<p><strong>Promises solve this by giving us:</strong></p>
<ul>
<li><p>Better readability</p>
</li>
<li><p>Linear flow of async code</p>
</li>
<li><p>Centralized error handling</p>
</li>
</ul>
<h2>What is a Promise?</h2>
<p>A <strong>Promise</strong> is basically a <strong>future value</strong>.</p>
<p>It represents:</p>
<blockquote>
<p>“I don’t have the result right now… but I will give it to you later.”</p>
</blockquote>
<p>Example:</p>
<pre><code class="language-plaintext">const promise = new Promise((resolve, reject) =&gt; {
  setTimeout(() =&gt; {
    resolve("Food delivered ");
  }, 2000);
});
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>resolve</code> → success</p>
</li>
<li><p><code>reject</code> → failure</p>
</li>
</ul>
<p>We will understand this code snippet ahead.</p>
<h2>Promise States</h2>
<p>Every promise has 3 states:</p>
<ol>
<li><p>Pending</p>
<ol>
<li><p>Initial state.</p>
</li>
<li><p>Work is still going on</p>
</li>
</ol>
</li>
<li><p>Fulfilled</p>
<ol>
<li><p>Operation completed successfully,</p>
</li>
<li><p>resolve() is called</p>
</li>
</ol>
</li>
<li><p>Rejected</p>
<ol>
<li><p>Operation failed</p>
</li>
<li><p>reject() is called</p>
</li>
</ol>
</li>
</ol>
<p>Think of it like ordering food:</p>
<ul>
<li><p>Pending → Order placed</p>
</li>
<li><p>Fulfilled → Food delivered</p>
</li>
<li><p>Rejected → Order canceled</p>
</li>
</ul>
<h2>Basic Promise Lifecycle</h2>
<pre><code class="language-plaintext">const orderFood = new Promise((resolve, reject) =&gt; {
  let success = true;

  if (success) {
    resolve("Order successful");
  } else {
    reject("Order failed");
  }
});
</code></pre>
<p>Now consuming it:</p>
<pre><code class="language-plaintext">const orderFood = new Promise((resolve, reject) =&gt; {
  let success = true;

  if (success) {
    resolve("Order successful");
  } else {
    reject("Order failed");
  }
});
</code></pre>
<h3>Flow:</h3>
<ol>
<li><p>Promise created</p>
</li>
<li><p>Async work happens</p>
</li>
<li><p>Either:</p>
<ul>
<li><p><code>resolve()</code> → <code>.then()</code> runs</p>
</li>
<li><p><code>reject()</code> → <code>.catch()</code> runs</p>
</li>
</ul>
</li>
</ol>
<h2>Handling Success and Failure</h2>
<p>Success → <code>.then()</code></p>
<pre><code class="language-plaintext">promise.then((data) =&gt; {
  console.log("Success:", data);
});
</code></pre>
<p>Failure → <code>.catch()</code></p>
<pre><code class="language-plaintext">promise.catch((error) =&gt; {
  console.log("Error:", error);
});
</code></pre>
<p>Always Run → <code>.finally()</code></p>
<pre><code class="language-plaintext">promise.finally(() =&gt; {
  console.log("Done (success or failure)");
});
</code></pre>
<h2>Promise Chaining (Most Important)</h2>
<p>This is where promises shine.</p>
<p>Instead of nesting, we chain:</p>
<pre><code class="language-plaintext">orderFood()
  .then((order) =&gt; makePayment(order))
  .then((payment) =&gt; deliverFood(payment))
  .then((delivery) =&gt; {
    console.log("Delivered:", delivery);
  })
  .catch((error) =&gt; {
    console.log("Something went wrong:", error);
  });
</code></pre>
<p>What changed?</p>
<ul>
<li><p>No nesting</p>
</li>
<li><p>Clean flow</p>
</li>
<li><p>Looks synchronous (but isn’t!)</p>
</li>
</ul>
<p>So yeah… that’s <strong>Promises</strong> in a nutshell</p>
<p>We started with messy callbacks…<br />Moved to cleaner, structured async handling…<br />And saw how promises make our code <strong>readable, predictable, and scalable</strong>.</p>
<p>But wait…<br />Promises themselves come with some powerful built-in methods that can take things to the next level — especially when dealing with <strong>multiple async operations</strong>.</p>
<p>Things like:</p>
<ul>
<li><p>Running multiple promises together</p>
</li>
<li><p>Handling the fastest or all results</p>
</li>
<li><p>Managing failures smartly</p>
</li>
</ul>
<p>I’ve already covered all of that in detail in my dedicated blog on <strong>Promise Methods</strong></p>
<p>🔗 <strong>Read it here:</strong><br /><a href="https://js-with-abhishek.hashnode.dev/">https://js-with-abhishek.hashnode.dev/</a></p>
<hr />
<p>And in the next blog… We’ll take one more step forward:<br /><strong>async/await — making async code look like sync magic</strong></p>
<p>Stay consistent and keep grinding.</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Callbacks in JavaScript: Why Do They Even Exist]]></title><description><![CDATA[Hello readers,
In my previous blog, we explored how JavaScript executes code—Sync vs. Async—and why things don't always run in the order we expect.
If you haven’t read it yet, I highly recommend check]]></description><link>https://js-with-abhishek.hashnode.dev/callbacks</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/callbacks</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[js]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 19 Apr 2026 22:16:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/88f8d857-ffd4-456e-bf4f-f1c7a8300de4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>In my previous blog, we explored how JavaScript executes code—Sync vs. Async—and why things don't always run in the order we expect.</p>
<p>If you haven’t read it yet, I highly recommend checking that out first. Here is the link:</p>
<p><a href="https://js-with-abhishek.hashnode.dev/sync-async">https://js-with-abhishek.hashnode.dev/sync-async</a></p>
<p>Because today’s topic is built on top of that understanding…</p>
<p>Here are some questions for you...</p>
<ul>
<li><p>How does JavaScript handle tasks like API calls or timers?</p>
</li>
<li><p>How can one function “wait” for another without blocking everything?</p>
</li>
<li><p>And why do we pass functions inside functions? 🤯</p>
</li>
</ul>
<p>That’s where <strong>callbacks</strong> enter the scene, and this blog is all about callbacks.</p>
<p>Before jumping into callbacks... let's understand this first</p>
<h3>Functions are just values in JavaScript</h3>
<p>In JavaScript, functions are <strong>first-class citizens</strong>.<br />That means:</p>
<ul>
<li><p>You can store them in variables</p>
</li>
<li><p>Pass them as arguments</p>
</li>
<li><p>Return them from other functions</p>
</li>
</ul>
<h3>Example:</h3>
<pre><code class="language-plaintext">function greet() {
  console.log("Hello!");
}

function execute(fn) {
  fn(); // calling the function passed as argument
}

execute(greet);
</code></pre>
<p>Here, greet is passed as a value.</p>
<h2>What is a Callback Function?</h2>
<p>In a simple way, the callback function is:</p>
<blockquote>
<p>A function that is passed as an argument to another function and is executed later</p>
</blockquote>
<p>Example:</p>
<pre><code class="language-plaintext">function processUser(name, callback) {
  console.log("Processing user:", name);
  callback();
}

function sayWelcome() {
  console.log("Welcome!");
}

processUser("Abhishek", sayWelcome);
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>sayWelcome</code> is the <strong>callback</strong></p>
</li>
<li><p>It runs <em>after</em> <code>processUser</code> does its job</p>
</li>
</ul>
<h2>Why do callbacks exist?</h2>
<p>Now comes the real question — <em>why do we even need them?</em></p>
<h3>Problem without callbacks</h3>
<p>JavaScript is <strong>single-threaded.</strong> It can do only ONE thing at a time</p>
<p>So what happens with slow tasks?</p>
<ul>
<li><p>API calls</p>
</li>
<li><p>File reading</p>
</li>
<li><p>Timers</p>
</li>
</ul>
<p>If JS waits for them → everything freezes</p>
<h3>Solution: Asynchronous programming</h3>
<p>Instead of blocking, JavaScript says:</p>
<blockquote>
<p>“Hey, I’ll continue my work… you call me back when you're done.”</p>
</blockquote>
<p>And that “call me back” is exactly what a <strong>callback</strong> is.</p>
<h3>Example</h3>
<pre><code class="language-plaintext">console.log("Start");

setTimeout(() =&gt; {
  console.log("Inside timeout");
}, 2000);

console.log("End");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Start
End
Inside timeout
</code></pre>
<p>The function inside the <code>setTimeout</code> is a callback.</p>
<h2>Passing Functions as Arguments</h2>
<p>Callbacks work because functions can be passed around like data.</p>
<p>Example:</p>
<pre><code class="language-plaintext">function calculate(a, b, operation) {
  return operation(a, b);
}

function add(x, y) {
  return x + y;
}

console.log(calculate(2, 3, add)); // 5
</code></pre>
<ul>
<li><p><code>add</code> is passed as a callback</p>
</li>
<li><p><code>calculate</code> decides when/how to execute it</p>
</li>
</ul>
<h2>Use case of callbacks</h2>
<h3>1. Timers</h3>
<pre><code class="language-plaintext">setTimeout(() =&gt; {
  console.log("Executed after delay");
}, 1000);
</code></pre>
<h3>2. API Calls</h3>
<pre><code class="language-plaintext">fetch("https://api.example.com/data")
  .then((response) =&gt; response.json())
  .then((data) =&gt; console.log(data));
</code></pre>
<p><code>.then()</code> takes a callback. Don't worry, this code snippet will be covered in the next blog.</p>
<h3>3. Event Handling</h3>
<pre><code class="language-plaintext">button.addEventListener("click", () =&gt; {
  console.log("Button clicked!");
});
</code></pre>
<p>The function runs only when an event happens.</p>
<h2>Problems with callbacks</h2>
<p>Up until now, callbacks look clean and powerful…</p>
<p>But in real-world apps, things don’t stay this simple</p>
<p>Let’s understand this with a relatable example</p>
<p><strong>To understand the problems with callbacks, imagine this scenario</strong></p>
<p>Imagine you're building a system like Zomato/Swiggy</p>
<p><strong>Steps involved:</strong></p>
<ol>
<li><p>Place Order</p>
</li>
<li><p>Process Payment</p>
</li>
<li><p>Assign Delivery Partner</p>
</li>
<li><p>Deliver Order</p>
</li>
</ol>
<p><strong>Important: Each step depends on the previous one</strong></p>
<ul>
<li><p>No payment → no delivery</p>
</li>
<li><p>No order → nothing happens</p>
</li>
</ul>
<p>Let’s implement this using callbacksLet’s implement this using callbacks</p>
<pre><code class="language-plaintext">function placeOrder(callback) {
  setTimeout(() =&gt; {
    console.log("Order placed");
    callback();
  }, 1000);
}

function processPayment(callback) {
  setTimeout(() =&gt; {
    console.log("Payment successful");
    callback();
  }, 1000);
}

function assignDelivery(callback) {
  setTimeout(() =&gt; {
    console.log("Delivery partner assigned");
    callback();
  }, 1000);
}

function deliverOrder() {
  setTimeout(() =&gt; {
    console.log("Order delivered");
  }, 1000);
}

// Flow
placeOrder(() =&gt; {
  processPayment(() =&gt; {
    assignDelivery(() =&gt; {
      deliverOrder();
    });
  });
});
</code></pre>
<h2>Problem number 1: Pyramid of Doom</h2>
<p>Look at that structure carefully…</p>
<pre><code class="language-plaintext">placeOrder(() =&gt; {
  processPayment(() =&gt; {
    assignDelivery(() =&gt; {
      deliverOrder();
    });
  });
});
</code></pre>
<p>This shape is called Pyramid of Doom (aka Callback Hell)</p>
<p>As steps increase → nesting increases</p>
<p>Imagine adding:</p>
<ul>
<li><p>Order tracking</p>
</li>
<li><p>Notifications</p>
</li>
<li><p>Refund logic</p>
</li>
</ul>
<p>Your code becomes a <strong>right-slanting triangle</strong></p>
<ul>
<li><p>Hard to read</p>
</li>
<li><p>Hard to maintain</p>
</li>
<li><p>Easy to break</p>
</li>
</ul>
<h2>Problem 2: Function Dependency</h2>
<h3>Each function depends on the previous one:</h3>
<ul>
<li><p><code>processPayment</code> depends on <code>placeOrder</code></p>
</li>
<li><p><code>assignDelivery</code> depends on <code>processPayment</code></p>
</li>
<li><p><code>deliverOrder</code> depends on <code>assignDelivery</code></p>
</li>
</ul>
<p>This creates <strong>tight coupling</strong></p>
<h3>Why is this bad?</h3>
<ul>
<li><p>You <strong>can’t reuse functions independently</strong></p>
</li>
<li><p>You <strong>must follow the strict order</strong></p>
</li>
<li><p>Changing one step may break the entire chain</p>
</li>
</ul>
<h2>Problem 3: Inversion of Control</h2>
<p>This is a subtle but <em>very important</em> issue.</p>
<p>When you pass a callback:</p>
<pre><code class="language-plaintext">placeOrder(() =&gt; {
  processPayment(() =&gt; {
    ...
  });
});
</code></pre>
<p>You are giving control of your function to another function</p>
<p>Now you’re trusting:</p>
<ul>
<li><p>Will it call your callback?</p>
</li>
<li><p>Will it call it once or multiple times?</p>
</li>
<li><p>Will it call it at the right time?</p>
</li>
</ul>
<p>You lose control over execution</p>
<h2>Problem 4: Error Handling Nightmare</h2>
<p>Now imagine something fails…</p>
<pre><code class="language-plaintext">placeOrder(() =&gt; {
  processPayment((err) =&gt; {
    if (err) {
      console.log("Payment failed");
    } else {
      assignDelivery(() =&gt; {
        deliverOrder();
      });
    }
  });
});
</code></pre>
<p>Error handling becomes:</p>
<ul>
<li><p>Scattered</p>
</li>
<li><p>Repetitive</p>
</li>
<li><p>Ugly</p>
</li>
</ul>
<p>And worse… You must handle errors at <strong>every level</strong></p>
<h2>Callbacks were powerful… but:</h2>
<ul>
<li><p>They don’t scale well</p>
</li>
<li><p>They make code messy</p>
</li>
<li><p>They reduce readability</p>
</li>
</ul>
<h3>And That’s Why Promises Exist</h3>
<p>To solve:</p>
<ul>
<li><p>Callback hell</p>
</li>
<li><p>Dependency issues</p>
</li>
<li><p>Error handling mess</p>
</li>
<li><p>Inversion of control</p>
</li>
</ul>
<p>JavaScript introduced <strong>Promises</strong></p>
<p>That's it for this blog. I hope you understood callbacks and the problems associated with them. In the next blog, I will discuss what promises are and how they solve these callback issues.</p>
<p>Until then...</p>
<p>Stay Consistent and keep grinding</p>
<p>Peace. ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Synchronous vs Asynchronous JavaScript]]></title><description><![CDATA[Hello readers,
Welcome back to another blog. In the previous post, I explained the call(), apply(), and bind() methods, highlighting how they can change the context of this and their practical applica]]></description><link>https://js-with-abhishek.hashnode.dev/sync-async</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/sync-async</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 19 Apr 2026 21:23:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/4328d4a8-8d7b-44f9-be0e-fc0810a90309.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome back to another blog. In the previous post, I explained the call(), apply(), and bind() methods, highlighting how they can change the context of this and their practical applications.</p>
<p>If you haven't read yet, then <a href="https://js-with-abhishek.hashnode.dev/call-apply-bind">READ HERE</a></p>
<p>Now, let me ask you something</p>
<ul>
<li><p>Why does your app not freeze when fetching data from an API?</p>
</li>
<li><p>How can JavaScript handle timers, clicks, and network requests <em>at the same time</em> if it’s single-threaded?</p>
</li>
<li><p>And what really happens when we say something is “async”?</p>
</li>
</ul>
<p>If you’ve ever been confused by these, this blog is going to clear things up.</p>
<p>Let's start.</p>
<h2>What is Synchronous Code?</h2>
<p><strong>Synchronous code means</strong></p>
<blockquote>
<p>Do one task at a time, in order</p>
</blockquote>
<pre><code class="language-plaintext">console.log("Start");
console.log("Processing...");
console.log("End");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">Start
Processing...
End
</code></pre>
<p>Everything runs <strong>step-by-step</strong> — no surprises.</p>
<p>You can think of it as if you are standing in a queue, then</p>
<ul>
<li><p>You order</p>
</li>
<li><p>You wait</p>
</li>
<li><p>Only after finishing, the next step happens</p>
</li>
</ul>
<p>You are <em>blocked</em> until the current task completes.</p>
<h2>What is Asynchronous Code?</h2>
<p>Now comes the interesting part.</p>
<p><strong>Asynchronous code means</strong></p>
<blockquote>
<p>Start a task, but don’t wait for it to finish</p>
</blockquote>
<pre><code class="language-plaintext">console.log("Start");

setTimeout(() =&gt; {
  console.log("Inside Timeout");
}, 2000);

console.log("End");
</code></pre>
<pre><code class="language-plaintext">Start
End
Inside Timeout
</code></pre>
<p>Even though <code>setTimeout</code> is written earlier, it runs later.</p>
<p>You can think of it as:</p>
<p>At a restaurant:</p>
<ul>
<li><p>You order food</p>
</li>
<li><p>You don’t stand in the kitchen 😄</p>
</li>
<li><p>You sit, talk, scroll…</p>
</li>
<li><p>Food arrives when ready</p>
</li>
</ul>
<p>That’s <strong>non-blocking behavior</strong></p>
<h2>Why Do We Even Need Async in JavaScript?</h2>
<p>To understand the importance of async, imagine this scenario where everything worked synchronously</p>
<ul>
<li><p>You click a button → app freezes</p>
</li>
<li><p>API call takes 5 seconds → UI stuck for 5 seconds</p>
</li>
<li><p>Large computation → browser becomes unresponsive</p>
</li>
</ul>
<p>Not a great experience, right?</p>
<p>This is exactly why <strong>asynchronous behavior exists</strong></p>
<h2>Blocking vs Non-Blocking (The Real Difference)</h2>
<h3>Blocking (Synchronous)</h3>
<ul>
<li><p>Execution <strong>stops</strong> until the task finishes</p>
</li>
<li><p>Can freeze your app</p>
</li>
</ul>
<pre><code class="language-plaintext">while (true) {}
console.log("Never runs");
</code></pre>
<h3>Non-Blocking (Asynchronous)</h3>
<ul>
<li><p>Execution continues</p>
</li>
<li><p>Task completes in the background</p>
</li>
</ul>
<p>This is what makes modern web apps smooth.</p>
<h2>Real-life example that can be used in daily life</h2>
<h3>1. API Calls</h3>
<pre><code class="language-plaintext">fetch("https://api.example.com/data")
  .then(res =&gt; res.json())
  .then(data =&gt; console.log(data));

console.log("After fetch");
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">After fetch
&lt;API data later&gt;
</code></pre>
<h3>2. Timers</h3>
<pre><code class="language-plaintext">setTimeout(() =&gt; console.log("Runs later"), 1000);
console.log("Runs first");
</code></pre>
<p>These are asynchronous because:</p>
<ul>
<li><p>They depend on external systems (network, browser timers)</p>
</li>
<li><p>JS doesn’t want to <em>wait and block everything</em></p>
</li>
</ul>
<h2>Problems with Blocking Code</h2>
<p>If JavaScript were only synchronous:</p>
<ul>
<li><p>UI would freeze</p>
</li>
<li><p>Slow user experience</p>
</li>
<li><p>Cannot handle multiple tasks</p>
</li>
</ul>
<p>Async solves all of this.</p>
<h2>How does async work behind the scenes?</h2>
<p>JavaScript is a single-threaded language, so a question definitely arises: how does non-blocking (asynchronous) code work?  </p>
<p>Without going too deep, here are the steps:</p>
<ul>
<li><p>JS runs your code in a <strong>call stack</strong></p>
</li>
<li><p>Async tasks go to <strong>browser APIs</strong></p>
</li>
<li><p>Once done → they come back via the <strong>event loop</strong></p>
</li>
</ul>
<p>I will cover this part in depth in some other blog. This is just an overview.</p>
<p>That's it for this blog. I hope it helps you understand the difference between synchronous and asynchronous code. But now comes the real question:</p>
<p><mark class="bg-yellow-200 dark:bg-yellow-500/30">“If JavaScript doesn’t wait… how do we get results back?”</mark></p>
<p>That’s where <strong>callbacks</strong> come in —<br />And trust me, they introduce a whole new set of problems.</p>
<p>I will cover this in the next blog, till then,</p>
<p>Stay consistent and keep grinding.</p>
<p>Peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Understanding this in Javascript]]></title><description><![CDATA[Hello readers,
Welcome to another blog. Until now, I have covered all the basics of JavaScript, and thank you so much for appreciating my effort.
In this blog, I'm going to cover the most important an]]></description><link>https://js-with-abhishek.hashnode.dev/this</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/this</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sat, 18 Apr 2026 09:09:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/117f635c-69a2-4b97-bf63-57924d319376.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog. Until now, I have covered all the basics of JavaScript, and thank you so much for appreciating my effort.</p>
<p>In this blog, I'm going to cover the most important and confusing topic of JavaScript, which is "this." It is the most confusing topic of JavaScript, but after reading this blog, you will have a clear understanding of this and its behavior.</p>
<p>Let's understand this with a Bollywood example.</p>
<p>Imagine Ranveer Singh (yup, our Dhurandhar)</p>
<p>He is an actor, and his real name is Ranveer Singh, but something interesting happens in movies.</p>
<p>In one movie, he is Bajirao.</p>
<p>In one movie, he is Alauddin Khilji.</p>
<p>In another movie, he is Hamza.</p>
<p>The actor is the same, but his identity changes depending on the movie he is acting in.</p>
<p>In JavaScript, <strong>functions behave exactly like actors</strong>.</p>
<p>And the movie they are acting in determines <strong>who they represent at that moment</strong>.</p>
<p>That changing identity is exactly what <code>this</code> it is.</p>
<blockquote>
<p><code>this</code> <strong>represents the object that is calling the function. It gives context to the functions or class.</strong></p>
</blockquote>
<p>So think of it like this:</p>
<pre><code class="language-plaintext">Actor (Function) → Ranveer Singh
Movie (Object) → Bajirao Mastani / Gully Boy
Role (this) → Bajirao / Hamza
</code></pre>
<h2><code>this</code> inside Objects</h2>
<p><code>this</code> Inside an object means Ranveer works in a movie, and this value will change according to that movie.</p>
<p>Example:</p>
<pre><code class="language-plaintext">const bajiraoMovie = {
  heroName: "Bajirao",
  actor: "Ranveer Singh",
  introduce() {
    console.log("I am", this.heroName);
  }
};

bajiraoMovie.introduce(); // I am Bajirao

//another movie
const gullyBoyMovie = {
  heroName: "Murad",
  actor: "Ranveer Singh",
  introduce() {
    console.log("I am", this.heroName);
  }
};

gullyBoyMovie.introduce(); //I am Murad
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/9d85dad4-8f67-44de-af32-9c80d502398b.png" alt="" style="display:block;margin:0 auto" />

<p>Here, you can see the movie changes the value of this change, but the function (introduce) is the same.</p>
<p>This is how <code>this</code> it works in JavaScript.</p>
<blockquote>
<p>This doesn't depend on where the function is written, it depends on who is calling the function.</p>
</blockquote>
<h2><code>this</code> inside the Global Context</h2>
<pre><code class="language-plaintext">console.log(this);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/1d98832a-20be-43ab-8149-e687e50721bb.png" alt="" style="display:block;margin:0 auto" />

<p>In this code blog, this is not called inside any object or function, so what do you think should be the output?</p>
<p>This output also depends on the environment where JS is running, because JS runs in different environments like browsers, mobile, desktops, etc.</p>
<p>So, the this keyword returns a Global Object whose value completely depends on the environment.</p>
<p>For a browser: the Global Object is equal to window, so you will get window as output.</p>
<p>For a Node environment, the Global Object is equal to global, so you will get global as output.</p>
<div>
<div>💡</div>
<div>This happens because the global environment becomes the caller.</div>
</div>

<p>Example:</p>
<pre><code class="language-plaintext">function x(){
    console.log(this)
}
window.x(); //output - window (becuase window is calling)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/5ade0add-e144-4bea-a937-ff0d8ad8ae58.png" alt="" style="display:block;margin:0 auto" />

<p>Just like this, you can imagine the above code snippet.</p>
<h2><code>this</code> Keywords also behave differently in strict and non-strict mode</h2>
<p>There are two modes in JS: strict and non-strict.</p>
<pre><code class="language-plaintext">console.log(this)
</code></pre>
<p>So, if you run the above snippet in strict mode, then you will get undefined, but the same code will give window as output in non-strict mode.</p>
<p>The reason is <code>this Substitution</code></p>
<h3><code>this Substitution</code>:</h3>
<p>If the value of <code>this</code> is undefined or null, then this keyword will be replaced with the Global Object. This only works in non-strict mode.</p>
<h2><code>this</code> inside normal functions</h2>
<pre><code class="language-plaintext"> function introduce() {
  console.log("Hello, I'm",  this.name);
}

let user1 = { name: "abhishek", introduce };
let user2 = { name: "agam", introduce };

user1.introduce(); // Hello, I'm abhishek
user2.introduce(); // Hello, I'm agam
</code></pre>
<p>The above code snippet explains that inside the function, this behaves according to the caller; it doesn't depend on where it is written. The output varies based on which user is calling the introduce function.</p>
<h2><code>this</code> Inside Arrow Functions</h2>
<pre><code class="language-plaintext">const introduce = () =&gt; {
  console.log("Hello, I'm", this.name);
};

let user1 = { name: "abhishek", introduce };
let user2 = { name: "agam", introduce };

user1.introduce(); // Hello, i'm undefined
user2.introduce(); // Hello, i'm undefined
</code></pre>
<p>Arrow functions don't have their own this. Arrow functions take this value from their lexical environment where they exist. That's why here we are getting undefined because introduce is in global and in global <code>this.name</code> value is undefined.</p>
<h3>What is the lexical environment?</h3>
<p>In simpler words:</p>
<blockquote>
<p>Lexical Environment means where the function is written. That's it.</p>
</blockquote>
<p>In the above example Introduce is written in the global, and the global value of this in the browser is Windows.</p>
<pre><code class="language-plaintext">console.log(this) // output window (in global)
console.log(this.name) // it equal to window.name = undefined
</code></pre>
<p>another example of an arrow function, but in a different lexical environment</p>
<pre><code class="language-plaintext">let user = {
  name: "abhishek",
  greet() {
    setTimeout(() =&gt; {
      console.log(this.name);
    }, 1000);
  }
};

user.greet(); // abhishek
</code></pre>
<p>In the above example, the arrow function is written inside the greet() function, so the lexical environment of the arrow function is the greet() function. Since greet() is a normal function, it has access to the name value, which is why we get the output "abhishek."</p>
<p>That's it about <code>this</code> the keyword. I hope this blog helps you to clear your doubts related to <code>this</code> keywords in JavaScript. Here is the final mental model</p>
<pre><code class="language-plaintext">in normal function = who is calling me that is this
in arrow function = what was i created decides this
in global this value depends on environment. 
</code></pre>
<p>Now you know that "this" provides context, but did you know you can change it? Yes, you can alter the context and even borrow functions from other objects. Sounds intriguing, right? My next blog will dive into this topic (call, apply, and bind). Until then, see you soon. Keep reading and exploring. Peace.</p>
]]></content:encoded></item><item><title><![CDATA[The magic this, apply(), call() & bind()]]></title><description><![CDATA[Hello readers,
Welcome to another blog in the JS series. In the previous blog, I covered this in depth and in a very simple way. The this keyword in JS is really confusing, but I've tried to make that]]></description><link>https://js-with-abhishek.hashnode.dev/call-apply-bind</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/call-apply-bind</guid><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:53:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/43c550a6-e52a-4519-b85e-cecabb13c09a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers,</p>
<p>Welcome to another blog in the JS series. In the previous blog, I covered this in depth and in a very simple way. The this keyword in JS is really confusing, but I've tried to make that easy with a real-life example. If you have not read that blog yet, click <a href="https://js-with-abhishek.hashnode.dev/this">here</a> and read that blog.</p>
<p>If someone asks me about this in one line, then I would say:</p>
<blockquote>
<p>This keyword in js is used to provide the context</p>
</blockquote>
<p>But do you know? We can change the context of <code>this</code> the keyword using methods like <code>callI()</code>, <code>apply()</code> and <code>bind()</code>. Yes, you heard write and this blog is all about these methods.</p>
<p>Before jumping into these methods, let's first understand:</p>
<h2>Why change the context?</h2>
<h3>Problem 1: <code>this</code> gets lost</h3>
<pre><code class="language-plaintext">const user = {
  name: "Abhishek",
  greet() {
    console.log(`Hello, ${this.name}`);
  }
};

const greetFunc = user.greet; //detached function

greetFunc(); 
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="language-plaintext">Hello, undefined
</code></pre>
<p>Why?</p>
<p>Because:</p>
<ul>
<li><p><code>user.greet()</code> → <code>this = user</code></p>
</li>
<li><p><code>greetFunc()</code> → koi object call nahi kar raha → <code>this</code> lost</p>
</li>
<li><p>In detached mode, we lost <code>this</code> value. So, manually, we need to change the context of the <code>this</code></p>
</li>
</ul>
<h3>Problem 2: Function Borrowing Needed</h3>
<pre><code class="language-plaintext">const user1 = {
  name: "Abhishek",
  greet() {
    console.log(`Hello, ${this.name}`);
  }
};

const user2 = {
  name: "Rahul"
};
</code></pre>
<p>If we want user2 to also greet, then, without context control:</p>
<pre><code class="language-plaintext">user2.greet = function () {
  console.log(`Hello, ${this.name}`);
};
</code></pre>
<p>Again, we have to write the same function in another object also. But it can be done easily by context switching; we don't need to write the same function for every object.</p>
<h3>Problem 3: Reusability Issue</h3>
<pre><code class="language-plaintext">function greet() {
  console.log(`Hello, ${this.name}`);
}
</code></pre>
<p>We want this function to be used with multiple objects, and for that, we have to pass the context of this because by default <code>this</code> has no context.</p>
<h2>Key Reasons to change the context</h2>
<ul>
<li><p>Fix lost <code>this</code></p>
</li>
<li><p>Borrow functions from other objects</p>
</li>
<li><p>Avoid duplicate code</p>
</li>
<li><p>Reuse the same function with different data</p>
</li>
<li><p>Control which object should execute the function</p>
</li>
<li><p>Handle callbacks and delayed execution properly</p>
</li>
</ul>
<p>In JavaScript, there are 3 ways to change the context and those are:</p>
<ol>
<li><p><code>call()</code></p>
</li>
<li><p><code>apply()</code></p>
</li>
<li><p><code>bind()</code></p>
</li>
</ol>
<h2>1. call()</h2>
<p><code>call()</code> allows you to <strong>call a function immediately and set</strong> <code>this</code> <strong>manually</strong></p>
<h3>Syntax</h3>
<pre><code class="language-plaintext">functionName.call(thisArg, arg1, arg2)
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">function greet() {
  console.log(`Hello, ${this.name}`);
}

const user1 = { name: "Abhishek" };
const user2 = { name: "Rahul" };

greet.call(user1); // Hello, Abhishek
greet.call(user2); // Hello, Rahul
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3d46cfa8-3e93-435a-9ee1-50c2e2787df3.png" alt="" style="display:block;margin:0 auto" />

<h3>With arguments</h3>
<pre><code class="language-plaintext">const user = { 
  name: "Abhishek", 
  introduce: function (age, city) {
    console.log(`\({this.name} is \){age} years old from ${city}`);
  }
};

const user2 = { name: "Vivek" };

// Normal call
user.introduce(22, "Patna");

// Borrowed call
user.introduce.call(user2, 22, "Ranchi");
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/afff7a4a-669a-4070-9bfa-de2dff04f3e8.png" alt="" style="display:block;margin:0 auto" />

<h3>Key Points</h3>
<ul>
<li><p>Function executes immediately</p>
</li>
<li><p>Arguments are passed individually</p>
</li>
<li><p>Most useful for quick function borrowing</p>
</li>
</ul>
<h2>2. <code>apply()</code></h2>
<p>apply() is almost the same as call(). The only difference is in argument passing; it takes an array for its arguments, while the rest is the same as call.</p>
<p>Syntax:</p>
<pre><code class="language-plaintext">functionName.apply(thisArg, [argsArray])
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">function introduce(age, city) {
  console.log(`\({this.name} is \){age} years old from ${city}`);
}

const user = { name: "Abhishek" };

introduce.apply(user, [22, "Patna"]);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/383cfbfb-5d88-444e-b0de-0256b9e07045.png" alt="" style="display:block;margin:0 auto" />

<h3>Key Points</h3>
<ul>
<li><p>Executes immediately</p>
</li>
<li><p>Arguments are passed as an array</p>
</li>
<li><p>Useful when data is already in array form</p>
</li>
</ul>
<h2>3. <code>bind()</code></h2>
<p>bind() does not execute immediately like <code>call()</code> and <code>apply()</code>. Instead of executing immediately, it returns a function with a changed context.</p>
<h3>Syntax:</h3>
<pre><code class="language-plaintext">const newFunc = functionName.bind(thisArg)
</code></pre>
<h3>Example:</h3>
<pre><code class="language-plaintext">function greet() {
  console.log(`Hello, ${this.name}`);
}

const user = { name: "Abhishek" };

const boundFunc = greet.bind(user);

boundFunc(); // Hello, Abhishek
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/f13ca49b-8bfd-4e51-850a-c0da63463999.png" alt="" style="display:block;margin:0 auto" />

<h3>With Arguments:</h3>
<pre><code class="language-plaintext">function introduce(age) {
  console.log(`\({this.name} is \){age}`);
}

const user = { name: "Abhishek" };

const bound = introduce.bind(user);

bound(25);
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/2f3515e3-810e-413a-aa64-24285f9c92b3.png" alt="" style="display:block;margin:0 auto" />

<h3>Key Points</h3>
<ul>
<li><p>Does not execute immediately</p>
</li>
<li><p>Returns a new function</p>
</li>
<li><p>Useful in callbacks, event handlers, setTimeout, etc.</p>
</li>
</ul>
<h2>Difference Between <code>call()</code>, <code>apply()</code>, and <code>bind()</code></h2>
<table>
<thead>
<tr>
<th>Features</th>
<th><code>call()</code></th>
<th><code>apply()</code></th>
<th><code>bind()</code></th>
</tr>
</thead>
<tbody><tr>
<td>Execution</td>
<td>Immediate</td>
<td>Immediate</td>
<td>Later</td>
</tr>
<tr>
<td>Arguments</td>
<td>Comma-seperated</td>
<td>Array</td>
<td>Comma (when called)</td>
</tr>
<tr>
<td>Return</td>
<td>Result</td>
<td>Result</td>
<td>New Function</td>
</tr>
</tbody></table>
<h2>TLDR;</h2>
<p>Understanding <code>this</code> is all about understanding <strong>who is calling the function</strong>.</p>
<p>And when JavaScript does not behave the way we want, we use:</p>
<ul>
<li><p><code>call()</code></p>
</li>
<li><p><code>apply()</code></p>
</li>
<li><p><code>bind()</code></p>
</li>
</ul>
<p>to take control.</p>
<p>In simple words:</p>
<p>We don’t let JavaScript decide <code>this</code>,<br />We decide it.</p>
<p>That's it for this blog! I hope it helps you understand the call, apply, and bind methods. I'll see you soon in another blog with just as much depth.</p>
<p>Until then, keep grinding and stay consistent.</p>
<p>Peace. ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Objects Oriented Programming in Js]]></title><description><![CDATA[In the previous blog, we explored objects in JavaScript. Objects help us organize related data and functionality together.
But when applications grow larger, we need a structured way to create many si]]></description><link>https://js-with-abhishek.hashnode.dev/oops</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/oops</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:49:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/b80eb1f7-5f85-4726-ac43-8cf2a7f76da4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the previous blog, we explored <strong>objects in JavaScript</strong>. Objects help us organize related data and functionality together.</p>
<p>But when applications grow larger, we need a <strong>structured way to create many similar objects</strong>.</p>
<p>That’s where <strong>Object-Oriented Programming (OOP)</strong> comes into play.</p>
<h2>OOP</h2>
<p><strong>Object-Oriented Programming</strong> is a programming style where we organize code using <strong>objects and classes</strong>.</p>
<p>Instead of writing separate variables and functions everywhere, we group related data and behavior together.</p>
<p>For example:</p>
<ul>
<li><p>A <strong>Car</strong> has properties → color, brand, speed</p>
</li>
<li><p>A <strong>Car</strong> has behaviors → start(), stop(), accelerate()</p>
</li>
</ul>
<p>OOP allows us to represent these things as <strong>objects in code</strong>.</p>
<p>This approach helps with:</p>
<ul>
<li><p>Code organization</p>
</li>
<li><p>Code reusability</p>
</li>
<li><p>Easier maintenance</p>
</li>
<li><p>Better structure for large applications</p>
</li>
</ul>
<p><strong>To understand OOP easily</strong>, think about <strong>building a house</strong>.</p>
<p>A builder first creates a <strong>blueprint</strong>.</p>
<p>From that blueprint, multiple houses can be built.</p>
<p>Example:</p>
<p>Blueprint → House 1<br />Blueprint → House 2<br />Blueprint → House 3</p>
<p>All houses follow the <strong>same structure</strong>, but they can have different colors, sizes, or owners.</p>
<p>In programming:</p>
<p>Blueprint → <strong>Class</strong><br />House → <strong>Object (Instance)</strong></p>
<p>So a <strong>class defines the structure</strong>, and <strong>objects are created from that structure</strong></p>
<h2><strong>Class in JS</strong></h2>
<p>A <strong>class</strong> is like a <strong>blueprint for creating objects</strong>.</p>
<p>It defines:</p>
<ul>
<li><p>What properties will the object have</p>
</li>
<li><p>What actions (methods) the object can perform</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="language-plaintext">class Person {

}
</code></pre>
<p>Right now, the class is empty. It just defines a structure.</p>
<p>We need to add properties and methods.</p>
<h2>Creating Objects using classes</h2>
<p>To create objects from a class, we use the <strong>new keyword</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">class Person {
  constructor(name, age) {
    this.name = name
    this.age = age
  }
}

const person1 = new Person("Abhishek", 22)
const person2 = new Person("Rahul", 25)

console.log(person1)
console.log(person2)
</code></pre>
<p>outptut</p>
<pre><code class="language-plaintext">Person { name: "Abhishek", age: 22 }
Person { name: "Rahul", age: 25 }
</code></pre>
<p>Here:</p>
<ul>
<li><p><strong>Person</strong> is the class</p>
</li>
<li><p><strong>person1, and person2</strong> are objects created from that class.</p>
</li>
</ul>
<h2>Understanding the Constructor</h2>
<p>A <strong>constructor</strong> is a special method used to <strong>initialize objects</strong>.</p>
<p>It runs <strong>automatically when a new object is created</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">class Car {
  constructor(brand, color) {
    this.brand = brand
    this.color = color
  }
}

const car1 = new Car("Tesla", "Red")
</code></pre>
<p>Here</p>
<pre><code class="language-plaintext">brand → Tesla
color → Red
</code></pre>
<p>The constructor assigns values to the object using <code>this</code>.</p>
<p><code>this</code> refers to the <strong>current object being created</strong>.</p>
<h2>Methods Inside a Class</h2>
<p>Classes can also contain <strong>methods</strong>.</p>
<p>Methods are simply <strong>functions inside a class</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">class Person {
  constructor(name, age) {
    this.name = name
    this.age = age
  }

  greet() {
    console.log(`Hello, my name is ${this.name}`)
  }
}

const user = new Person("Abhishek", 22)

user.greet()
</code></pre>
<pre><code class="language-plaintext">Hello, my name is Abhishek
</code></pre>
<p>Here <code>greet()</code> is a <strong>method</strong> of the Person class.</p>
<h2>Why OOP is Useful</h2>
<p>Object-Oriented Programming helps developers:</p>
<ul>
<li><p>Reuse code efficiently</p>
</li>
<li><p>Organize large programs</p>
</li>
<li><p>Model real-world systems easily</p>
</li>
<li><p>Maintain and extend applications</p>
</li>
</ul>
<p>Most modern applications rely heavily on OOP concepts.</p>
<p>Understanding these concepts is important because many real-world applications rely on object-oriented design to keep the code <strong>clean, scalable, and maintainable</strong>.</p>
<p>Practice creating your own classes like <strong>Student, Car, or Person</strong>, and try adding different properties and methods to them. The more you experiment, the clearer these concepts will become.</p>
<p>That's it for this blog. In the next blog, we will dive into <strong>call, apply, and bind</strong>, and see how JavaScript allows us to use the methods of one object with the properties of another object.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Objects in Js]]></title><description><![CDATA[Hello readers...
Welcome back to another blog. We have reached the most important part of JS. JS is all about objects; it is also said that everything in JS is an object. This is the 8th blog of my JS]]></description><link>https://js-with-abhishek.hashnode.dev/objects</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/objects</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[js]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 15 Mar 2026 14:37:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/1777978f-d3c8-4616-a869-9e6643fa34a4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers...</p>
<p>Welcome back to another blog. We have reached the most important part of JS. JS is all about objects; it is also said that everything in JS is an object. This is the 8th blog of my JS series, and thank you so much for showing so much love to my previous blogs. They are really in-depth and worth reading. You can click on the JS series above and read the blogs.</p>
<p><strong>Let's start this blog</strong></p>
<h2>Object</h2>
<p>Whatever you see or imagine is an object. Anything that can have height, width, or properties can be an object. In terms of programming language, an object is a collection of related data stored as key-value pairs.</p>
<p>Each value in an object is associated with a <strong>key (also called a property)</strong>.</p>
<p>Think of it like storing information about a person.</p>
<pre><code class="language-plaintext">Name → Abhishek
Age → 22
City → Ranchi
</code></pre>
<pre><code class="language-plaintext">const person = {
  name: "Abhishek",
  age: 22,
  city: "Ranchi"
}
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>name</code>, <code>age</code>, and <code>city</code> are <strong>keys</strong></p>
</li>
<li><p><code>"Abhishek"</code>, <code>22</code>, and <code>"Ranchi"</code> are <strong>values</strong></p>
</li>
</ul>
<p>So the structure looks like this:</p>
<pre><code class="language-plaintext">key : value
</code></pre>
<p>This is why objects are often called a <strong>key-value data structure</strong>.</p>
<h2>Why Do We Need Objects?</h2>
<p>Let’s imagine storing a person's details using variables.</p>
<pre><code class="language-plaintext">const name = "Abhishek"
const age = 22
const city = "Ranchi"
</code></pre>
<p>This works, but these variables are <strong>not connected</strong>.</p>
<p>Objects help us <strong>group related information together</strong>.</p>
<pre><code class="language-plaintext">const person = {
  name: "Abhishek",
  age: 22,
  city: "Ranchi"
}
</code></pre>
<p>Now all the information related to a person is stored <strong>in one place</strong>.</p>
<p>This makes code:</p>
<ul>
<li><p>easier to read</p>
</li>
<li><p>easier to manage</p>
</li>
<li><p>easier to extend</p>
</li>
</ul>
<h2>Creating Objects</h2>
<p>Objects are created using <strong>curly braces</strong> <code>{}</code>.</p>
<p><strong>Basic syntax:</strong></p>
<pre><code class="language-plaintext">const objectName = {
  key1: value1,
  key2: value2
}
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const person = {
  name: "Abhishek",
  age: 22,
  city: "Ranchi"
}
</code></pre>
<h2>Accessing Object Properties</h2>
<p>There are two ways to access object properties:</p>
<ol>
<li>Dot notation</li>
</ol>
<p>This is the <strong>most commonly used</strong> method.</p>
<pre><code class="language-plaintext">console.log(person.name)
console.log(person.age)
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">Abhishek
22
</code></pre>
<ol>
<li><h3>Bracket Notation</h3>
</li>
</ol>
<p>This is less commonly used, but when you need to access properties dynamically, this is the only way to access or set a property.</p>
<pre><code class="language-plaintext">console.log(person["city"])
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">Ranchi
</code></pre>
<h2>Updating Object Properties</h2>
<p>Updating object properties is very easy. You can use dot notation or bracket notation to assign a new value.</p>
<pre><code class="language-plaintext">person.age = 23
</code></pre>
<p>Now the object becomes:</p>
<pre><code class="language-plaintext">{
  name: "Abhishek",
  age: 23,
  city: "Ranchi"
}
</code></pre>
<div>
<div>💡</div>
<div>Objects in JavaScript are <strong>mutable</strong>, meaning their properties can be changed.</div>
</div>

<h2></h2>
<p>Adding New Properties</p>
<p>We can also <strong>add new properties</strong> to an object.</p>
<pre><code class="language-plaintext">person.country = "India"
</code></pre>
<p>Now our object becomes:</p>
<pre><code class="language-plaintext">{
  name: "Abhishek",
  age: 23,
  city: "Ranchi",
  country: "India"
}
</code></pre>
<h2>Deleting Properties</h2>
<p>To remove a property, we use the <strong>delete keyword</strong>.</p>
<pre><code class="language-plaintext">delete person.city
</code></pre>
<p>Now the object becomes:</p>
<pre><code class="language-plaintext">{
  name: "Abhishek",
  age: 23,
  country: "India"
}
</code></pre>
<h2>Looping Through Object Keys</h2>
<p>To iterate over an object, we commonly use the <code>for...in</code> <strong>loop</strong>.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const person = {
  name: "Abhishek",
  age: 22,
  city: "Ranchi"
}

for (let key in person) {
  console.log(key, person[key])
}
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">name Abhishek
age 22
city Ranchi
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>key</code> gives the property name</p>
</li>
<li><p><code>person[key]</code> gives the corresponding value</p>
</li>
</ul>
<h2>Array V/S Object</h2>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c468add3-9dee-4c8e-b118-249acfe174e5.png" alt="" style="display:block;margin:0 auto" />

<p>That’s it for this blog. I hope it was helpful and that you now have a clear understanding of objects in JavaScript.</p>
<p>In the next blog, we will explore <strong>Object-Oriented Programming (OOP)</strong> in JavaScript. Even though OOP in JavaScript is mostly considered syntactic sugar, it is still an important concept to understand.</p>
<p>So stay tuned, keep practicing, and keep building.</p>
]]></content:encoded></item><item><title><![CDATA[Arrow Functions in Js]]></title><description><![CDATA[Hello readers...
Welcome back to another blog. In the previous blog, I wrote about the functions and some quirks of the functions in JS. I hope you enjoyed that blog. This blog is a continuation of th]]></description><link>https://js-with-abhishek.hashnode.dev/arrow-functions</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/arrow-functions</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[js]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 15 Mar 2026 13:54:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/aa3a903a-4350-4203-a832-f71dc4f707f0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers...</p>
<p>Welcome back to another blog. In the previous blog, I wrote about the functions and some quirks of the functions in JS. I hope you enjoyed that blog. This blog is a continuation of the previous one, and I'm going to tell you about Arrow functions. Arrow functions are one of the most used features of JS. They make writing functions shorter, cleaner, and easier to read.</p>
<p>In modern JavaScript, arrow functions are used everywhere — especially in <strong>React, Node.js, and functional programming patterns</strong>.</p>
<p>So let's understand them step by step.</p>
<h2>Arrow Functions</h2>
<p>Arrow functions are a <strong>shorter syntax for writing functions in JavaScript</strong>.</p>
<p>They were introduced in <strong>ES6 (ECMAScript 2015)</strong> to reduce the amount of code needed to write functions.</p>
<p>Instead of writing the traditional <code>function</code> keyword, we use an <strong>arrow (</strong><code>=&gt;</code><strong>)</strong>.</p>
<h3><strong>Normal Function</strong></h3>
<pre><code class="language-plaintext">function greet(name) {
  return "Hello " + name;
}
</code></pre>
<h3><strong>Arrow Function</strong></h3>
<pre><code class="language-plaintext">const greet = (name) =&gt; {
  return "Hello " + name;
};
</code></pre>
<h3>Normal Functions vs Arrow Functions</h3>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/c00f0023-c82e-4fd9-a0ea-5f0136876d60.png" alt="" style="display:block;margin:0 auto" />

<h2>Basic Arrow Function Syntax</h2>
<p>The general syntax of an arrow function looks like this:</p>
<pre><code class="language-plaintext">const functionName = (parameters) =&gt; {
  // code
};
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const add = (a, b) =&gt; {
  return a + b;
};

console.log(add(2, 3));
</code></pre>
<p><strong>Output</strong></p>
<pre><code class="language-plaintext">5
</code></pre>
<p>Here:</p>
<ul>
<li><p><code>add</code> is the function name</p>
</li>
<li><p><code>(a, b)</code> are parameters</p>
</li>
<li><p><code>=&gt;</code> defines the arrow function</p>
</li>
<li><p><code>{}</code> contains the function body</p>
</li>
</ul>
<h2>Arrow Function with One Parameter</h2>
<p>When there is <strong>only one parameter</strong>, parentheses are optional.</p>
<h3>Example</h3>
<pre><code class="language-plaintext">const square = num =&gt; {
  return num * num;
};

console.log(square(4));
</code></pre>
<p>output:</p>
<pre><code class="language-plaintext">16
</code></pre>
<p>This makes the code <strong>shorter and easier to read</strong>.</p>
<h2>Implicit Return vs Explicit Return</h2>
<p>Arrow functions have a powerful feature called <strong>implicit return</strong>.</p>
<p>Let's understand this step by step.</p>
<h2>Explicit Return</h2>
<p>When we use <code>{}</code>, We must use the <code>return</code> keyword.</p>
<pre><code class="language-plaintext">const add = (a, b) =&gt; {
  return a + b;
};
</code></pre>
<p>This is called <strong>explicit return</strong>.</p>
<h2>Implicit Return</h2>
<p>If the function has <strong>only one expression</strong>, we can remove <code>{}</code> and <code>return</code>.</p>
<pre><code class="language-plaintext">const add = (a, b) =&gt; a + b;

console.log(add(2, 3));
</code></pre>
<p>Output:</p>
<pre><code class="language-plaintext">5
</code></pre>
<h2>Using Arrow Functions with Arrays</h2>
<p>Arrow functions are <strong>very commonly used with array methods</strong> like <code>map</code>, <code>filter</code>, and <code>reduce</code>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">const numbers = [1, 2, 3, 4];

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

console.log(squares);
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">[1, 4, 9, 16]
</code></pre>
<p>Here, we used an <strong>arrow function inside</strong> <code>map()</code> to square every number.</p>
<p>This is one of the most common real-world uses of arrow functions.</p>
<p>That's it for this blog.</p>
<p>In the next blog, we will dive deeper into <strong>JavaScript objects</strong>. We'll explore how <strong>functions in JavaScript can also behave like objects</strong> and learn <strong>different ways to create objects in JavaScript</strong>.</p>
<p>Trust me, this is where JavaScript starts getting really interesting.</p>
<p>Until then, keep learning and keep building 🚀</p>
]]></content:encoded></item><item><title><![CDATA[Function Declaration v/s Function expression]]></title><description><![CDATA[Hello readers...
Welcome to another in-depth blog; this is my 6th blog in this JS series. So far, we have covered topics like variables, operators, if-else, arrays, and array methods. But have you eve]]></description><link>https://js-with-abhishek.hashnode.dev/functions</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/functions</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[chai-code ]]></category><category><![CDATA[js]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sun, 15 Mar 2026 13:35:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/2f651f7a-d57b-4465-9d67-5154367f5922.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers...</p>
<p>Welcome to another in-depth blog; this is my 6th blog in this JS series. So far, we have covered topics like variables, operators, if-else, arrays, and array methods. But have you ever considered what you would do if you needed to use the same logic elsewhere? Would you write the same code again? What if you had to use the same logic in multiple features?</p>
<p>So, you can't write the same code everywhere because:</p>
<ol>
<li><p>It is repetitive code.</p>
</li>
<li><p>If you need to change something in the logic, you have to update every single place you've written it.</p>
</li>
<li><p>If your peers also want to use that logic, they have to copy-paste or write the same logic again.</p>
</li>
</ol>
<p>We need a solution to resolve these repetition problems, and today's blog is all about this problem resolution: functions. In JS, functions have some extra features compared to other languages, so it is important to learn them in depth.</p>
<p>let's start.</p>
<h2>What is a function?</h2>
<p>A <strong>function</strong> is simply a reusable block of code that performs a specific task.</p>
<p>Instead of writing the same code again and again, we can <strong>wrap it inside a function and reuse it whenever needed.</strong></p>
<h3>Without functions</h3>
<pre><code class="language-plaintext">let a = 5
let b = 10
console.log(a + b)

let x = 20
let y = 30
console.log(x + y)
</code></pre>
<p>We are repeating the same logic.</p>
<h3>With function:</h3>
<pre><code class="language-plaintext">function add(num1, num2) {
  return num1 + num2
}

console.log(add(5, 10))
console.log(add(20, 30))
</code></pre>
<p>Now the logic is written <strong>once</strong> and reused multiple times.</p>
<p>That’s the power of functions.</p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/a270f68d-66f0-4ea1-9dad-e29b05fbb4ec.png" alt="" style="display:block;margin:0 auto" />

<h2>Function Declaration</h2>
<p>A <strong>function declaration</strong> defines a named function using the keyword.</p>
<p><strong>Syntax:</strong></p>
<pre><code class="language-plaintext">function functionName(parameters) {
   // code
}
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">function multiply(a, b) {
  return a * b
}

console.log(multiply(4, 5))
</code></pre>
<p>This is the most traditional way of defining functions in JavaScript.</p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3ba72be3-b003-453a-a586-efe120451d4e.png" alt="" style="display:block;margin:0 auto" />

<h2>Function Expression</h2>
<p>In JavaScript, functions can also be <strong>stored inside variables</strong>. This is called a <strong>function expression</strong>.</p>
<pre><code class="language-plaintext">const variableName = function(parameters) {
   // code
}
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">const multiply = function(a, b) {
  return a * b
}

console.log(multiply(4, 5))
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/b9d0d69d-fd0d-4b33-a0ae-ef7c1b9a905b.png" alt="" style="display:block;margin:0 auto" />

<h2>Function Declaration vs Function Expression</h2>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3697e80e-1b6d-43f2-a45a-f89a9572d953.png" alt="" style="display:block;margin:0 auto" />

<h2>Hoisting</h2>
<p>In the first blog, I also described a little about hoisting, but here I will explain it in depth. Hoisting is the memory preparation phase of JavaScript. As you run your JavaScript file, the JS engine first scans your file and starts to prepare the memory, which is known as hoisting. This occurs even before running your code. In hoisting, function declarations are stored as a reference, meaning you can use the function declaration even before defining it because the function reference is already stored.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">sayHello()

function sayHello() {
  console.log("Hello from function declaration")
}
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">Hello from function declaration
</code></pre>
<p>Even though the function is written <strong>after the call</strong>, it still works.</p>
<p>Why?</p>
<p>Because <strong>function declarations are hoisted completely</strong>.</p>
<p>However, when you use a function expression, hoisting doesn't store it as a function reference because you use let, const, or var. Therefore, hoisting works differently with function expressions.</p>
<p><strong>Example:</strong></p>
<pre><code class="language-plaintext">sayHello()

const sayHello = function() {
  console.log("Hello from function expression")
}
</code></pre>
<p>output:</p>
<pre><code class="language-plaintext">ReferenceError
</code></pre>
<h2>Some Interesting JavaScript Function Quirks</h2>
<p>JavaScript functions have some behaviors that surprise many developers.</p>
<p>Let's look at a few.</p>
<h3>1. A function can be stored in a value</h3>
<p><strong>example:</strong></p>
<pre><code class="language-plaintext">function greet(name) { 
    console.log("Hello, ", name) 
}
const sayHello = greet
sayHello("Abhishek")
</code></pre>
<p>This happens because <strong>functions are treated like values in JavaScript.</strong></p>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/15d1453c-d355-4a87-a71c-d4a7ee17c6e3.png" alt="" style="display:block;margin:0 auto" />

<h3>2. Functions Can Be Passed as Arguments</h3>
<pre><code class="language-plaintext">function greet(name) {
  return "Hello " + name
}

function processUser(callback) {
  console.log(callback("Abhishek"))
}

processUser(greet)
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">Hello Abhishek
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/df352404-7327-412a-be50-8fba0f2feccd.png" alt="" style="display:block;margin:0 auto" />

<h3>3. Function can return a function</h3>
<pre><code class="language-plaintext">function outer() {
  return function() {
    console.log("Inner function")
  }
}

const result = outer()
result()
</code></pre>
<p><strong>output</strong></p>
<pre><code class="language-plaintext">Inner function
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/a45cb827-426a-4ec8-a8fa-1b73051ae426.png" alt="" style="display:block;margin:0 auto" />

<h3>4. Functions have a length property</h3>
<pre><code class="language-plaintext">function add(a, b, c) {}

console.log(add.length)
</code></pre>
<p><strong>output:</strong></p>
<pre><code class="language-plaintext">3
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/359a2e59-0568-49c3-8a9e-73fc0b011162.png" alt="" style="display:block;margin:0 auto" />

<h2>When to use which type?</h2>
<h3>Use Function Declaration When</h3>
<ul>
<li><p>You are defining <strong>core logic</strong></p>
</li>
<li><p>The function should be available <strong>throughout the scope</strong></p>
</li>
<li><p>You want a cleaner, readable structure</p>
</li>
</ul>
<h3>Use a Function Expression when</h3>
<ul>
<li><p>You want to <strong>store functions in variables</strong></p>
</li>
<li><p>You are creating <strong>callbacks</strong></p>
</li>
<li><p>You want <strong>more control over execution timing</strong></p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/db1af19c-e9b3-4e70-9b15-7154702323e5.png" alt="" style="display:block;margin:0 auto" />

<p>That’s it for this blog. In the next one, we’ll dive deeper into <strong>arrow functions</strong>. Until then, keep learning and building.</p>
<p>Functions are more than just reusable blocks of code. In JavaScript, they behave in powerful and sometimes surprising ways.</p>
<p>Understanding <strong>function declarations, function expressions, and hoisting</strong> helps you write more predictable and maintainable code.</p>
<p>And remember:<br /><strong>In JavaScript, functions are not just code — they behave like values.</strong></p>
<p>In the upcoming blog, we’ll explore <strong>why functions can be treated like objects in JavaScript</strong> and what that actually means.</p>
<p>If you enjoyed this blog or learned something new, feel free to <strong>share it and drop your feedback</strong>.</p>
<p>See you in the next one 🚀</p>
]]></content:encoded></item><item><title><![CDATA[Array Methods: You must Know]]></title><description><![CDATA[Hello readers...
Welcome to another blog. This blog is part of the previous blog, where we discussed the basics of arrays. If you have read that blog yet, here you can read that: Arrays Basics
In this]]></description><link>https://js-with-abhishek.hashnode.dev/array-methods</link><guid isPermaLink="true">https://js-with-abhishek.hashnode.dev/array-methods</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Abhishek Kumar]]></dc:creator><pubDate>Sat, 14 Mar 2026 09:10:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/f4710cbb-ade5-48f8-b790-ef77e4c1a604.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello readers...</p>
<p>Welcome to another blog. This blog is part of the previous blog, where we discussed the basics of arrays. If you have read that blog yet, here you can read that: <a href="https://js-with-abhishek.hashnode.dev/arrays">Arrays Basics</a></p>
<p>In this blog, I'm going to cover the methods of arrays. These methods are very important and make the JS array powerful.</p>
<p>These methods will allow you to <strong>transform, filter, search, and manipulate data with very little code</strong>.</p>
<p>Let's start</p>
<ol>
<li><h2>Push()</h2>
</li>
</ol>
<p>The push method is used to insert elements at the end of an array. You can pass multiple elements at a time.</p>
<pre><code class="language-plaintext">let arr = [1,2,3,4];

//push 5 &amp; 6
arr.push(5,6)

//print the array
console.log(arr)
</code></pre>
<ol>
<li><h2>POP()</h2>
</li>
</ol>
<p>The pop method is used to extract the last element of the array. It returns the poped (last) element of the array</p>
<pre><code class="language-plaintext">let arr = [1,2,3,4];

let poppedValue = arr.pop();

console.log("Popped Value: ", poppedValue)
console.log("array: ", arr)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/2c9b2c8b-16ee-4ef6-92c8-344ecd6de385.png" alt="" style="display:block;margin:0 auto" />

<div>
<div>💡</div>
<div>If the array is empty (length === 0) then you will get undefined in the popped value</div>
</div>

<ol>
<li><h2>shift() &amp; unshift</h2>
</li>
</ol>
<p>shift and unshift also work like push and pop, but they insert or pop the element from the start (index 0).</p>
<p>These are called shift and unshift because, due to these operations, all the values of the array shift.</p>
<p><strong>Shift:</strong> Returns the first element of the array and remove that from the array. The rest of the elements are shifted to index 0</p>
<pre><code class="language-plaintext">let arr = [1,2,3,4,5];

let shiftedElement = arr.shift();

console.log("Shifted Value: ", shiftedElement)
console.log("array: ", arr)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/3811ba3d-afad-468a-bfd0-a0172b43c2ed.png" alt="" style="display:block;margin:0 auto" />

<p><strong>unshift: It inserts the element at the 0th index and shifts the rest of the elements from 0.</strong></p>
<pre><code class="language-plaintext">let arr = [1,2,3];

arr.unshift(-1,0);

console.log("array: ", arr)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/506e8a3a-274f-499c-bcb2-17073b9d043e.png" alt="" style="display:block;margin:0 auto" />

<ol>
<li><h2>Map()</h2>
</li>
</ol>
<p>Map is one of the most used methods of array. It transforms each element of your array and returns the array with transformed elements.</p>
<p>How does it work?</p>
<ol>
<li><p>First, it calculates the length of the array.</p>
</li>
<li><p>It takes a callback function where you write the logic of the value transformation</p>
</li>
<li><p>It iterates through each element of the array and transforms those values according to the callback function.</p>
</li>
<li><p>At the end, it returns the new transformed array.</p>
</li>
</ol>
<p><strong>syntax:</strong></p>
<pre><code class="language-plaintext">array.map(() =&gt; ())
</code></pre>
<p>Example:</p>
<pre><code class="language-plaintext">let arr = [10, 20, 30, 3, 5]
let newArray = arr.map((v) =&gt; v*2);
console.log(newArray)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/7cf54746-cbf1-4a24-90d6-bf0fb0712d3f.png" alt="" style="display:block;margin:0 auto" />

<p><strong>Note:</strong></p>
<ol>
<li><p>Map always returns the array with the same length as the original array</p>
</li>
<li><p>In the example, there is only one statement, so no need to wrap it under the curly braces. You can wrap, but if you wrap, then you have to write a return statement to return the value.</p>
</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/68de73c5-c4ba-46b0-92b1-794b01e28fc5.png" alt="" style="display:block;margin:0 auto" />

<h2>5. Filter()</h2>
<p>Filter also returns an array and takes a callback function, but it returns only those values that satisfy the condition you passed in the callback function.</p>
<p>It filters the array values based on the condition you pass.</p>
<pre><code class="language-plaintext">let arr = [10, 20, 9,  30, 3, 5]
console.log("Original Array: ", arr)

let filteredArray = arr.filter((v) =&gt; v%5 === 0);

//returns an array with elements which are divisible by 5
console.log("transformed array",filteredArray)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/0cfae54f-8fce-4b4d-9cb2-361a72afb219.png" alt="" style="display:block;margin:0 auto" />

<h2>6. Reduce()</h2>
<p>Reduce function is one of the powerfull method of an array. It <strong>reduces</strong> the array into a single value.</p>
<p>It takes a callback function with an argument:</p>
<ol>
<li><p>accumulator: the result value (it can be any data type)</p>
</li>
<li><p>iterator: current value (in each iteration)</p>
</li>
</ol>
<pre><code class="language-plaintext">let arr = [1,2,3,4,5]
console.log("Original Array: ", arr)

let sum = arr.reduce((acc, iterator) =&gt; acc+iterator, 0);

//sum of each element
console.log("sum: ", sum)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/e734da48-f20f-46d0-a961-1db7885b9b08.png" alt="" style="display:block;margin:0 auto" />

<h2>7. ForEach()</h2>
<p>For each method is another way to iterate over an array. It go though through each element of the array and performs the task you pass as a callback function.</p>
<p>This is a forEach loop, which means you can't use break or continue. It must iterate through each element of the array.</p>
<p>It doesn't return any value.</p>
<pre><code class="language-plaintext">let arr = [1,2,3,4,5]
console.log("Original Array: ", arr)

arr.forEach((element) =&gt; console.log(element * 2));
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/67fe80d2ce22ffd823da1f2d/810b6e30-22ce-4932-9266-04deb9b5941b.png" alt="" style="display:block;margin:0 auto" />

<p>In the above example, I have printed each element twice.</p>
<h2>Final Thoughts</h2>
<p>JavaScript arrays are much more powerful than simple data containers.</p>
<p>Once you master methods like:</p>
<ul>
<li><p><code>map()</code></p>
</li>
<li><p><code>filter()</code></p>
</li>
<li><p><code>reduce()</code></p>
</li>
</ul>
<p>You will write <strong>cleaner, shorter, and more expressive code.</strong></p>
<p>These methods are also <strong>heavily used in React, Node.js, and modern JavaScript development.</strong></p>
<p>So mastering them is <strong>not optional — it’s essential.</strong></p>
<p>That's it for this blog. I hope this helped you understand how powerful JavaScript array methods are and how they can make your code cleaner and easier to write.</p>
<p>Instead of writing long loops for everything, methods like <code>map()</code>, <code>filter()</code>, and <code>reduce()</code> allow us to work with arrays in a much more expressive and modern way. These methods are heavily used in real-world JavaScript applications, especially in frameworks like React.</p>
<p>If you enjoyed this blog and found it helpful, do share it with others and let me know your feedback.</p>
<p>In the <strong>next blog</strong>, we will dive into one of the most important concepts in JavaScript — <strong>Functions</strong>. We'll explore how functions work, why they are so powerful, and how they help us write reusable and organized code.</p>
<p>See you in the next one 🚀</p>
]]></content:encoded></item></channel></rss>