<?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[Nadim.in]]></title><description><![CDATA[Practical web dev &amp; SEO blog sharing free tools, image optimization, performance tips, and real case studies to help you build faster sites and grow organic]]></description><link>https://blog.nadim.in</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1770934734299/4849f7d7-b9d2-4f29-9328-156704476e24.png</url><title>Nadim.in</title><link>https://blog.nadim.in</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 14:29:46 GMT</lastBuildDate><atom:link href="https://blog.nadim.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I Built Free Image Tools to Improve Website Speed & SEO (2026 Case Study)]]></title><description><![CDATA[I’m a developer from India, and like most of us who build websites, I used to focus a lot on content, design, and SEO tricks. But for a long time, I ignored one simple thing — image optimization.
I used to upload images directly from my phone or Canv...]]></description><link>https://blog.nadim.in/how-i-built-free-image-tools-to-improve-webs</link><guid isPermaLink="true">https://blog.nadim.in/how-i-built-free-image-tools-to-improve-webs</guid><category><![CDATA[SEO]]></category><category><![CDATA[web performance]]></category><category><![CDATA[image optimization ]]></category><category><![CDATA[Core Web Vitals]]></category><category><![CDATA[google discover]]></category><category><![CDATA[PageSpeed Insights]]></category><category><![CDATA[Website speed optimization]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Thu, 12 Feb 2026 21:21:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1770934089235/97ae3fe9-82a1-406b-92b1-821805e69a33.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I’m a developer from India, and like most of us who build websites, I used to focus a lot on content, design, and SEO tricks. But for a long time, I ignored one simple thing — <strong>image optimization</strong>.</p>
<p>I used to upload images directly from my phone or Canva. Big files, no compression, no resizing.</p>
<p><strong>Result?</strong><br />My website was slow, mobile users were suffering, and rankings were not improving much.</p>
<p>Then I started digging deeper into <strong>PageSpeed, Core Web Vitals, and Google Discover</strong>. That’s when I realised — images were the main problem.</p>
<p>So instead of depending on random online tools, I decided to build my own free image tools. This is how it changed my website speed and SEO.</p>
<hr />
<h2 id="heading-the-real-problem-heavy-images-slow-website">The Real Problem: Heavy Images = Slow Website</h2>
<p>When I did a proper audit, I found:</p>
<ul>
<li>Featured images were <strong>1–3 MB</strong></li>
<li>Same <strong>JPG images</strong> used everywhere</li>
<li>No <strong>WebP or modern formats</strong></li>
<li>No proper <strong>resizing</strong></li>
<li>Mobile <strong>LCP was very bad</strong></li>
</ul>
<p>Even if your content is good, users won’t wait if your page takes <strong>4–5 seconds</strong> to load.</p>
<p>On mobile, people just close the tab and move on.</p>
<hr />
<h2 id="heading-why-i-built-image-resizernet">Why I Built image-resizer.net</h2>
<p>I tried many tools online, but most of them were:</p>
<ul>
<li>Full of ads  </li>
<li>Slow  </li>
<li>Asking for signup  </li>
<li>Uploading images to their server  </li>
<li>Limiting usage unless you pay  </li>
</ul>
<p>So I thought, why not build something <strong>simple, fast, and free</strong> for everyone?</p>
<p>That’s how <strong>image-resizer.net</strong> was born — a browser-based tool to:</p>
<ul>
<li>Convert images (<strong>JPG to WebP, AVIF to JPG, PNG to JPG</strong>)  </li>
<li>Compress images without quality loss  </li>
<li>Resize images for blogs, websites &amp; social media  </li>
</ul>
<p>Everything runs in your browser.<br /><strong>No signup, no data stored, no headache.</strong></p>
<p>👉 Try it here: https://image-resizer.net</p>
<hr />
<h2 id="heading-before-vs-after-what-changed">Before vs After: What Changed</h2>
<p>After I optimized all images on my website, the difference was very clear.</p>
<h3 id="heading-before-optimization">Before Optimization</h3>
<ul>
<li>Average image size: <strong>1–2 MB</strong>  </li>
<li>LCP: <strong>4+ seconds</strong>  </li>
<li>Mobile PageSpeed: <strong>40–50</strong>  </li>
<li>Discover impressions: <strong>Very low</strong>  </li>
<li>Bounce rate: <strong>High</strong></li>
</ul>
<h3 id="heading-after-optimization">After Optimization</h3>
<ul>
<li>Average image size: <strong>100–250 KB</strong>  </li>
<li>LCP: <strong>Under 2 seconds</strong>  </li>
<li>Mobile PageSpeed: <strong>80+</strong>  </li>
<li>Discover impressions: <strong>Increased</strong>  </li>
<li>Bounce rate: <strong>Reduced</strong></li>
</ul>
<p>Honestly, I didn’t change much else.<br />Just image optimization gave me a big boost.</p>
<hr />
<h2 id="heading-the-3-free-tools-i-use-daily">The 3 Free Tools I Use Daily</h2>
<p>These are the exact tools I personally use before publishing any post:</p>
<h3 id="heading-1-jpg-to-webp-converter-biggest-impact">1. JPG to WebP Converter (Biggest Impact)</h3>
<p>This one alone reduced file size by <strong>60–80%</strong>.<br />👉 https://image-resizer.net/jpg-to-webp</p>
<p>Use this for:</p>
<ul>
<li>Blog images  </li>
<li>Featured images  </li>
<li>Thumbnails  </li>
<li>Google Discover images  </li>
</ul>
<hr />
<h3 id="heading-2-compress-image-tool">2. Compress Image Tool</h3>
<p>Sometimes you can’t change format, so compression helps a lot.<br />👉 https://image-resizer.net/compress-image</p>
<p>Best for:</p>
<ul>
<li>Hero images  </li>
<li>Product images  </li>
<li>Social media previews  </li>
</ul>
<hr />
<h3 id="heading-3-resize-image-tool">3. Resize Image Tool</h3>
<p>No point uploading a <strong>4000px</strong> image if your blog shows it at <strong>1200px</strong>.<br />👉 https://image-resizer.net/resize-image</p>
<p>Best for:</p>
<ul>
<li>Blog banners  </li>
<li>OG images  </li>
<li>Thumbnails  </li>
</ul>
<hr />
<h2 id="heading-why-image-optimization-is-super-important-for-seo-in-2026">Why Image Optimization Is Super Important for SEO in 2026</h2>
<p>In 2026, Google cares a lot about:</p>
<ul>
<li>Page speed  </li>
<li>Mobile performance  </li>
<li>Core Web Vitals  </li>
<li>User experience  </li>
</ul>
<p>Images directly affect all of these.</p>
<p>If your images are heavy, your SEO will suffer — <strong>simple as that.</strong></p>
<hr />
<h2 id="heading-what-i-recommend-to-every-blogger-founder">What I Recommend to Every Blogger / Founder</h2>
<p>If you’re starting today, follow this simple process:</p>
<ol>
<li>Convert JPG to WebP  </li>
<li>Compress large images  </li>
<li>Resize images to exact size  </li>
<li>Use lazy loading  </li>
<li>Always test on mobile  </li>
</ol>
<p>This alone can improve your site performance more than many advanced SEO tricks.</p>
<hr />
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>I built these tools to solve my own problem.</p>
<p>But now many people are using them daily to speed up their websites.</p>
<p>If your site is slow, don’t overthink SEO.<br /><strong>Start with images.</strong> It gives the fastest and safest improvement.</p>
<p>👉 Try the free tools here: https://image-resizer.net</p>
<hr />
<p><strong>Author</strong><br /><strong>Nadim Anwar</strong><br />Building free tools to make websites faster 🚀<br />https://image-resizer.net</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Nodemon: Why We Use It and Its Features]]></title><description><![CDATA[In the world of Node.js development, a tool that stands out for its utility and convenience is Nodemon. If you're a Node.js developer or just getting started, you've likely heard of or used Nodemon. This blog post will help you understand why we use ...]]></description><link>https://blog.nadim.in/understanding-nodemon-why-we-use-it-and-its-features</link><guid isPermaLink="true">https://blog.nadim.in/understanding-nodemon-why-we-use-it-and-its-features</guid><category><![CDATA[nodemon]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[React]]></category><category><![CDATA[Express]]></category><category><![CDATA[backend]]></category><category><![CDATA[website]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[npm]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Tue, 06 Aug 2024 10:23:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722939732757/e86e6370-69fa-45fd-aeb3-eedc09bc93ce.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the world of Node.js development, a tool that stands out for its utility and convenience is <strong>Nodemon</strong>. If you're a Node.js developer or just getting started, you've likely heard of or used Nodemon. This blog post will help you understand why we use Nodemon and highlight its key features.</p>
<h4 id="heading-what-is-nodemon">What is Nodemon?</h4>
<p>Nodemon is a utility that automatically restarts your Node.js application when file changes in the directory are detected. It is a popular tool among developers because it streamlines the development process by eliminating the need to manually stop and restart the server every time a change is made.</p>
<h4 id="heading-why-do-we-use-nodemon">Why Do We Use Nodemon?</h4>
<ol>
<li><p><strong>Automatic Restarts</strong>: One of the primary reasons to use Nodemon is its ability to automatically restart your application when changes are detected. This feature saves a significant amount of time and effort, especially during active development.</p>
</li>
<li><p><strong>Enhanced Productivity</strong>: By automating the restart process, Nodemon allows developers to focus more on writing code and less on managing the server. This leads to increased productivity and a smoother development workflow.</p>
</li>
<li><p><strong>Ease of Use</strong>: Nodemon is easy to install and use. With just a few commands, you can set up Nodemon to watch your files and restart the server as needed.</p>
</li>
<li><p><strong>Error Reduction</strong>: Manual restarts can sometimes lead to errors if developers forget to restart the server after making changes. Nodemon helps mitigate this risk by ensuring the server is always up-to-date with the latest code changes.</p>
</li>
</ol>
<h4 id="heading-key-features-of-nodemon">Key Features of Nodemon</h4>
<ol>
<li><p><strong>Simple Installation</strong>: Installing Nodemon is straightforward. You can add it as a development dependency to your project or install it globally using npm:</p>
<pre><code class="lang-sh"> npm install -g nodemon
</code></pre>
<p> Or as a dev dependency:</p>
<pre><code class="lang-sh"> npm install --save-dev nodemon
</code></pre>
</li>
<li><p><strong>Easy Configuration</strong>: Nodemon requires minimal configuration to get started. By default, it monitors all files with the <code>.js</code>, <code>.mjs</code>, <code>.coffee</code>, <code>.litcoffee</code>, and <code>.json</code> extensions. However, you can customize the files and directories it watches by specifying them in the <code>nodemon.json</code> file or using command-line options.</p>
</li>
<li><p><strong>Customizable Events</strong>: Nodemon allows you to specify custom actions to be taken before or after the server restarts. You can use this feature to perform tasks such as running tests or cleaning up temporary files.</p>
</li>
<li><p><strong>Extensive File Watching</strong>: Nodemon can be configured to watch additional file types and directories, ensuring that your entire project is monitored for changes. This is useful for projects that include non-JavaScript files, such as HTML, CSS, or other configuration files.</p>
</li>
<li><p><strong>Delay Option</strong>: Nodemon provides a delay option that allows you to specify a waiting period before restarting the server. This can be useful in scenarios where multiple files are changed in quick succession, preventing unnecessary restarts.</p>
</li>
<li><p><strong>Executable Wrappers</strong>: Nodemon can be used with any executable. It can also wrap your application, allowing you to pass any arguments to your Node.js application.</p>
</li>
<li><p><strong>Verbose Mode</strong>: For debugging purposes, Nodemon offers a verbose mode that provides detailed information about the changes being detected and the actions being taken. This can be helpful for troubleshooting and understanding Nodemon's behavior.</p>
</li>
</ol>
<h4 id="heading-conclusion">Conclusion</h4>
<p>Nodemon is an indispensable tool for Node.js developers, offering automatic restarts, enhanced productivity, and ease of use. Its customizable features and extensive file-watching capabilities make it a versatile and powerful addition to any development workflow. By incorporating Nodemon into your development process, you can save time, reduce errors, and focus on what truly matters – writing great code.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding next() in Express.js]]></title><description><![CDATA[Mastering Middleware in Express.js: The Power ofnext()!
Hey community! 🌟
Today, I want to dive into one of the most crucial aspects of Express.js middleware – the next() function. If you're building web applications with Express.js, understanding ho...]]></description><link>https://blog.nadim.in/understanding-next-in-expressjs</link><guid isPermaLink="true">https://blog.nadim.in/understanding-next-in-expressjs</guid><category><![CDATA[Express]]></category><category><![CDATA[React]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[website]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[backend]]></category><category><![CDATA[framework]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Tue, 06 Aug 2024 05:56:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722923718126/07e31839-62bc-42fd-b2bc-8cb4dbcfcfb0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Mastering Middleware in Express.js: The Power of</strong><code>next()</code>!</p>
<p>Hey community! 🌟</p>
<p>Today, I want to dive into one of the most crucial aspects of Express.js middleware – the <code>next()</code> function. If you're building web applications with Express.js, understanding how <code>next()</code> works can greatly enhance your ability to handle requests and streamline your code.</p>
<h3 id="heading-what-is-next">What is <code>next()</code>?</h3>
<p>In Express.js, middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle. The <code>next()</code> function is a callback that, when called, passes control to the next middleware function. If <code>next()</code> is not called, the request will be left hanging, resulting in a timeout.</p>
<h3 id="heading-why-use-next">Why Use <code>next()</code>?</h3>
<ol>
<li><p><strong>Middleware Chaining</strong>: <code>next()</code> allows you to create a chain of middleware functions that can perform various operations on the request and response objects.</p>
</li>
<li><p><strong>Error Handling</strong>: By passing an error to <code>next(error)</code>, you can trigger error-handling middleware, making it easier to manage and debug issues in your application.</p>
</li>
<li><p><strong>Asynchronous Operations</strong>: <code>next()</code> can help manage asynchronous operations, ensuring that your middleware does not block the processing of subsequent middleware.</p>
</li>
</ol>
<h3 id="heading-example">Example:</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = express();

<span class="hljs-keyword">const</span> logger = <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${req.method}</span> <span class="hljs-subst">${req.url}</span>`</span>);
  next(); <span class="hljs-comment">// Passes control to the next middleware</span>
};

<span class="hljs-keyword">const</span> checkAuth = <span class="hljs-function">(<span class="hljs-params">req, res, next</span>) =&gt;</span> {
  <span class="hljs-keyword">if</span> (req.isAuthenticated()) {
    next(); <span class="hljs-comment">// User is authenticated, proceed to the next middleware</span>
  } <span class="hljs-keyword">else</span> {
    res.status(<span class="hljs-number">403</span>).send(<span class="hljs-string">'Forbidden'</span>); <span class="hljs-comment">// User is not authenticated, end the request</span>
  }
};

app.use(logger);
app.use(checkAuth);

app.get(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.send(<span class="hljs-string">'Hello, authenticated user!'</span>);
});

app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Server is running on port 3000'</span>);
});
</code></pre>
<p>In this example, <code>logger</code> and <code>checkAuth</code> are middleware functions. The <code>next()</code> function is used to pass control from one middleware to the next, allowing for modular and reusable code.</p>
<h3 id="heading-key-takeaways">Key Takeaways:</h3>
<ul>
<li><p><strong>Flexibility</strong>: Middleware functions can perform a wide range of tasks such as logging, authentication, and data validation.</p>
</li>
<li><p><strong>Error Management</strong>: Use <code>next(error)</code> to handle errors gracefully.</p>
</li>
<li><p><strong>Asynchronous Control</strong>: Ensure your asynchronous operations don’t block the request-response cycle by using <code>next()</code> effectively.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Middle Of Linked List LeetCode 876]]></title><description><![CDATA[In this blog post, we'll explore an efficient way to find the middle node of a singly linked list using JavaScript. We'll dive into the code and understand the logic behind it step by step.
Link:https://leetcode.com/problems/middle-of-the-linked-list...]]></description><link>https://blog.nadim.in/middle-of-linked-list-leetcode-876</link><guid isPermaLink="true">https://blog.nadim.in/middle-of-linked-list-leetcode-876</guid><category><![CDATA[#linkedlists]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Mon, 05 Aug 2024 05:16:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722834704185/ee2c9e14-cfd6-438d-b4a2-45de89f510ce.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog post, we'll explore an efficient way to find the middle node of a singly linked list using JavaScript. We'll dive into the code and understand the logic behind it step by step.</p>
<p><strong>Link:</strong><a target="_blank" href="https://leetcode.com/problems/middle-of-the-linked-list/">https://leetcode.com/problems/middle-of-the-linked-list/</a></p>
<h3 id="heading-problem-statement">Problem Statement</h3>
<p>Given a non-empty, singly linked list with head node <code>head</code>, return a middle node of the linked list.</p>
<p>If there are two middle nodes, return the second middle node.</p>
<h3 id="heading-approach">Approach</h3>
<p>We can solve this problem using two pointers: a slow pointer and a fast pointer. The slow pointer moves one step at a time while the fast pointer moves two steps at a time. By the time the fast pointer reaches the end of the list, the slow pointer will be at the middle node.</p>
<h3 id="heading-code-explanation">Code Explanation</h3>
<p>Here’s the complete code to find the middle node of a linked list:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> middleNode = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">head</span>) </span>{
    <span class="hljs-keyword">let</span> slowPointer = head;
    <span class="hljs-keyword">let</span> fastPointer = head;

    <span class="hljs-keyword">while</span>(fastPointer !== <span class="hljs-literal">null</span> &amp;&amp; fastPointer.next !== <span class="hljs-literal">null</span>){
        slowPointer = slowPointer.next;
        fastPointer = fastPointer.next.next;
    }

    <span class="hljs-keyword">return</span> slowPointer;
};
</code></pre>
<p>Let's break down the code step by step.</p>
<h3 id="heading-step-by-step-explanation">Step-by-Step Explanation</h3>
<ol>
<li><p><strong>Initialization</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> slowPointer = head;
 <span class="hljs-keyword">let</span> fastPointer = head;
</code></pre>
<p> We initialize two pointers, <code>slowPointer</code> and <code>fastPointer</code>, both pointing to the head of the linked list.</p>
</li>
<li><p><strong>Traversal</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">while</span>(fastPointer !== <span class="hljs-literal">null</span> &amp;&amp; fastPointer.next !== <span class="hljs-literal">null</span>){
     slowPointer = slowPointer.next;
     fastPointer = fastPointer.next.next;
 }
</code></pre>
<p> We use a <code>while</code> loop to move through the linked list. The loop continues until the fast pointer reaches the end of the list.</p>
<ul>
<li><p><strong>Condition</strong>: The loop runs as long as <code>fastPointer</code> and <a target="_blank" href="http://fastPointer.next"><code>fastPointer.next</code></a> are not <code>null</code>. This ensures that the fast pointer can move two steps ahead without encountering <code>null</code>.</p>
</li>
<li><p><strong>Movement</strong>:</p>
<pre><code class="lang-javascript">  slowPointer = slowPointer.next;
  fastPointer = fastPointer.next.next;
</code></pre>
<p>  Inside the loop, we move the slow pointer one step forward (<a target="_blank" href="http://slowPointer.next"><code>slowPointer.next</code></a>) and the fast pointer two steps forward (<a target="_blank" href="http://fastPointer.next.next"><code>fastPointer.next.next</code></a>).</p>
</li>
</ul>
</li>
<li><p><strong>Returning the Middle Node</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">return</span> slowPointer;
</code></pre>
<p> Once the fast pointer reaches the end of the list, the slow pointer will be at the middle node. We return the slow pointer as the result.</p>
</li>
</ol>
<h3 id="heading-why-this-approach-works">Why This Approach Works</h3>
<p>The fast pointer moves twice as fast as the slow pointer. Therefore, by the time the fast pointer reaches the end of the list, the slow pointer will have covered half the distance. This ensures that the slow pointer is positioned at the middle node.</p>
<h3 id="heading-edge-cases">Edge Cases</h3>
<ol>
<li><p><strong>Single Node</strong>: If the linked list has only one node, the function will return that node as both pointers will initially point to the same node.</p>
</li>
<li><p><strong>Even Number of Nodes</strong>: The function will return the second middle node if the linked list has an even number of nodes. This is because the fast pointer will skip over the middle nodes, making the slow pointer land on the second middle node.</p>
</li>
</ol>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Finding the middle node of a linked list using the two-pointer technique is an efficient approach with a time complexity of O(n) and a space complexity of O(1). This method is widely used in various linked list problems due to its simplicity and efficiency.</p>
]]></content:encoded></item><item><title><![CDATA[React Class Components vs. Function Components: State Management]]></title><description><![CDATA[React has evolved significantly since its inception, with function components becoming increasingly popular due to the introduction of hooks. One of the critical aspects of this evolution is how state management differs between class components and f...]]></description><link>https://blog.nadim.in/react-class-components-vs-function-components-state-management</link><guid isPermaLink="true">https://blog.nadim.in/react-class-components-vs-function-components-state-management</guid><category><![CDATA[class vs functional]]></category><category><![CDATA[React]]></category><category><![CDATA[Functional Components]]></category><category><![CDATA[Class Based Components]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Thu, 18 Jul 2024 14:20:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721312358335/6c10cab1-010c-4eeb-8872-7e6d20f162d8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React has evolved significantly since its inception, with function components becoming increasingly popular due to the introduction of hooks. One of the critical aspects of this evolution is how state management differs between class components and function components. In this blog post, we'll explore these differences and discuss the advantages and disadvantages of each approach.</p>
<h2 id="heading-class-components-state-management">Class Components: State Management</h2>
<p>Class components have been a fundamental part of React since its early days. They manage state using the <code>this.state</code> object and the <code>setState</code> method.</p>
<h3 id="heading-example">Example</h3>
<p>Here’s an example of a simple counter implemented as a class component:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { Component } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Counter</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span> </span>{
  <span class="hljs-keyword">constructor</span>(props) {
    <span class="hljs-built_in">super</span>(props);
    <span class="hljs-built_in">this</span>.state = { <span class="hljs-attr">count</span>: <span class="hljs-number">0</span> }; <span class="hljs-comment">// Initial state</span>

    <span class="hljs-comment">// Binding methods</span>
    <span class="hljs-built_in">this</span>.increment = <span class="hljs-built_in">this</span>.increment.bind(<span class="hljs-built_in">this</span>);
    <span class="hljs-built_in">this</span>.decrement = <span class="hljs-built_in">this</span>.decrement.bind(<span class="hljs-built_in">this</span>);
  }

  increment() {
    <span class="hljs-built_in">this</span>.setState(<span class="hljs-function"><span class="hljs-params">prevState</span> =&gt;</span> ({ <span class="hljs-attr">count</span>: prevState.count + <span class="hljs-number">1</span> })); <span class="hljs-comment">// Updating state</span>
  }

  decrement() {
    <span class="hljs-built_in">this</span>.setState(<span class="hljs-function"><span class="hljs-params">prevState</span> =&gt;</span> ({ <span class="hljs-attr">count</span>: prevState.count - <span class="hljs-number">1</span> })); <span class="hljs-comment">// Updating state</span>
  }

  render() {
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Count: {this.state.count}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.increment}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.decrement}</span>&gt;</span>Decrement<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter;
</code></pre>
<h3 id="heading-advantages-of-class-components">Advantages of Class Components</h3>
<ol>
<li><strong>Familiarity</strong>: Many developers are familiar with object-oriented programming, making it easier to understand and use class components.</li>
<li><strong>Lifecycle Methods</strong>: Class components provide built-in lifecycle methods like <code>componentDidMount</code>, <code>componentDidUpdate</code>, and <code>componentWillUnmount</code>, making it easier to manage side effects.</li>
<li><strong>Single Place for State</strong>: State is centralized in one place (<code>this.state</code>), making it easy to understand the current state of the component.</li>
</ol>
<h3 id="heading-disadvantages-of-class-components">Disadvantages of Class Components</h3>
<ol>
<li><strong>Verbosity</strong>: Class components can be verbose, requiring more boilerplate code (e.g., constructor, method binding).</li>
<li><strong>Complexity</strong>: Managing state and lifecycle methods can become complex, especially in large components.</li>
<li><strong>Performance</strong>: Class components can be less performant than function components due to the overhead of <code>this</code> binding and other object-oriented features.</li>
</ol>
<h2 id="heading-function-components-state-management-with-hooks">Function Components: State Management with Hooks</h2>
<p>Function components were initially stateless, but the introduction of hooks, particularly <code>useState</code> and <code>useEffect</code>, allowed them to manage state and side effects.</p>
<h3 id="heading-example-1">Example</h3>
<p>Here’s the same counter example implemented as a function component:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>); <span class="hljs-comment">// Initial state</span>

  <span class="hljs-keyword">const</span> increment = <span class="hljs-function">() =&gt;</span> {
    setCount(<span class="hljs-function"><span class="hljs-params">prevCount</span> =&gt;</span> prevCount + <span class="hljs-number">1</span>); <span class="hljs-comment">// Updating state</span>
  };

  <span class="hljs-keyword">const</span> decrement = <span class="hljs-function">() =&gt;</span> {
    setCount(<span class="hljs-function"><span class="hljs-params">prevCount</span> =&gt;</span> prevCount - <span class="hljs-number">1</span>); <span class="hljs-comment">// Updating state</span>
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Count: {count}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{increment}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{decrement}</span>&gt;</span>Decrement<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter;
</code></pre>
<h3 id="heading-advantages-of-function-components">Advantages of Function Components</h3>
<ol>
<li><strong>Simplicity</strong>: Function components are simpler and require less boilerplate code than class components.</li>
<li><strong>Hooks</strong>: Hooks provide a powerful and flexible way to manage state and side effects, promoting better code reuse and separation of concerns.</li>
<li><strong>Performance</strong>: Function components are generally more performant due to the lack of <code>this</code> binding and other object-oriented overhead.</li>
<li><strong>Readability</strong>: The code is often more readable and easier to understand, especially for those familiar with functional programming concepts.</li>
</ol>
<h3 id="heading-disadvantages-of-function-components">Disadvantages of Function Components</h3>
<ol>
<li><strong>Learning Curve</strong>: Developers need to learn and understand hooks, which can have a steeper learning curve for those new to React or functional programming.</li>
<li><strong>Complexity with Multiple Hooks</strong>: Managing complex state and side effects with multiple hooks can become challenging and sometimes lead to "hook hell."</li>
</ol>
<h2 id="heading-key-differences">Key Differences</h2>
<h3 id="heading-state-initialization">State Initialization</h3>
<ul>
<li><strong>Class Components</strong>: State is initialized in the constructor using <code>this.state</code>.</li>
<li><strong>Function Components</strong>: State is initialized using the <code>useState</code> hook directly in the function body.</li>
</ul>
<h3 id="heading-state-updates">State Updates</h3>
<ul>
<li><strong>Class Components</strong>: State updates are done using the <code>setState</code> method, which can merge state updates.</li>
<li><strong>Function Components</strong>: State updates are done using the state setter function returned by <code>useState</code>, which replaces the state rather than merging.</li>
</ul>
<h3 id="heading-lifecycle-methods">Lifecycle Methods</h3>
<ul>
<li><strong>Class Components</strong>: Provide built-in lifecycle methods for managing side effects.</li>
<li><strong>Function Components</strong>: Use the <code>useEffect</code> hook to manage side effects, which can handle componentDidMount, componentDidUpdate, and componentWillUnmount in one function.</li>
</ul>
<h3 id="heading-boilerplate-code">Boilerplate Code</h3>
<ul>
<li><strong>Class Components</strong>: Require more boilerplate, such as constructors and method binding.</li>
<li><strong>Function Components</strong>: Require less boilerplate, making the code cleaner and more concise.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Both class components and function components have their strengths and weaknesses when it comes to state management in React. Class components offer familiarity and built-in lifecycle methods, while function components provide simplicity, performance benefits, and the power of hooks. </p>
<p>In modern React development, function components with hooks are generally preferred due to their simplicity and flexibility. However, understanding both approaches is crucial for maintaining and upgrading existing React codebases and for making informed decisions in new projects.</p>
]]></content:encoded></item><item><title><![CDATA[How to Use React's useState Hook: A Step-by-Step Guide]]></title><description><![CDATA[React is a powerful library for building user interfaces, and one of its key features is the ability to manage state within functional components. The useState hook is essential for managing local component state, making your components interactive a...]]></description><link>https://blog.nadim.in/how-to-use-reacts-usestate-hook-a-step-by-step-guide</link><guid isPermaLink="true">https://blog.nadim.in/how-to-use-reacts-usestate-hook-a-step-by-step-guide</guid><category><![CDATA[useState]]></category><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[components]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Tue, 16 Jul 2024 08:18:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721117781119/35d8de5f-6b34-4544-8018-fe615e9fb9f8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React is a powerful library for building user interfaces, and one of its key features is the ability to manage state within functional components. The <code>useState</code> hook is essential for managing local component state, making your components interactive and dynamic.</p>
<h2 id="heading-what-is-usestate">What is useState?</h2>
<p><code>useState</code> is a built-in hook that allows you to add state to your functional components. Before hooks, state management was primarily done in class components, but <code>useState</code> enables functional components to hold and manage their state without the need for classes.</p>
<h2 id="heading-how-to-use-usestate">How to Use useState</h2>
<p>To use the <code>useState</code> hook, you need to import it from the React library. Here’s the basic syntax:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> MyComponent = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [state, setState] = useState(initialState);

  <span class="hljs-comment">// Component logic here</span>

  <span class="hljs-keyword">return</span> (
    <span class="hljs-comment">// JSX to render</span>
  );
};
</code></pre>
<h3 id="heading-parameters">Parameters</h3>
<ul>
<li><code>initialState</code>: This is the initial state value. It can be of any type (string, number, object, array, etc.).</li>
</ul>
<h3 id="heading-return-value">Return Value</h3>
<p><code>useState</code> returns an array with two elements:</p>
<ol>
<li><p>The current state value.</p>
</li>
<li><p>A function that allows you to update the state.</p>
</li>
</ol>
<h3 id="heading-example-basic-counter">Example: Basic Counter</h3>
<p>Let’s look at a simple example of a counter component that uses <code>useState</code> to manage its state.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Counter = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>); <span class="hljs-comment">// Initial state is 0</span>

  <span class="hljs-keyword">const</span> increment = <span class="hljs-function">() =&gt;</span> {
    setCount(count + <span class="hljs-number">1</span>); <span class="hljs-comment">// Update state</span>
  };

  <span class="hljs-keyword">const</span> decrement = <span class="hljs-function">() =&gt;</span> {
    setCount(count - <span class="hljs-number">1</span>); <span class="hljs-comment">// Update state</span>
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Count: {count}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{increment}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{decrement}</span>&gt;</span>Decrement<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Counter;
</code></pre>
<h3 id="heading-explanation">Explanation</h3>
<ol>
<li><p><strong>Initial State</strong>: The <code>useState(0)</code> initializes the <code>count</code> state variable to <code>0</code>.</p>
</li>
<li><p><strong>State Update</strong>: The <code>setCount</code> function updates the <code>count</code> state whenever the increment or decrement button is clicked.</p>
</li>
<li><p><strong>Rendering</strong>: The current <code>count</code> is displayed, and buttons trigger the state changes.</p>
</li>
</ol>
<h2 id="heading-updating-state-with-usestate">Updating State with useState</h2>
<p>When updating a state using <code>useState</code>, it’s important to understand how state updates work. State updates can be asynchronous, so using the previous state to calculate the new state is often necessary. Here’s how you can do that:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> increment = <span class="hljs-function">() =&gt;</span> {
  setCount(<span class="hljs-function"><span class="hljs-params">prevCount</span> =&gt;</span> prevCount + <span class="hljs-number">1</span>); <span class="hljs-comment">// Using the previous state</span>
};
</code></pre>
<h2 id="heading-handling-objects-and-arrays">Handling Objects and Arrays</h2>
<p>If your state is an object or an array, you can update it while maintaining immutability by spreading the previous state:</p>
<h3 id="heading-updating-an-object">Updating an Object</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> [user, setUser] = useState({ <span class="hljs-attr">name</span>: <span class="hljs-string">'John'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">30</span> });

<span class="hljs-keyword">const</span> updateName = <span class="hljs-function">(<span class="hljs-params">newName</span>) =&gt;</span> {
  setUser(<span class="hljs-function"><span class="hljs-params">prevUser</span> =&gt;</span> ({ ...prevUser, <span class="hljs-attr">name</span>: newName }));
};
</code></pre>
<h3 id="heading-updating-an-array">Updating an Array</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> [items, setItems] = useState([<span class="hljs-string">'item1'</span>, <span class="hljs-string">'item2'</span>]);

<span class="hljs-keyword">const</span> addItem = <span class="hljs-function">(<span class="hljs-params">newItem</span>) =&gt;</span> {
  setItems(<span class="hljs-function"><span class="hljs-params">prevItems</span> =&gt;</span> [...prevItems, newItem]); <span class="hljs-comment">// Adding a new item</span>
};
</code></pre>
<h2 id="heading-best-practices-for-using-usestate">Best Practices for Using useState</h2>
<ol>
<li><p><strong>Keep State Local</strong>: Only store the state necessary for the component. If multiple components need the same state, consider using context or state management libraries.</p>
</li>
<li><p><strong>Batch State Updates</strong>: If you need to perform multiple state updates, try to batch them together to avoid unnecessary re-renders.</p>
</li>
<li><p><strong>Use Functional Updates</strong>: When the new state depends on the previous state, use the functional update form of the setter function.</p>
</li>
<li><p><strong>Initialization</strong>: If the initial state requires computation, consider using a function to initialize the state:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">const</span> [value, setValue] = useState(<span class="hljs-function">() =&gt;</span> {
   <span class="hljs-comment">// Computation logic here</span>
   <span class="hljs-keyword">return</span> initialValue;
 });
</code></pre>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The <code>useState</code> hook is a powerful and straightforward way to manage the local state in functional components. Understanding how to use it effectively will enable you to create dynamic and interactive React applications. By following best practices, you can ensure that your components remain efficient and maintainable.</p>
]]></content:encoded></item><item><title><![CDATA[Improve Content Loading: The Benefits of Infinite Scrolling]]></title><description><![CDATA[Introduction
In today's fast-paced digital world, users expect seamless and uninterrupted browsing experiences. Infinite scrolling is a web design technique that meets this expectation by continuously loading content as users scroll down a page. This...]]></description><link>https://blog.nadim.in/improve-content-loading-the-benefits-of-infinite-scrolling</link><guid isPermaLink="true">https://blog.nadim.in/improve-content-loading-the-benefits-of-infinite-scrolling</guid><category><![CDATA[#unsplash-api]]></category><category><![CDATA[#image galary]]></category><category><![CDATA[#image-infinnite-scrolling]]></category><category><![CDATA[infinite scrolling]]></category><category><![CDATA[React]]></category><category><![CDATA[CSS]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Mon, 15 Jul 2024 10:25:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721038102299/5bd9d3d0-e913-4a30-8da0-5d8409a2a67d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-introduction">Introduction</h4>
<p>In today's fast-paced digital world, users expect seamless and uninterrupted browsing experiences. Infinite scrolling is a web design technique that meets this expectation by continuously loading content as users scroll down a page. This approach eliminates the need for pagination, creating a more engaging and intuitive user experience. In this blog post, we'll explore what infinite scrolling is, its benefits and drawbacks, and how to implement it in a React application using an API.</p>
<h4 id="heading-what-is-infinite-scrolling">What is Infinite Scrolling?</h4>
<p>Infinite scrolling, also known as endless scrolling, is a web design pattern where additional content is loaded dynamically as the user scrolls down a page. This method is widely used on social media platforms like Facebook, Twitter, and Instagram, as well as news websites and e-commerce stores. Instead of clicking through pagination links, users can continue scrolling to access more content.</p>
<h4 id="heading-benefits-of-infinite-scrolling">Benefits of Infinite Scrolling</h4>
<ol>
<li><p><strong>Improved User Experience</strong>: Users can consume content seamlessly without interruption, making the browsing experience more enjoyable.</p>
</li>
<li><p><strong>Increased Engagement</strong>: Infinite scrolling can keep users engaged on a site longer, as they are more likely to continue scrolling rather than clicking through pages.</p>
</li>
<li><p><strong>Modern Design</strong>: It gives websites a modern, sleek look and feel, aligning with contemporary web design trends.</p>
</li>
<li><p><strong>Mobile Friendliness</strong>: Infinite scrolling is particularly useful on mobile devices where tapping on small pagination links can be cumbersome.</p>
</li>
</ol>
<h4 id="heading-drawbacks-of-infinite-scrolling">Drawbacks of Infinite Scrolling</h4>
<ol>
<li><p><strong>Performance Issues</strong>: Loading large amounts of data can slow down a website and increase load times.</p>
</li>
<li><p><strong>Navigation Difficulties</strong>: Users may find it challenging to return to specific content or track their browsing progress.</p>
</li>
<li><p><strong>SEO Challenges</strong>: Infinite scrolling can make it harder for search engines to index all content, potentially impacting SEO.</p>
</li>
<li><p><strong>Accessibility Concerns</strong>: It may not be suitable for users with disabilities who rely on screen readers or keyboard navigation.</p>
</li>
</ol>
<h4 id="heading-implementing-infinite-scrolling-in-react">Implementing Infinite Scrolling in React</h4>
<p>To demonstrate how to implement infinite scrolling, we'll create a simple image gallery using React and the Unsplash API. The gallery will load more images as the user scrolls down.</p>
<h5 id="heading-step-1-set-up-the-react-project">Step 1: Set Up the React Project</h5>
<p>First, set up a new React project using Create React App:</p>
<pre><code class="lang-sh">npx create-react-app infinite-scroll
<span class="hljs-built_in">cd</span> infinite-scroll
</code></pre>
<h5 id="heading-step-2-install-dependencies">Step 2: Install Dependencies</h5>
<p>We'll use the Fetch API to request data from the Unsplash API. No additional dependencies are needed.</p>
<h5 id="heading-step-3-create-the-infinitescroll-component">Step 3: Create the InfiniteScroll Component</h5>
<p>Create a new file <code>InfiniteScroll.js</code> and add the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useCallback, useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'../App.css'</span>; <span class="hljs-comment">// Make sure to update the path if your CSS file is located elsewhere</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">InfiniteScroll</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [items, setItems] = useState([]);
    <span class="hljs-keyword">const</span> [hasMore, setHasMore] = useState(<span class="hljs-literal">true</span>);
    <span class="hljs-keyword">const</span> [page, setPage] = useState(<span class="hljs-number">1</span>);

    <span class="hljs-keyword">const</span> fetchItems = useCallback(<span class="hljs-keyword">async</span> () =&gt; {
        <span class="hljs-keyword">try</span> {
            <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`https://api.unsplash.com/photos?page=<span class="hljs-subst">${page}</span>&amp;client_id=YOUR ACCESS KEY`</span>);
            <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> response.json();
            setItems(<span class="hljs-function"><span class="hljs-params">prevItems</span> =&gt;</span> [...prevItems, ...data]);
            <span class="hljs-keyword">if</span> (data.length === <span class="hljs-number">0</span>) {
                setHasMore(<span class="hljs-literal">false</span>);
            }
        } <span class="hljs-keyword">catch</span> (error) {
            <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Error fetching items:'</span>, error);
        }
    }, [page]);



    useEffect(<span class="hljs-function">() =&gt;</span> {
        fetchItems();
    }, [fetchItems]);

    <span class="hljs-keyword">const</span> handleScroll = <span class="hljs-function">() =&gt;</span> {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">window</span>.innerHeight + <span class="hljs-built_in">document</span>.documentElement.scrollTop &gt;= <span class="hljs-built_in">document</span>.documentElement.offsetHeight - <span class="hljs-number">500</span> &amp;&amp; hasMore) {
            setPage(<span class="hljs-function"><span class="hljs-params">prevPage</span> =&gt;</span> prevPage + <span class="hljs-number">1</span>);
        }
    };

    useEffect(<span class="hljs-function">() =&gt;</span> {
        <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">'scroll'</span>, handleScroll);
        <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">window</span>.removeEventListener(<span class="hljs-string">'scroll'</span>, handleScroll);
    }, [hasMore]);

    <span class="hljs-keyword">return</span> (

        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"container"</span>&gt;</span>
            {items.map((item, index) =&gt; (
                <span class="hljs-tag">&lt;<span class="hljs-name">figure</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{item.urls.small}</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">{item.alt_description}</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"image card"</span> /&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">figure</span>&gt;</span>
            ))}
            {hasMore &amp;&amp; <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"loading"</span>&gt;</span>Loading more items...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>}
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> InfiniteScroll;
</code></pre>
<p>Replace <code>YOUR_ACCESS_KEY</code> with your Unsplash API access key.</p>
<h5 id="heading-step-4-style-the-component">Step 4: Style the Component</h5>
<p>Create or update the <code>App.css</code> file with the following styles to make the gallery visually appealing:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f4f4f9</span>;
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">'Roboto'</span>, Arial, Helvetica, sans-serif;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#333</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
}
<span class="hljs-selector-class">.logo</span>{
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span> ;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
}

<span class="hljs-selector-class">.card</span>{
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">display</span>: block;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
  <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.3s</span> ease-in-out;
}

<span class="hljs-selector-tag">img</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1.05</span>);
}

<span class="hljs-selector-tag">figure</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">1</span>fr auto;
  <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">break-inside</span>: avoid;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">8px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.1</span>);
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">transition</span>: box-shadow <span class="hljs-number">0.3s</span> ease-in-out;
}

<span class="hljs-selector-tag">figure</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">8px</span> <span class="hljs-number">16px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>);
}

<span class="hljs-selector-tag">figure</span> &gt; <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">1</span> / -<span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span>;
}

<span class="hljs-selector-tag">figure</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#333</span>;
  <span class="hljs-attribute">text-decoration</span>: none;
}

<span class="hljs-selector-tag">figcaption</span> {
  <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">2</span>;
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">rgba</span>(<span class="hljs-number">255</span>, <span class="hljs-number">255</span>, <span class="hljs-number">255</span>, <span class="hljs-number">0.9</span>);
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.5em</span> <span class="hljs-number">1em</span>;
  <span class="hljs-attribute">justify-self</span>: start;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.9em</span>;
}

<span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">column-count</span>: <span class="hljs-number">4</span>;
  <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1200px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1200px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">column-count</span>: <span class="hljs-number">3</span>;
  }
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">900px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">column-count</span>: <span class="hljs-number">2</span>;
  }
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">600px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">column-count</span>: <span class="hljs-number">1</span>;
  }
}
</code></pre>
<h5 id="heading-step-5-use-the-component">Step 5: Use the Component</h5>
<p>In your <code>App.js</code> file, import and use the <code>InfiniteScroll</code> component:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> InfiniteScroll <span class="hljs-keyword">from</span> <span class="hljs-string">'./InfiniteScroll'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">InfiniteScroll</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h4 id="heading-conclusion">Conclusion</h4>
<p>Infinite scrolling is a powerful technique to enhance user experience by providing a seamless and engaging way to browse content. While it has its drawbacks, careful implementation can mitigate many of these issues. By following the steps outlined above, you can add infinite scrolling to your React applications, creating a modern and user-friendly interface. Experiment with the design and functionality to best suit your project's needs and always keep user experience at the forefront of your design decisions.</p>
<p><a target="_blank" href="https://github.com/anwarnadim7/infinite-scroll">GITHUB LINK</a></p>
]]></content:encoded></item><item><title><![CDATA[Understanding the <!DOCTYPE html> Declaration]]></title><description><![CDATA[In web development, ensuring that your website displays correctly across different browsers is crucial. One small but significant part of this puzzle is the <!DOCTYPE html> declaration. This article will help you understand what <!DOCTYPE html> is, w...]]></description><link>https://blog.nadim.in/understanding-the-doctype-html-declaration</link><guid isPermaLink="true">https://blog.nadim.in/understanding-the-doctype-html-declaration</guid><category><![CDATA[html, doctype, web-development, web-standards, quirks-mode, html5, xhtml, standards-compliance, browser-rendering, best-practices]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[website]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Developer]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Mon, 15 Jul 2024 03:02:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721012470923/74cff451-e9f2-42ed-ad0f-1070464837cd.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In web development, ensuring that your website displays correctly across different browsers is crucial. One small but significant part of this puzzle is the <code>&lt;!DOCTYPE html&gt;</code> declaration. This article will help you understand what <code>&lt;!DOCTYPE html&gt;</code> is, why it’s important, and how to use it correctly.</p>
<h2 id="heading-what-is">What is <code>&lt;!DOCTYPE html&gt;</code>?</h2>
<p>The <code>&lt;!DOCTYPE html&gt;</code> declaration is a statement that appears at the very top of an HTML document, before the <code>&lt;html&gt;</code> tag. It is an instruction to the web browser about the version of HTML the page is written in.</p>
<h2 id="heading-purpose-of">Purpose of <code>&lt;!DOCTYPE html&gt;</code></h2>
<p>The primary purpose of the <code>&lt;!DOCTYPE html&gt;</code> declaration is to ensure that the web browser renders the document in standards-compliant mode. This mode ensures that the web page adheres to the rules and behaviors defined by the HTML specification, which helps to maintain consistency and predictability in how web pages are displayed.</p>
<h3 id="heading-html5-doctype">HTML5 Doctype</h3>
<p>With the introduction of HTML5, the doctype declaration became significantly simpler than its predecessors. In HTML5, the declaration is simply:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
</code></pre>
<p>This simplicity makes it easier to remember and reduces the likelihood of errors.</p>
<h3 id="heading-importance-of">Importance of <code>&lt;!DOCTYPE html&gt;</code></h3>
<p>Including the <code>&lt;!DOCTYPE html&gt;</code> declaration in your HTML documents is important for several reasons:</p>
<ol>
<li><p><strong>Standards Mode</strong>: Ensures the browser renders the document in standards mode, which adheres to the latest HTML specifications.</p>
</li>
<li><p><strong>Consistency</strong>: Helps maintain consistent rendering across different browsers.</p>
</li>
<li><p><strong>Compatibility</strong>: Avoids quirks mode, where browsers emulate older, non-standard behaviors to support legacy websites. This can lead to inconsistent and unpredictable rendering.</p>
</li>
</ol>
<h4 id="heading-quirks-mode-vs-standards-mode">Quirks Mode vs. Standards Mode</h4>
<p>When a web browser encounters an HTML document, it can render it in one of two modes: quirks mode or standards mode.</p>
<ul>
<li><p><strong>Standards Mode</strong>: The browser adheres strictly to the HTML and CSS specifications. This mode ensures that modern web standards are followed, providing a consistent experience across different browsers.</p>
</li>
<li><p><strong>Quirks Mode</strong>: The browser attempts to emulate the non-standard behaviors of older browsers to ensure backward compatibility with legacy websites. This mode can lead to rendering issues and inconsistencies.</p>
</li>
</ul>
<p>By including the <code>&lt;!DOCTYPE html&gt;</code> declaration, you ensure that the browser uses standards mode, avoiding the pitfalls of quirks mode.</p>
<h3 id="heading-problems-you-might-face-without">Problems You Might Face Without <code>&lt;!DOCTYPE html&gt;</code></h3>
<p>If you omit the <code>&lt;!DOCTYPE html&gt;</code> declaration at the beginning of your HTML document, the web browser may encounter several issues. Here are some of the problems you might face:</p>
<h4 id="heading-1-browser-quirks-mode">1. <strong>Browser Quirks Mode</strong></h4>
<p>When the <code>&lt;!DOCTYPE html&gt;</code> declaration is missing, most browsers switch to quirks mode instead of standards mode. In quirks mode, browsers attempt to render the page using outdated, non-standard behaviors to maintain compatibility with older websites. This can lead to several problems:</p>
<ul>
<li><p><strong>Inconsistent Rendering</strong>: Different browsers may display your web page differently, leading to an inconsistent user experience.</p>
</li>
<li><p><strong>CSS Issues</strong>: Modern CSS may not work as expected. For example, the box model might be interpreted incorrectly, causing layout issues.</p>
</li>
<li><p><strong>JavaScript Bugs</strong>: JavaScript may not behave as intended because quirks mode can affect the Document Object Model (DOM) and how scripts interact with the page.</p>
</li>
</ul>
<h4 id="heading-2-compatibility-problems">2. <strong>Compatibility Problems</strong></h4>
<p>Without <code>&lt;!DOCTYPE html&gt;</code>, your website might not be compatible with modern web standards, which can cause issues such as:</p>
<ul>
<li><p><strong>HTML5 Features</strong>: Newer HTML5 features and elements might not be supported correctly, limiting the functionality and interactivity of your web pages.</p>
</li>
<li><p><strong>CSS3 Features</strong>: Advanced CSS3 features and properties may not be interpreted correctly, leading to styling problems.</p>
</li>
</ul>
<h4 id="heading-3-seo-and-accessibility-issues">3. <strong>SEO and Accessibility Issues</strong></h4>
<p>Modern search engines and accessibility tools expect web pages to follow web standards. Omitting the <code>&lt;!DOCTYPE html&gt;</code> declaration can negatively impact:</p>
<ul>
<li><p><strong>Search Engine Optimization (SEO)</strong>: Search engines might not index your site correctly, leading to lower search rankings.</p>
</li>
<li><p><strong>Accessibility</strong>: Tools that assist users with disabilities might not work properly, making your website less accessible to all users.</p>
</li>
</ul>
<h4 id="heading-4-performance-issues">4. <strong>Performance Issues</strong></h4>
<p>Quirks mode can affect the performance of your website:</p>
<ul>
<li><p><strong>Rendering Performance</strong>: Browsers might take longer to render your pages because they need to switch between modern and legacy rendering modes.</p>
</li>
<li><p><strong>JavaScript Performance</strong>: JavaScript execution can be slower and more error-prone due to differences in the DOM and scripting environment.</p>
</li>
</ul>
<h4 id="heading-example-of-problems-without">Example of Problems Without <code>&lt;!DOCTYPE html&gt;</code></h4>
<p>Consider the following example where <code>&lt;!DOCTYPE html&gt;</code> is omitted:</p>
<pre><code class="lang-c">htmlCopy code&lt;html lang=<span class="hljs-string">"en"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;
    &lt;title&gt;Quirks Mode Example&lt;/title&gt;
    &lt;style&gt;
        div {
            width: <span class="hljs-number">200</span>px;
            padding: <span class="hljs-number">10</span>px;
            border: <span class="hljs-number">5</span>px solid black;
            margin: <span class="hljs-number">10</span>px;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div&gt;Box Model Test&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>In quirks mode, the browser may interpret the box model incorrectly, resulting in a div that is not 200px wide but larger due to the padding and border being added to the width.</p>
<h3 id="heading-solution-always-include">Solution: Always Include <code>&lt;!DOCTYPE html&gt;</code></h3>
<p>To avoid these issues, always include the <code>&lt;!DOCTYPE html&gt;</code> declaration at the very beginning of your HTML documents:</p>
<pre><code class="lang-c">htmlCopy code&lt;!DOCTYPE html&gt;
&lt;html lang=<span class="hljs-string">"en"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;
    &lt;title&gt;Standards Mode Example&lt;/title&gt;
    &lt;style&gt;
        div {
            width: <span class="hljs-number">200</span>px;
            padding: <span class="hljs-number">10</span>px;
            border: <span class="hljs-number">5</span>px solid black;
            margin: <span class="hljs-number">10</span>px;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div&gt;Box Model Test&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Including <code>&lt;!DOCTYPE html&gt;</code> ensures the browser uses standards mode, providing a consistent and predictable rendering of your web page.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>The <code>&lt;!DOCTYPE html&gt;</code> declaration may seem like a small detail, but it plays a crucial role in web development. It ensures that your web pages are rendered consistently and correctly across different browsers by adhering to modern web standards. Always include <code>&lt;!DOCTYPE html&gt;</code> at the beginning of your HTML documents to take advantage of these benefits.</p>
<p>By understanding and using <code>&lt;!DOCTYPE html&gt;</code> correctly, you can create more reliable, predictable, and maintainable web pages, ensuring a better experience for your users.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with HTML: The Foundation of Web Design]]></title><description><![CDATA[Introduction:
Welcome to the first post in our "Mastering Web Design: HTML & CSS" series. In this post, we’ll dive into HTML, the fundamental building block of web pages. You'll learn what HTML is, why it's important, and how to create your first HTM...]]></description><link>https://blog.nadim.in/getting-started-with-html-the-foundation-of-web-design</link><guid isPermaLink="true">https://blog.nadim.in/getting-started-with-html-the-foundation-of-web-design</guid><category><![CDATA[HTML5]]></category><category><![CDATA[Browsers]]></category><category><![CDATA[headings]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[website]]></category><category><![CDATA[HTML tags ]]></category><category><![CDATA[HTML CSS JAVASCRIPT]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Mon, 15 Jul 2024 02:49:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721011439340/5b07e452-8e5d-42b3-b079-e1b3976af83a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction:</strong></h2>
<p>Welcome to the first post in our "Mastering Web Design: HTML &amp; CSS" series. In this post, we’ll dive into HTML, the fundamental building block of web pages. You'll learn what HTML is, why it's important, and how to create your first HTML document.</p>
<h2 id="heading-1-what-is-html"><strong>1. What is HTML?</strong></h2>
<p>HTML, or HyperText Markup Language, is the standard language used to create web pages. It provides the structure of a webpage, allowing you to organize content and define elements such as headings, paragraphs, links, and images. HTML is essential for web development because it forms the backbone of all websites.</p>
<h2 id="heading-2-basic-structure-of-an-html-document"><strong>2. Basic Structure of an HTML Document</strong></h2>
<p>Every HTML document follows a basic structure. Here’s an overview of the essential tags:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>My First HTML Page<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph of text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<ul>
<li><p><code>&lt;!DOCTYPE html&gt;</code>: Declares the document type and version of HTML.</p>
</li>
<li><p><code>&lt;html&gt;</code>: The root element that contains all other HTML elements.</p>
</li>
<li><p><code>&lt;head&gt;</code>: Contains meta-information about the document, such as the title.</p>
</li>
<li><p><code>&lt;title&gt;</code>: Sets the title of the webpage, which appears in the browser tab.</p>
</li>
<li><p><code>&lt;body&gt;</code>: Contains the content of the webpage that is displayed to users.</p>
</li>
</ul>
<h2 id="heading-3-common-html-elements"><strong>3. Common HTML Elements</strong></h2>
<p>Here are some basic HTML elements you’ll use frequently:</p>
<ul>
<li><p><strong>Headings:</strong> Define headings using <code>&lt;h1&gt;</code> to <code>&lt;h6&gt;</code>. <code>&lt;h1&gt;</code> is the main heading, while <code>&lt;h6&gt;</code> is the smallest.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Main Heading<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Subheading<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Paragraphs:</strong> Use <code>&lt;p&gt;</code> to define a paragraph of text.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Links:</strong> Use <code>&lt;a&gt;</code> to create hyperlinks. The <code>href</code> attribute specifies the URL.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.example.com"</span>&gt;</span>Visit Example<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Images:</strong> Use <code>&lt;img&gt;</code> to embed images. The <code>src</code> attribute specifies the image source, and <code>alt</code> provides alternative text.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Description of image"</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Lists:</strong> Create ordered lists with <code>&lt;ol&gt;</code> and unordered lists with <code>&lt;ul&gt;</code>. Use <code>&lt;li&gt;</code> for list items.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
</li>
</ul>
<h2 id="heading-4-creating-your-first-html-page"><strong>4. Creating Your First HTML Page</strong></h2>
<p>Let’s create a basic HTML page step-by-step.</p>
<ol>
<li><p>Open your text editor (like VS Code or Notepad++).</p>
</li>
<li><p>Type the following code:</p>
<pre><code class="lang-html"> <span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>My First HTML Page<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Welcome to My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is a paragraph of text.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.example.com"</span>&gt;</span>Visit Example<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Description of image"</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
</li>
<li><p>Save the file with a <code>.html</code> extension, like <code>index.html</code>.</p>
</li>
<li><p>Open the file in your web browser to see your first HTML page in action!</p>
</li>
</ol>
<h2 id="heading-5-best-practices"><strong>5. Best Practices</strong></h2>
<p>Here are some tips for writing clean and semantic HTML:</p>
<ul>
<li><p><strong>Use Proper Indentation:</strong> Indent nested elements for better readability.</p>
</li>
<li><p><strong>Write Semantic HTML:</strong> Use HTML elements according to their meaning (e.g., <code>&lt;header&gt;</code>, <code>&lt;footer&gt;</code>, <code>&lt;article&gt;</code>).</p>
</li>
<li><p><strong>Comment Your Code:</strong> Use <code>&lt;!-- comment --&gt;</code> to add comments and explain sections of your code.</p>
</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion:</strong></h3>
<p>In this post, you learned about the basics of HTML, including its importance, structure, and common elements. You also created your first HTML page. In the next post, we’ll explore how to style your HTML pages using CSS.</p>
<p><strong>Call to Action:</strong></p>
<p>Now it's your turn! Create your own HTML document using the examples provided and experiment with different elements. If you have any questions or comments, feel free to leave them below. Stay tuned for our next post where we dive into CSS!</p>
]]></content:encoded></item><item><title><![CDATA[What Is Big O Notation? A Beginner's Explanation]]></title><description><![CDATA[Big O notation is a mathematical concept used to describe an algorithm's performance or complexity. It shows how the runtime or space needs of an algorithm increase as the input size grow. If the pace of an algorithm is not known, it will be difficul...]]></description><link>https://blog.nadim.in/what-is-big-o-notation-a-beginners-explanation</link><guid isPermaLink="true">https://blog.nadim.in/what-is-big-o-notation-a-beginners-explanation</guid><category><![CDATA[#BigONotation ]]></category><category><![CDATA[data structures]]></category><category><![CDATA[timecomplexity]]></category><category><![CDATA[Space Complexity]]></category><category><![CDATA[FileTransferProtocol]]></category><category><![CDATA[big o]]></category><category><![CDATA[array]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Java]]></category><category><![CDATA[runtime]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Sun, 14 Jul 2024 04:46:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720927404360/c6e259f9-f0c0-4779-bad1-3b3496538b92.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Big O notation is a mathematical concept used to describe an algorithm's performance or complexity. It shows how the runtime or space needs of an algorithm increase as the input size grow. If the pace of an algorithm is not known, it will be difficult to determine the program's efficiency. Big O notation helps describe how much time an algorithm will take to run as the size of the input grows.</p>
<h2 id="heading-what-is-time-complexity">What is Time Complexity?</h2>
<p>A way of showing how the runtime of a function increases as the size of an input increases</p>
<h2 id="heading-what-is-space-complexity">What is Space Complexity?</h2>
<p>Space complexity is a way of showing how the memory usage of a function increases as the size of the input increases.</p>
<p>Let's understand with an example</p>
<p>Imagine a scenario where you have a file on your hard drive and you need to send it to your friend you need to send the file as soon as possible</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720929311530/5e7f4b87-f1bd-4c6c-8883-7305ec609a8c.jpeg" alt="file to system" class="image--center mx-auto" /></p>
<p>Send it via email, FTP, or another electronic transfer method.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>File Size</td><td>Physical Transfer</td><td>Electronic Transfer</td></tr>
</thead>
<tbody>
<tr>
<td><strong>1 MB</strong></td><td><strong>Take Time:</strong> Time remains constant, independent of file size</td><td>Quickly: The time taken to transfer a file increases with the size of the file.</td></tr>
<tr>
<td><strong>1 TB or Large</strong></td><td>It can be done in a day</td><td>This size of file can take more than one day to transfer</td></tr>
</tbody>
</table>
</div><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720930268900/5bfb7cfc-19cb-4d3d-b418-84f8117e6f1d.png" alt="Performance variation based on size" class="image--center mx-auto" /></p>
<p>Performance variation of an algorithm based on input</p>
<p>Let's understand with an example.</p>
<p>Suppose we want to buy a brand-new car. Obviously, we want to know more about the car's performance, which means we are interested in knowing how many liters of petrol it takes to drive 100 miles.</p>
<p>In the case of a car, there is no standard answer. Even though the manual mentions that it takes 70 liters of petrol for 100 miles, this information may not be correct since a car performs differently based on the conditions.</p>
<ul>
<li><p>City Traffic - 20 L</p>
</li>
<li><p>Highway - 10 L</p>
</li>
<li><p>Mixed Condition - 15 L</p>
</li>
</ul>
<p>So, here we see that the same car performs differently based on the conditions in which we drive it.</p>
<p>Similarly, based on the conditions given, an algorithm performs differently.</p>
<p>There are three scenarios for measuring any given algorithm:</p>
<ul>
<li><p>Best Case</p>
</li>
<li><p>Average Case</p>
</li>
<li><p>Worst Case</p>
</li>
</ul>
<p>Three Greek letters are used to define the cases of an algorithm.</p>
<p><strong>Omega (Ω), Theta (Θ), and Omicron (O) also known as Big O</strong></p>
<p>Let's consider an example</p>
<p>We have an array containing a list of numbers, and we need to find a specific number.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720931275926/5f50605d-2a25-4610-bdf0-9f6d1313c9ed.jpeg" alt="Array of 8 elements" class="image--center mx-auto" /></p>
<ol>
<li><p>Find 1 - It is at the beginning of the array.</p>
</li>
<li><p>Find 8 - It is at the end of the array.</p>
</li>
<li><p>Find 4 - It is at the 4th position in the array.</p>
</li>
</ol>
<p>So, finding 1 is quick and easy, but to find 8, we need to go through the entire array and check each element until we reach the end.</p>
<ol>
<li><p><strong>Find 1 - Ω</strong> time complexity <strong>Best Case</strong></p>
</li>
<li><p><strong>Find 4 - Θ</strong> time complexity <strong>Average Case</strong></p>
</li>
<li><p><strong>Find 8 - O</strong> time complexity <strong>Worst Case</strong></p>
</li>
</ol>
<h2 id="heading-runtime-complexity-of-an-algorithm">Runtime complexity of an algorithm</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Complexity</td><td>Name</td><td>Sample</td></tr>
</thead>
<tbody>
<tr>
<td>O(1)</td><td>Constant</td><td>A simple add number function</td></tr>
<tr>
<td>O(N)</td><td>Linear</td><td>Loop through numbers from 1 to n</td></tr>
<tr>
<td>O(log N)</td><td>Logarithmic</td><td>Find an element in a sorted array</td></tr>
<tr>
<td>O(N²)</td><td>Quadratic</td><td>Nested Loops</td></tr>
</tbody>
</table>
</div><ul>
<li><p>O(1) - Order of 1</p>
</li>
<li><p>O(N) - Order of N</p>
</li>
<li><p>O(log N) - Order of log N</p>
</li>
<li><p>O(N²) - Order of N²</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Data Structures for Beginners: Essential Concepts Simplified]]></title><description><![CDATA[What is Data Structure?
A data structure is a way of organizing data so that it can be used effectively and efficiently. From a code design perspective, we need to pay particular attention to the way data is structured. If data isn’t stored properly,...]]></description><link>https://blog.nadim.in/data-structures-for-beginners-essential-concepts-simplified</link><guid isPermaLink="true">https://blog.nadim.in/data-structures-for-beginners-essential-concepts-simplified</guid><category><![CDATA[#nadim.in]]></category><category><![CDATA[datastructure]]></category><category><![CDATA[DSA]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[introduction]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[Recursion]]></category><category><![CDATA[backtracking]]></category><category><![CDATA[divide and conquer]]></category><category><![CDATA[greedy]]></category><category><![CDATA[algorithm]]></category><category><![CDATA[bruteforcing]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Sun, 14 Jul 2024 02:50:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720925241232/f8787d1c-38a8-44d9-a90f-0d8f041cb515.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-data-structure">What is Data Structure?</h2>
<p>A data structure is a way of organizing data so that it can be used effectively and efficiently. From a code design perspective, we need to pay particular attention to the way data is structured. If data isn’t stored properly, efficiently, or correctly structured, then the overall performance of the code will be reduced.</p>
<h2 id="heading-what-is-an-algorithm">What is an Algorithm?</h2>
<p>It is a set of instructions to perform a task.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720917697966/6ca7e07f-28d9-44d7-844c-a672af9d89c1.jpeg" alt class="image--center mx-auto" /></p>
<p>Let's consider a scenario to understand the importance of data structure and algorithms.</p>
<p>Imagine we have a disorganized bunch of wood, and we want to choose a specific color, such as black. Since the wood is not organized, finding the desired color would be time-consuming as we would need to check each piece one by one.</p>
<p>Now, if we organize the wood based on color, finding any color of wood becomes easy. This is similar to what data structure does in applications. All applications deal with data and perform operations on that data. Before processing the data, it's organized in a way that makes the process efficient.</p>
<p>So, if we want to use organized wooden pieces for flooring, certain tasks need to be accomplished.</p>
<h2 id="heading-types-of-data-structure">Types of data structure</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720921767705/6b3da1c4-3980-4622-b077-694e901d425b.jpeg" alt class="image--center mx-auto" /></p>
<p><strong>Primitive:</strong> Data structures built into the programming language itself, available for the programmer.</p>
<p><strong>Non-Primitive:</strong> Also known as user-defined data structures. They are created by combining two or more primitive data structures.</p>
<p><strong>Linear:</strong> Items are arranged in memory in a linear, sequential manner. They can be either static or dynamic.</p>
<p><strong>Static:</strong> Sizes and structures associated with memory location are fixed at compile time.</p>
<p><strong>Dynamic:</strong> Also known as non-static, the memory location changes every compile time.</p>
<p><strong>Non-Linear:</strong> Data is connected to several other items and is not organized sequentially.</p>
<h2 id="heading-types-of-algorithms">Types of algorithms</h2>
<p>Algorithms can be classified based on the problem they are trying to solve based on the working principle, there are eight different types of algorithms</p>
<ol>
<li><p>Simple recursive algorithms</p>
</li>
<li><p>Backtracking Algorithms</p>
</li>
<li><p>Divide and Conquer Algorithms</p>
</li>
<li><p>Dynamic Programming Algorithms</p>
</li>
<li><p>Greedy Algorithms</p>
</li>
<li><p>Brach &amp; Bound Algorithms</p>
</li>
<li><p>Brute Force Algorithms</p>
</li>
<li><p>Randomized Algorithms</p>
</li>
</ol>
<h2 id="heading-what-makes-a-good-algorithm">What makes a good algorithm?</h2>
<p>A good algorithm typically has the following characteristics:</p>
<ol>
<li><p><strong>Correctness</strong>: Make sure the algorithm solves the problem correctly. Test it with different inputs to see if it always produces the right output.</p>
</li>
<li><p><strong>Efficiency</strong>: Try to write an algorithm that runs quickly and doesn't use too much memory. This means understanding basic concepts like time and space complexity, even at a high level.</p>
</li>
<li><p><strong>Simplicity</strong>: Keep your algorithm simple. Avoid over-complicating your solution. Clear and simple code is easier to understand and debug.</p>
</li>
<li><p><strong>Robustness</strong>: Your algorithm should be able to handle unexpected inputs without crashing. Think about edge cases and test them.</p>
</li>
<li><p><strong>Scalability</strong>: As you get more comfortable, start thinking about how your algorithm performs with larger inputs. Does it slow down significantly? If so, you might need to find a more efficient approach.</p>
</li>
<li><p><strong>Readability</strong>: Write your code in a way that others (and you in the future) can easily read and understand it. Use meaningful variable names, and add comments if needed.</p>
</li>
</ol>
<h3 id="heading-example-find-the-largest-among-three-numbers"><strong>Example: Find the Largest Among Three Numbers</strong></h3>
<ol>
<li><p><strong>Start</strong></p>
</li>
<li><p><strong>Declare</strong> variables <code>a</code>, <code>b</code>, and <code>c</code>.</p>
</li>
<li><p><strong>Read</strong> values for variables <code>a</code>, <code>b</code>, and <code>c</code>.</p>
</li>
<li><p><strong>Compare</strong> the values:</p>
<ul>
<li><p>If <code>a</code> is greater than <code>b</code>:</p>
<ul>
<li><p>If <code>a</code> is also greater than <code>c</code>:</p>
<ul>
<li><strong>Display</strong><code>a</code> is the largest number.</li>
</ul>
</li>
<li><p>Else:</p>
<ul>
<li><strong>Display</strong><code>c</code> is the largest number.</li>
</ul>
</li>
</ul>
</li>
<li><p>Else:</p>
<ul>
<li><p>If <code>b</code> is greater than <code>c</code>:</p>
<ul>
<li><strong>Display</strong><code>b</code> is the largest number.</li>
</ul>
</li>
<li><p>Else:</p>
<ul>
<li><strong>Display</strong><code>c</code> is the largest number.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Stop</strong></p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[How to Optimize Web Apps Using Lazy Loading and Code Splitting]]></title><description><![CDATA[In the world of web development, performance is key. Users expect fast, responsive applications that load quickly and provide a seamless experience. Two powerful techniques to achieve these goals are lazy loading and code splitting. These strategies ...]]></description><link>https://blog.nadim.in/how-to-optimize-web-apps-using-lazy-loading-and-code-splitting</link><guid isPermaLink="true">https://blog.nadim.in/how-to-optimize-web-apps-using-lazy-loading-and-code-splitting</guid><category><![CDATA[lazyload]]></category><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[lazy loading]]></category><category><![CDATA[optimization]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Thu, 11 Jul 2024 13:18:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720704821480/95a41325-e00b-4d5b-ba9f-e5c2b4e07069.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the world of web development, performance is key. Users expect fast, responsive applications that load quickly and provide a seamless experience. Two powerful techniques to achieve these goals are lazy loading and code splitting. These strategies are essential for optimizing web applications, especially those built with modern JavaScript frameworks like React.</p>
<h2 id="heading-understanding-lazy-loading">Understanding Lazy Loading</h2>
<p>Lazy loading is a design pattern that defers the loading of non-critical resources until they are needed. Instead of loading everything at once, which can slow down the initial page load, lazy loading ensures that only the essential parts of the application are loaded first. Additional resources are fetched as they become necessary, improving overall performance and user experience.</p>
<h4 id="heading-key-benefits-of-lazy-loading">Key Benefits of Lazy Loading:</h4>
<ul>
<li><p><strong>Improved Performance</strong>: By loading only the necessary components initially, the initial load time is reduced, leading to a faster, more responsive application.</p>
</li>
<li><p><strong>Reduced Bandwidth Usage</strong>: Only the required resources are loaded, saving bandwidth and reducing data usage.</p>
</li>
<li><p><strong>Enhanced User Experience</strong>: Users can interact with the essential parts of the application more quickly, while other parts load in the background.</p>
</li>
</ul>
<h4 id="heading-implementing-lazy-loading-in-react">Implementing Lazy Loading in React</h4>
<p>In React, lazy loading can be implemented using <code>React.lazy</code> and <code>Suspense</code>. Here's an example:</p>
<pre><code class="lang-plaintext">import React, { Suspense } from 'react';

const LazyComponent = React.lazy(() =&gt; import('./LazyComponent'));

function App() {
  return (
    &lt;div&gt;
      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;
        &lt;LazyComponent /&gt;
      &lt;/Suspense&gt;
    &lt;/div&gt;
  );
}

export default App;
</code></pre>
<p>In this example, the <code>LazyComponent</code> is loaded only when it is needed. The <code>Suspense</code> component is used to display a fallback (e.g., a loading spinner) while the component is being loaded.</p>
<h3 id="heading-understanding-code-splitting">Understanding Code Splitting</h3>
<p>Code splitting is a technique to split your code into various bundles that can be loaded on demand or in parallel. This approach reduces the size of the initial bundle, speeding up the initial load time of your application.</p>
<h4 id="heading-key-benefits-of-code-splitting">Key Benefits of Code Splitting:</h4>
<ul>
<li><p><strong>Optimized Load Time</strong>: By splitting code into smaller bundles, the browser loads only the necessary code for the current page, reducing the initial load time.</p>
</li>
<li><p><strong>Improved Performance</strong>: It prevents loading the entire application codebase at once, which can significantly enhance performance, especially for large applications.</p>
</li>
<li><p><strong>Enhanced User Experience</strong>: Users can start interacting with the application faster, as the critical parts load quicker.</p>
</li>
</ul>
<h4 id="heading-implementing-code-splitting-in-react">Implementing Code Splitting in React</h4>
<p>In React, code splitting can be achieved using dynamic <code>import()</code> statements. Here's an example:</p>
<pre><code class="lang-plaintext">import React, { Component } from 'react';

class App extends Component {
  state = {
    Component: null
  };

  loadComponent = () =&gt; {
    import('./MyComponent').then(Component =&gt; {
      this.setState({ Component: Component.default });
    });
  };

  render() {
    const { Component } = this.state;
    return (
      &lt;div&gt;
        &lt;button onClick={this.loadComponent}&gt;Load Component&lt;/button&gt;
        {Component &amp;&amp; &lt;Component /&gt;}
      &lt;/div&gt;
    );
  }
}

export default App;
</code></pre>
<p>In this example, the <code>MyComponent</code> is loaded only when the button is clicked, demonstrating code splitting in action.</p>
<h3 id="heading-combining-lazy-loading-and-code-splitting">Combining Lazy Loading and Code Splitting</h3>
<p>These techniques are often used together to optimize performance and user experience. Lazy loading components that are code-split ensures that the initial bundle is small and additional code is loaded only when necessary.</p>
<h3 id="heading-real-world-use-cases-and-benefits">Real-World Use Cases and Benefits</h3>
<h4 id="heading-use-cases">Use Cases:</h4>
<ol>
<li><p><strong>Large Applications</strong>: In applications with numerous routes and components, lazy loading and code splitting can significantly improve performance by loading only the required components for the current route.</p>
</li>
<li><p><strong>Media-Rich Content</strong>: For applications with heavy media content (images, videos), lazy loading ensures that these resources are loaded only when needed, reducing the initial load time.</p>
</li>
<li><p><strong>Third-Party Libraries</strong>: Large third-party libraries can be loaded on demand, reducing the initial bundle size.</p>
</li>
</ol>
<h4 id="heading-benefits">Benefits:</h4>
<ul>
<li><p><strong>Faster Initial Load</strong>: Only essential code is loaded initially, leading to faster page loads.</p>
</li>
<li><p><strong>Improved Performance</strong>: Loading code on demand reduces memory usage and enhances application responsiveness.</p>
</li>
<li><p><strong>Better User Experience</strong>: Users can access and interact with the core functionalities of the application quickly while additional features load in the background.</p>
</li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Lazy loading and code splitting are powerful techniques for optimizing web applications. By deferring the loading of non-critical resources and splitting code into smaller bundles, developers can create more efficient, performant, and user-friendly applications. These strategies not only improve performance but also enhance the overall user experience, making them essential tools in the modern web development toolkit.</p>
<h2 id="heading-faqs-about-lazy-loading-and-code-splitting">FAQs about Lazy Loading and Code Splitting</h2>
<h3 id="heading-what-is-lazy-loading">What is Lazy Loading?</h3>
<p>Lazy loading is a design pattern that defers the loading of non-critical resources until they are needed. This helps in reducing the initial load time of a web application by loading only the essential components first.</p>
<h3 id="heading-how-does-lazy-loading-improve-performance">How does Lazy Loading improve performance?</h3>
<p>By loading only the necessary resources initially, lazy loading reduces the initial load time, conserves bandwidth, and allows users to interact with the essential parts of the application more quickly.</p>
<h3 id="heading-how-can-i-implement-lazy-loading-in-react">How can I implement Lazy Loading in React?</h3>
<p>In React, lazy loading can be implemented using <code>React.lazy</code> and <code>Suspense</code>. Here's a simple example:</p>
<pre><code class="lang-plaintext">codeimport React, { Suspense } from 'react';

const LazyComponent = React.lazy(() =&gt; import('./LazyComponent'));

function App() {
  return (
    &lt;div&gt;
      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;
        &lt;LazyComponent /&gt;
      &lt;/Suspense&gt;
    &lt;/div&gt;
  );
}

export default App;
</code></pre>
<h3 id="heading-what-is-code-splitting">What is Code Splitting?</h3>
<p>Code splitting is a technique to divide your code into smaller bundles that can be loaded on demand or in parallel. This approach optimizes the load time and performance of web applications by loading only the necessary code for the current page.</p>
<h3 id="heading-how-does-code-splitting-enhance-web-application-performance">How does Code Splitting enhance web application performance?</h3>
<p>By splitting the code into smaller bundles, code splitting ensures that the browser only loads the code required for the current view, reducing the initial load time and improving overall performance.</p>
<h3 id="heading-how-can-i-implement-code-splitting-in-react">How can I implement Code Splitting in React?</h3>
<p>In React, code splitting can be achieved using dynamic <code>import()</code> statements. Here’s an example:</p>
<pre><code class="lang-plaintext">import React, { Component } from 'react';

class App extends Component {
  state = {
    Component: null
  };

  loadComponent = () =&gt; {
    import('./MyComponent').then(Component =&gt; {
      this.setState({ Component: Component.default });
    });
  };

  render() {
    const { Component } = this.state;
    return (
      &lt;div&gt;
        &lt;button onClick={this.loadComponent}&gt;Load Component&lt;/button&gt;
        {Component &amp;&amp; &lt;Component /&gt;}
      &lt;/div&gt;
    );
  }
}

export default App;
</code></pre>
<h3 id="heading-can-lazy-loading-and-code-splitting-be-used-together">Can Lazy Loading and Code Splitting be used together?</h3>
<p>Yes, these techniques are often used together to optimize the performance and user experience of web applications. Lazy loading components that are code-split ensures that the initial bundle is small and additional code is loaded only when necessary.</p>
<h3 id="heading-what-are-the-benefits-of-combining-lazy-loading-and-code-splitting">What are the benefits of combining Lazy Loading and Code Splitting?</h3>
<ul>
<li><p><strong>Faster Initial Load</strong>: Only essential code is loaded initially, leading to faster page loads.</p>
</li>
<li><p><strong>Improved Performance</strong>: Loading code on demand reduces memory usage and enhances application responsiveness.</p>
</li>
<li><p><strong>Better User Experience</strong>: Users can access and interact with the core functionalities of the application quickly while additional features load in the background.</p>
</li>
</ul>
<h3 id="heading-what-are-some-real-world-use-cases-for-lazy-loading-and-code-splitting">What are some real-world use cases for Lazy Loading and Code Splitting?</h3>
<ul>
<li><p><strong>Large Applications</strong>: Improves performance by loading only the required components for the current route.</p>
</li>
<li><p><strong>Media-Rich Content</strong>: Loads heavy media content (images, videos) only when needed, reducing the initial load time.</p>
</li>
<li><p><strong>Third-Party Libraries</strong>: Loads large third-party libraries on demand, reducing the initial bundle size.</p>
</li>
</ul>
<h3 id="heading-how-do-these-techniques-affect-seo">How do these techniques affect SEO?</h3>
<p>For client-side rendered applications, lazy loading can sometimes delay the loading of content, which may affect SEO if not handled properly. Using server-side rendering (SSR) or static site generation (SSG) with frameworks like Next.js can mitigate these issues by ensuring that content is available to search engines.</p>
<h3 id="heading-what-tools-and-libraries-support-lazy-loading-and-code-splitting">What tools and libraries support Lazy Loading and Code Splitting?</h3>
<ul>
<li><p><strong>React</strong>: Supports lazy loading and code splitting natively with <code>React.lazy</code>, <code>Suspense</code>, and dynamic <code>import()</code> statements.</p>
</li>
<li><p><strong>Webpack</strong>: A popular module bundler that supports code splitting and lazy loading.</p>
</li>
<li><p><strong>Next.js</strong>: A React framework that provides built-in support for server-side rendering, static site generation, and code splitting.</p>
</li>
</ul>
<p>By understanding and implementing lazy loading and code splitting, developers can create web applications that are not only efficient and performant but also deliver a superior user experience.</p>
]]></content:encoded></item><item><title><![CDATA[How Prototype Chaining Works in JavaScript: An Easy Explanation]]></title><description><![CDATA[Prototype chaining is a fundamental concept in JavaScript that enables inheritance and the sharing of properties and methods between objects. It's essential for creating flexible and reusable code. In this blog, we'll dive deep into prototype chainin...]]></description><link>https://blog.nadim.in/how-prototype-chaining-works-in-javascript-an-easy-explanation</link><guid isPermaLink="true">https://blog.nadim.in/how-prototype-chaining-works-in-javascript-an-easy-explanation</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ Object Prototypes]]></category><category><![CDATA[prototype chaining]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[coding]]></category><category><![CDATA[techblog]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[#javaScriptPrototypes]]></category><dc:creator><![CDATA[Nadim Anwar]]></dc:creator><pubDate>Thu, 11 Jul 2024 06:33:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720679218699/28ce609f-f01d-46aa-8b32-1a5085b8566b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Prototype chaining is a fundamental concept in JavaScript that enables inheritance and the sharing of properties and methods between objects. It's essential for creating flexible and reusable code. In this blog, we'll dive deep into prototype chaining, its mechanics, common pitfalls, advanced topics, and address some frequently asked questions.</p>
<h2 id="heading-what-is-prototype-chaining">What is Prototype Chaining?</h2>
<p>Prototype chaining is a method used to build new types of objects based on existing ones. It allows objects to inherit properties and methods from other objects. This concept is similar to inheritance in class-based languages but implemented differently in JavaScript.</p>
<p>When you create an object using a constructor function or a class, the newly created object (instance) inherits properties from a prototype object. This prototype object can have properties and methods that are shared among all instances created by the constructor function.</p>
<h2 id="heading-how-does-prototype-chaining-work">How Does Prototype Chaining Work?</h2>
<h3 id="heading-1-prototype-of-constructor-function">1. Prototype of Constructor Function</h3>
<p>Every function in JavaScript has a <code>prototype</code> property, which is an object. When a function is used as a constructor with the <code>new</code> keyword, the <code>prototype</code> property of the function becomes the prototype of the newly created object.</p>
<h3 id="heading-2-prototype-of-object-instance">2. Prototype of Object Instance</h3>
<p>An object instance created by a constructor function has an internal property (<code>[[Prototype]]</code>, accessible via <code>__proto__</code>) that points to the prototype object of the constructor function.</p>
<h3 id="heading-3-the-chain">3. The Chain</h3>
<p>When a property or method is accessed on an object, JavaScript first looks for it on the object itself. If it’s not found, it follows the <code>__proto__</code> link to the prototype object and continues this process up the chain until it either finds the property/method or reaches the end of the chain (usually <code>Object.prototype</code>, which is <code>null</code>).</p>
<h2 id="heading-example-of-prototype-chaining">Example of Prototype Chaining</h2>
<p>Let's look at a simple example to understand how prototype chaining works:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
    <span class="hljs-built_in">this</span>.name = name;
}

Person.prototype.greet = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Hello, my name is <span class="hljs-subst">${<span class="hljs-built_in">this</span>.name}</span>`</span>);
};

<span class="hljs-keyword">const</span> alice = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">'Alice'</span>);
<span class="hljs-keyword">const</span> bob = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">'Bob'</span>);

alice.greet(); <span class="hljs-comment">// Hello, my name is Alice</span>
bob.greet();   <span class="hljs-comment">// Hello, my name is Bob</span>
</code></pre>
<p>In this example:</p>
<ul>
<li><code>Person</code> is a constructor function.</li>
<li><code>Person.prototype</code> has a method <code>greet</code>.</li>
<li>Instances <code>alice</code> and <code>bob</code> have their internal <code>[[Prototype]]</code> (or <code>__proto__</code>) pointing to <code>Person.prototype</code>.</li>
</ul>
<p>When <code>alice.greet()</code> is called, JavaScript looks for <code>greet</code> on <code>alice</code>. It’s not found, so it follows the prototype chain to <code>Person.prototype</code> where it finds and calls <code>greet</code>.</p>
<h2 id="heading-real-world-examples">Real-World Examples</h2>
<h3 id="heading-1-extending-built-in-objects">1. Extending Built-In Objects</h3>
<p>Prototype chaining allows you to extend built-in objects like arrays and strings:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Array</span>.prototype.last = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>[<span class="hljs-built_in">this</span>.length - <span class="hljs-number">1</span>];
};

<span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-built_in">console</span>.log(numbers.last()); <span class="hljs-comment">// 3</span>
</code></pre>
<h3 id="heading-2-creating-hierarchical-structures">2. Creating Hierarchical Structures</h3>
<p>You can create complex hierarchical structures by chaining prototypes:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Animal</span>(<span class="hljs-params">name</span>) </span>{
    <span class="hljs-built_in">this</span>.name = name;
}

Animal.prototype.speak = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-built_in">this</span>.name}</span> makes a sound`</span>);
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Dog</span>(<span class="hljs-params">name, breed</span>) </span>{
    Animal.call(<span class="hljs-built_in">this</span>, name);
    <span class="hljs-built_in">this</span>.breed = breed;
}

Dog.prototype = <span class="hljs-built_in">Object</span>.create(Animal.prototype);
Dog.prototype.constructor = Dog;

Dog.prototype.bark = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-built_in">this</span>.name}</span> barks`</span>);
};

<span class="hljs-keyword">const</span> rex = <span class="hljs-keyword">new</span> Dog(<span class="hljs-string">'Rex'</span>, <span class="hljs-string">'German Shepherd'</span>);
rex.speak(); <span class="hljs-comment">// Rex makes a sound</span>
rex.bark();  <span class="hljs-comment">// Rex barks</span>
</code></pre>
<h2 id="heading-common-pitfalls">Common Pitfalls</h2>
<h3 id="heading-1-overwriting-prototypes">1. Overwriting Prototypes</h3>
<p>Be cautious when modifying prototypes, as it can lead to unexpected behavior if not handled correctly:</p>
<pre><code class="lang-javascript">Dog.prototype = Animal.prototype; <span class="hljs-comment">// Incorrect way</span>
</code></pre>
<p>Instead, use <code>Object.create</code>:</p>
<pre><code class="lang-javascript">Dog.prototype = <span class="hljs-built_in">Object</span>.create(Animal.prototype);
</code></pre>
<h3 id="heading-2-performance-issues">2. Performance Issues</h3>
<p>Excessive use of prototype chaining can lead to performance issues, especially when the chain is long. Always balance between flexibility and performance.</p>
<h2 id="heading-advanced-topics">Advanced Topics</h2>
<h3 id="heading-1-es6-classes">1. ES6 Classes</h3>
<p>ES6 introduced class syntax, which simplifies prototype chaining:</p>
<pre><code class="lang-javascript"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
    <span class="hljs-keyword">constructor</span>(name) {
        <span class="hljs-built_in">this</span>.name = name;
    }

    greet() {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Hello, my name is <span class="hljs-subst">${<span class="hljs-built_in">this</span>.name}</span>`</span>);
    }
}

<span class="hljs-keyword">const</span> alice = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">'Alice'</span>);
alice.greet(); <span class="hljs-comment">// Hello, my name is Alice</span>
</code></pre>
<h3 id="heading-2-reflect-api">2. Reflect API</h3>
<p>The <code>Reflect</code> API provides methods for manipulating objects and their prototypes:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Reflect</span>.setPrototypeOf(alice, newPrototype);
</code></pre>
<h2 id="heading-faqs-on-prototype-chaining">FAQs on Prototype Chaining</h2>
<h3 id="heading-1-what-is-the-difference-between-proto-and-prototype">1. What is the difference between <code>__proto__</code> and <code>prototype</code>?</h3>
<ul>
<li><code>__proto__</code> is an internal property of an object, pointing to its prototype. It is used to access the prototype of the instance.</li>
<li><code>prototype</code> is a property of a constructor function that is used to define the prototype object for instances created with that constructor.</li>
</ul>
<h3 id="heading-2-can-you-modify-the-prototype-of-an-existing-object">2. Can you modify the prototype of an existing object?</h3>
<p>Yes, you can modify the prototype of an existing object. This allows you to add or change properties and methods that will be shared among all instances.</p>
<pre><code class="lang-javascript">Person.prototype.sayGoodbye = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Goodbye from <span class="hljs-subst">${<span class="hljs-built_in">this</span>.name}</span>`</span>);
};

alice.sayGoodbye(); <span class="hljs-comment">// Goodbye from Alice</span>
bob.sayGoodbye();   <span class="hljs-comment">// Goodbye from Bob</span>
</code></pre>
<h3 id="heading-3-how-does-prototype-chaining-affect-performance">3. How does prototype chaining affect performance?</h3>
<p>Prototype chaining can affect performance when accessing properties or methods that are deep in the chain. Each step in the chain requires a lookup, which can be time-consuming if the chain is long. However, for most use cases, this performance impact is negligible.</p>
<h3 id="heading-4-what-happens-if-you-delete-a-property-on-an-object-that-exists-on-its-prototype">4. What happens if you delete a property on an object that exists on its prototype?</h3>
<p>Deleting a property from an object only removes the property from the object itself. If the property exists on the prototype, it will still be accessible via the prototype chain.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">delete</span> alice.name;
<span class="hljs-built_in">console</span>.log(alice.name); <span class="hljs-comment">// undefined</span>
<span class="hljs-built_in">console</span>.log(bob.name);   <span class="hljs-comment">// Bob</span>
</code></pre>
<h3 id="heading-5-how-can-you-create-an-object-without-a-prototype">5. How can you create an object without a prototype?</h3>
<p>You can create an object without a prototype using <code>Object.create(null)</code>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = <span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Object</span>.getPrototypeOf(obj)); <span class="hljs-comment">// null</span>
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Prototype chaining is a powerful feature in JavaScript that enables inheritance and code reuse. By understanding how prototype chaining works, you can write more efficient and maintainable code. Whether you're adding new methods to existing prototypes or creating complex inheritance structures, prototype chaining is an essential tool in your JavaScript toolkit.</p>
<p>Feel free to experiment with the examples provided and explore how prototype chaining can enhance your JavaScript applications. If you have any further questions or comments, feel free to leave them below!</p>
]]></content:encoded></item></channel></rss>