<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sejal on Medium]]></title>
        <description><![CDATA[Stories by Sejal on Medium]]></description>
        <link>https://medium.com/@SejalPande1994?source=rss-b995bb39fdbb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1dsZbGtXUz9HX8ES-iZUqw.jpeg</url>
            <title>Stories by Sejal on Medium</title>
            <link>https://medium.com/@SejalPande1994?source=rss-b995bb39fdbb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:02:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@SejalPande1994/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering Routing in Next.js: From Basics to Advanced Patterns]]></title>
            <link>https://medium.com/@SejalPande1994/mastering-routing-in-next-js-from-basics-to-advanced-patterns-c6220a5a436c?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6220a5a436c</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[seo]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Tue, 31 Mar 2026 10:08:29 GMT</pubDate>
            <atom:updated>2026-03-31T10:09:55.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*M8sGyTGfLNyPG-7zfjKXjA.avif" /><figcaption>Javascript Framework</figcaption></figure><p>Next.js has revolutionized the way we build full-stack React applications. By abstracting away the complexities of configuration and providing a robust, file-based routing system, it allows developers to focus on what matters most: <strong>building features.</strong></p><p>In this guide, we’ll break down how routing works in the Next.js App Router, moving from basic folder structures to complex dynamic segments.</p><h3>What is Next.js?</h3><p>Next.js is a powerful React framework designed for high-performance, full-stack web applications. While React handles the UI, Next.js provides the “batteries” included:</p><ul><li><strong>Built-in Routing &amp; API Routes</strong></li><li><strong>Flexible Rendering (SSR, SSG, ISR)</strong></li><li><strong>Optimized Performance</strong> (Images, Fonts, and Scripts)</li><li><strong>Zero Config</strong> build systems for development and production.</li></ul><p><strong>Getting Started</strong></p><p>To kick off a new project, ensure you have <strong>Node.js</strong> installed and run:</p><p>Bash</p><pre>npx create-next-app@latest my-awesome-project<br>npm run dev</pre><h3>The Paradigm Shift: React Server Components (RSC)</h3><p>Before diving into routes, it’s crucial to understand the two types of components in Next.js:</p><ul><li><strong>Server Components:</strong> The default. They fetch data directly on the server and keep your bundle size small. However, they cannot use hooks (like useState) or handle user interactions.</li><li><strong>Client Components:</strong> These are your traditional React components. Defined with the &#39;use client&#39; directive at the top, they handle state, effects, and event listeners.</li></ul><h3>The Core of Next.js Routing</h3><p>Next.js uses a <strong>file-based routing system</strong>. This means the URL path is a direct reflection of your folder structure inside the src/app directory.</p><h3>The Rules of the Road</h3><ul><li><strong>Location:</strong> All routes must live inside the app folder.</li><li><strong>Naming:</strong> A route is only publicly accessible if it contains a page.js or page.tsx file.</li><li><strong>Hierarchy:</strong> Each folder represents a <strong>URL segment</strong>.</li></ul><h3>1. Basic &amp; Nested Routes</h3><p>If you want a route like /about, you create a folder named about with a page.tsx inside.</p><p>For <strong>Nested Routes</strong>, like /product/shoes, you simply nest the folders:</p><ul><li>app/product/page.tsx → matches /product</li><li>app/product/shoes/page.tsx → matches /product/shoes</li></ul><h3>2. Dynamic Routes</h3><p>Creating folders for 1,000 different products isn’t feasible. <strong>Dynamic Routes</strong> solve this by using square brackets.</p><ul><li><strong>Structure:</strong> app/product/[productId]/page.tsx</li><li><strong>URL:</strong> This will match /product/1, /product/apple, or /product/any-id.</li></ul><h3>3. Nested Dynamic Routes</h3><p>You can go deeper. If you need a review page for a specific product:</p><ul><li><strong>Structure:</strong> app/product/[productId]/reviews/[reviewId]/page.tsx</li><li><strong>URL Example:</strong> /product/101/reviews/5</li></ul><h3>Advanced Catch-all Segments</h3><p>Sometimes you don’t know how many segments the URL will have (like a documentation site or a file explorer).</p><ul><li><strong>Catch-all Segments </strong><strong>[...slug]</strong></li></ul><p><strong>Usage:</strong> Captures all subsequent URL segments.</p><p><strong>Example:</strong> /shop/[...slug] matches /shop/clothes and /shop/clothes/tops/shirts.</p><ul><li><strong>Optional Catch-all Segments </strong><strong>[[...slug]]</strong></li></ul><p><strong>Usage:</strong> Captures all segments, but also matches the root route without any segments.</p><p><strong>Example:</strong> /shop/[[...slug]] matches /shop (the base folder) as well as /shop/clothes.</p><blockquote><strong><em>Note:</em></strong><em> Optional catch-all segments are great for pages where the content changes dynamically based on the URL, but the base page still needs to exist.</em></blockquote><h3>Handling the “Not Found” State</h3><p>Next.js provides a built-in 404 page, but you’ll likely want something custom to match your brand.</p><h3>Global vs. Local 404s</h3><ul><li><strong>Custom Global 404:</strong> Create a not-found.tsx file in the root of your app folder.</li><li><strong>Route-Specific 404:</strong> You can place a not-found.tsx inside a specific folder (e.g., /product) to show a more tailored error message.</li></ul><h3>The notFound() Function</h3><p>Sometimes you need to trigger a 404 manually (e.g., if a product ID doesn’t exist in your database). Next.js provides a notFound() function for this.</p><p><strong>Pro-tip:</strong> While the not-found component itself doesn&#39;t accept props, you can use it in combination with Client Components and hooks to create a seamless user experience. Don&#39;t forget to add &#39;use client&#39; if you are using routing-specific hooks in your error UI!</p><h3>Conclusion</h3><p>Next.js routing is intuitive yet incredibly deep. By mastering the folder structure and understanding when to use Dynamic or Catch-all segments, you can build complex, scalable web applications with ease.</p><p><strong>Happy Coding!</strong> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6220a5a436c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything You Need to Know About JavaScript Promises]]></title>
            <link>https://medium.com/@SejalPande1994/everything-you-need-to-know-about-javascript-promises-71c8655bfae8?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/71c8655bfae8</guid>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 21:01:19 GMT</pubDate>
            <atom:updated>2025-12-29T21:01:19.176Z</atom:updated>
            <content:encoded><![CDATA[<ol><li><strong>Promises Are Immutable</strong></li></ol><p>Once a Promise is <strong>fulfilled or rejected</strong>, its state and value <strong>can never change</strong>.</p><blockquote>const p = new Promise(resolve =&gt; {<br> resolve(1);<br> resolve(2); // ignored<br>});</blockquote><blockquote>const p = Promise.resolve(10);</blockquote><blockquote>p.then(v =&gt; console.log(v));<br>p.then(v =&gt; console.log(v * 2));</blockquote><blockquote>Output: <br>10<br>20</blockquote><p><strong>2. Multiple </strong><strong>.then() Handlers Are Allowed</strong><br>You can attach <strong>multiple </strong><strong>.then() handlers</strong> to the same Promise, and they all run independently.</p><blockquote>promise.then(a =&gt; console.log(a));<br>promise.then(b =&gt; console.log(b));</blockquote><p>This does <strong>not</strong> create multiple executions — just multiple listeners.</p><p><strong>3. Returning a Promise Pauses the Chain</strong><br>If you return a Promise from .then(), the next .then() <strong>waits until it resolves</strong>.</p><blockquote>fetchData()<br> .then(() =&gt; fetchMoreData())<br> .then(result =&gt; console.log(result));</blockquote><p>The chain pauses until fetchMoreData() settles.</p><p><strong>4. Not Returning Anything Resolves with </strong><strong>undefined</strong></p><p>If a .then() handler doesn’t return a value, the next .then() receives undefined.</p><blockquote>promise<br> .then(() =&gt; {<br> doSomething();<br> })<br> .then(value =&gt; {<br> console.log(value); // undefined<br> });</blockquote><p>⚠️ This is a <strong>very common real-world bug</strong> when chaining Promises.</p><p><strong>5. Promise Callbacks vs </strong><strong>setTimeout</strong></p><ul><li>.then() callbacks go to the <strong>microtask queue</strong></li><li>setTimeout() callbacks go to the <strong>macrotask queue</strong></li></ul><blockquote>Promise.resolve().then(() =&gt; console.log(“promise”));<br>setTimeout(() =&gt; console.log(“timeout”), 0);</blockquote><blockquote>Output: <br>promise<br>timeout</blockquote><p>➡️ Microtasks always run <strong>before</strong> macrotasks once the call stack is empty.</p><p><strong>6. </strong><strong>await Uses the Microtask Queue</strong></p><p>await pauses execution and schedules the remaining code as a <strong>microtask</strong>.</p><blockquote>await fetchData();<br>console.log(“done”);</blockquote><p>This behavior is <strong>functionally equivalent to </strong><strong>.then()</strong>, just with cleaner syntax.</p><p><strong>7. Promise Executor Runs Synchronously</strong></p><p>The function passed to new Promise() executes <strong>immediately</strong>.</p><blockquote>new Promise(() =&gt; {<br> console.log(“executor”);<br>});<br>console.log(“after”);</blockquote><blockquote>Output<br>executor<br>after</blockquote><p>However, .then() handlers always run <strong>asynchronously</strong>.</p><p><strong>Conclusion:<br></strong>Understanding <strong>immutability, chaining behavior, and the event loop</strong> is what separates using Promises from mastering async JavaScript.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71c8655bfae8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Short Polling in JavaScript: A Real-Time Approach to Data Updates]]></title>
            <link>https://medium.com/@SejalPande1994/exploring-short-polling-in-javascript-a-real-time-approach-to-data-updates-643d5c016d99?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/643d5c016d99</guid>
            <category><![CDATA[real-time-communication]]></category>
            <category><![CDATA[polling]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[web-communications]]></category>
            <category><![CDATA[short-polling]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 14:58:28 GMT</pubDate>
            <atom:updated>2024-03-26T14:58:28.822Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Introduction</strong>:</blockquote><p>In the realm of real-time web applications, developers often rely on various techniques to provide up-to-date information to users without constant page refreshes. One such technique is short polling, a lightweight method for fetching updates from a server at regular intervals. In this article, we’ll delve into short polling in JavaScript, understanding its concept, implementation, and best practices for real-time data updates.</p><blockquote><strong>What is Short Polling?</strong></blockquote><p>Short polling involves periodically sending requests to a server to fetch updated data, regardless of whether there are any changes. Unlike long polling or Web Sockets, where the server maintains an open connection, short polling involves making discrete HTTP requests at fixed intervals.</p><p>Implementation: To implement short polling in JavaScript, we can leverage the XMLHttpRequest or Fetch API to make periodic requests to a server endpoint. Here’s a basic example using the Fetch API:</p><pre>//JS function to fetch the data from the server<br>const fetchData = () =&gt; {<br>    try{<br>        fetch(&#39;/api/getData&#39;).then(res =&gt; {<br>            console.log(&#39;API Response&#39;, res.json())<br>        }).then(data =&gt; {<br>            console.log(&#39;Fetched Data&#39;, data)<br>        });<br>    } catch(e) {<br>        console.log(e)<br>    }<br>}<br><br><br>//JS fnction to handle short polling of the requests<br>const startShortPolling = (interval) =&gt; {<br>    let initialInterval;<br>    interval = setInterval(fetchData, interval);<br><br><br>    //Note - Remember to clear the interval on any user event, action or on completion of the task, <br>    //as it may lead to load on server because of consequetive requests and lead to global exception<br>    clearInterval(initialInterval);<br>}<br><br><br>startShortPolling(5000);</pre><blockquote><strong>Best Practices:</strong></blockquote><p>While short polling is straightforward to implement, there are some best practices to consider for optimal performance and user experience:</p><ol><li><strong><em>Frequency Control</em></strong><em>: </em>Determine an appropriate polling interval based on the nature of your application and the rate of data changes. Avoid excessive polling, which can strain server resources and consume unnecessary bandwidth.</li><li><strong><em>Throttling</em></strong><em>:</em> Implement throttling mechanisms to prevent rapid consecutive requests, especially in scenarios where updates are infrequent or bursts of traffic occur.</li><li><strong><em>Error Handling</em></strong><em>:</em> Handle network errors and server failures gracefully to ensure robustness. Implement retry mechanisms with exponential backoff to handle transient errors and prevent overwhelming the server with repeated requests.</li><li><strong><em>Server Optimization</em></strong><em>:</em> Optimize server-side logic to minimize response times and efficiently handle polling requests. Consider caching strategies to reduce the computational overhead of generating responses for frequent requests.</li></ol><blockquote><strong>Use Cases:</strong></blockquote><p>Short polling can be beneficial in various use cases where real-time or near-real-time updates are required without the complexity of maintaining persistent connections. Some common use cases include:</p><ol><li><strong><em>Chat Applications:</em></strong> Short polling can be used to fetch new messages from the server at regular intervals, allowing users to see the latest messages without refreshing the page. While not as efficient as Web Sockets for real-time chat, short polling provides a simple way to implement basic chat functionality.</li><li><strong><em>Notification Systems</em></strong>: Short polling is suitable for notification systems where users receive alerts or updates about events, messages, or changes in the application. By polling the server for new notifications, users can be promptly informed of relevant information.</li><li><strong><em>E-commerce Product Availability</em></strong>: E-commerce websites can use short polling to check product availability or stock levels in real-time. By periodically querying the inventory database, users can be notified of changes in product availability without delays.</li></ol><blockquote><strong>Conclusion</strong>:</blockquote><p>Short polling is a simple yet effective technique for achieving real-time updates in web applications. By periodically fetching data from a server at regular intervals, developers can provide users with timely information without resorting to heavyweight solutions like long polling or Web Sockets. However, it’s essential to strike a balance between update frequency, server load, and user experience to ensure optimal performance and reliability. With careful implementation and adherence to best practices, short polling can be a valuable tool in the developer’s arsenal for building responsive and dynamic web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=643d5c016d99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying REST APIs: Understanding HTTP Status Codes]]></title>
            <link>https://medium.com/@SejalPande1994/demystifying-rest-apis-understanding-http-status-codes-82053a4c4b21?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/82053a4c4b21</guid>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[http-status-code]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[list-of-http-status-codes]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 21:03:59 GMT</pubDate>
            <atom:updated>2024-03-21T21:11:35.590Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction:</strong></p><p>REST APIs (<strong>Representational State Transfer Application Programming Interfaces</strong>) have become the backbone of modern web development, allowing seamless communication between different software systems over the internet. At the heart of this communication protocol lie HTTP status codes, which serve as a crucial means of conveying the outcome of an HTTP request. In this article, we will delve into the significance of HTTP status codes in REST APIs and understand their various categories and common codes.</p><p><strong>Understanding HTTP Status Codes:</strong></p><p>HTTP status codes are three-digit integers returned by a server in response to a client’s request made to the server via HTTP (<strong>Hypertext Transfer Protocol</strong>). These status codes indicate whether a specific HTTP request has been successfully completed, encountered an error, or requires further action from the client.</p><p><strong>Categories of HTTP Status Codes:</strong></p><p>HTTP status codes are categorized into five classes, each representing a specific type of response:</p><ol><li><strong><em>Informational (1xx):</em></strong> These status codes indicate that the server has received the request and is continuing the process. One common example is 100 Continue, which informs the client to continue with its request.</li><li><strong><em>Success (2xx): </em></strong>These status codes indicate that the request was successfully received, understood, and accepted. The most familiar among these is 200 OK, which signifies a successful request.</li><li><strong><em>Redirection (3xx):</em></strong> These status codes indicate that further action needs to be taken by the client to complete the request. For instance, 301 Moved Permanently instructs the client to use a different URL to access the resource.</li><li><strong><em>Client Error (4xx):</em></strong> These status codes indicate that the client has made an error in the request, such as providing incorrect parameters or attempting to access unauthorized resources. A well-known example is 404 Not Found, which indicates that the requested resource could not be found on the server.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iF-Uqv91cn-Ji_Gm3XOZmA.jpeg" /><figcaption>HTTP Status Code</figcaption></figure><p><strong>Common HTTP Status Codes in REST APIs:</strong></p><ol><li><strong><em>100 Continue: </em></strong>The server has received the initial part of the request and expects the client to continue with the remainder of the request.</li><li><strong><em>101 Switching Protocols: </em></strong>The server is indicating a change in the protocol being used, for example, switching from HTTP to WebSocket.</li><li><strong>200 OK: </strong>The request has succeeded. The server typically returns this status code for successful GET, POST, PUT, or DELETE requests.</li><li><strong><em>201 Created:</em></strong> The request has been fulfilled, and a new resource has been created as a result. This is commonly used for POST requests when a new resource is created.</li><li><strong><em>202 Accepted:</em></strong> The request has been accepted for processing, but the processing has not been completed. This status code is often used for asynchronous processing. For Example File upload/download.</li><li><strong><em>204 No Content:</em></strong> The server successfully processed the request but is not returning any content in the response body. For Example, a delete request.</li><li><strong><em>206 Partial Content:</em></strong> The server is delivering only part of the resource due to a range request made by the client. For example, downloading a file in chunks.</li><li><strong><em>301 Moved Permanently:</em></strong> The requested resource has been permanently moved to a new location, and the client should use the new URL for all future requests.</li><li><strong><em>302 Found (or Moved Temporarily): </em></strong>The requested resource has been temporarily moved to a different location. The client should continue to use the original URL for future requests.</li><li><strong><em>307 Temporary Redirect:</em></strong> Similar to 302, but it indicates that the client should continue to use the original URL for future requests.</li><li><strong><em>308 Permanent Redirect: </em></strong>Similar to 301, but it indicates that the client should use the new URL for all future requests.</li><li><strong>400 Bad Request: </strong>The server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing.</li><li><strong><em>401 Unauthorized: </em></strong>The request requires user authentication. The client needs to authenticate itself to get the requested response.</li><li><strong><em>403 Forbidden:</em></strong> The server understood the request, but it refuses to authorize it. This status code indicates that the client does not have permission to access the resource.</li><li><strong><em>404 Not Found:</em></strong> The server cannot find the requested resource. This is one of the most common HTTP status codes and indicates that the requested resource does not exist.</li><li><strong><em>405 Method Not Allowed: </em></strong>The request method (such as GET, POST, PUT) is not supported for the requested resource.</li><li><strong><em>429 Too Many Requests:</em></strong> The user has sent too many requests in a given amount of time (“rate limiting”). This status code indicates that the client needs to slow down its requests.</li><li><strong><em>500 Internal Server Error:</em></strong> A generic error message indicating that something unexpected happened on the server, preventing it from fulfilling the request.</li><li><strong><em>502 Bad Gateway:</em></strong> The server received an invalid response from an upstream server while acting as a gateway or proxy.</li><li><strong><em>503 Service Unavailable:</em></strong> The server is currently unable to handle the request due to temporary overloading or maintenance of the server. This is often used for planned maintenance.</li><li><strong><em>504 Gateway Timeout:</em></strong> The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.</li><li><strong><em>507 Insufficient Storage: </em></strong>The server is unable to store the representation needed to complete the request.</li></ol><p>These status codes are essential for understanding the outcome of HTTP requests and diagnosing issues in web applications.</p><p><strong>Conclusion:</strong></p><p>HTTP status codes play a vital role in REST APIs, providing valuable information about the outcome of HTTP requests. Understanding these status codes is essential for building robust and error-tolerant APIs. By familiarizing yourself with the common status codes and their meanings, you can effectively diagnose and resolve issues in your RESTful applications, ensuring a smooth user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82053a4c4b21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Execution Context in JavaScript: A Comprehensive Guide]]></title>
            <link>https://medium.com/@SejalPande1994/understanding-execution-context-in-javascript-a-comprehensive-guide-dfd9231ed197?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfd9231ed197</guid>
            <category><![CDATA[call-stack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[event-loop]]></category>
            <category><![CDATA[execution-context]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 11:54:44 GMT</pubDate>
            <atom:updated>2024-03-01T11:54:44.125Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction:</strong></p><blockquote>In the world of JavaScript, understanding how code is executed is fundamental to writing efficient and bug-free applications. One of the key concepts in this realm is the “<strong>execution context</strong>.” In this article, we will delve deep into what execution context is, how it works, and why it’s essential for every JavaScript developer to grasp.</blockquote><blockquote>What is Execution Context? Execution context can be thought of as the environment in which JavaScript code is evaluated and executed. It consists of two main components: the Variable Object (VO) and the Scope Chain.</blockquote><ol><li><strong>The Variable Object (VO) / Memory Allocation</strong>:</li></ol><ul><li>The Variable Object is a container that stores variables, functions, and parameters defined within the context.</li><li>For global context, the Variable Object represents the global scope and contains all global variables and functions.</li><li>For function context, the Variable Object represents the local scope of that function and includes parameters, variables declared with var, function declarations, and this reference.</li></ul><p>2. <strong>The Scope Chain:</strong></p><ul><li>The Scope Chain is a list of Variable Objects that represent the scope hierarchy.</li><li>When JavaScript attempts to resolve an identifier, it traverses the Scope Chain from inner to outer scopes until it finds a match.</li><li>This mechanism ensures lexical scoping and determines the accessibility of variables and functions within nested scopes.</li></ul><p><strong>Types of Execution Context:</strong></p><p>JavaScript has three types of execution contexts:</p><ol><li><strong><em>Global Execution Context:</em></strong></li></ol><ul><li>The default execution context when a script is executed.</li><li>It represents the global scope and persists throughout the lifetime of the script.</li><li>The Variable Object for the global context contains global variables, functions, and the this reference.</li></ul><p><strong><em>2. Function Execution Context:</em></strong></p><ul><li>Created whenever a function is invoked.</li><li>Each function call creates its own execution context with its unique Variable Object and Scope Chain.</li><li>These contexts are pushed and popped from the Call Stack during function invocation and return.</li></ul><p><strong><em>3. Eval Execution Context (Optional):</em></strong></p><ul><li>Created when code is executed within the eval() function.</li><li>It creates a new scope but inherits the Variable Object and Scope Chain from its outer context.</li></ul><p><strong>Execution Context Lifecycle:</strong></p><p>Understanding the lifecycle of an execution context is crucial for debugging and optimizing JavaScript code:</p><p><strong><em>Creation Phase:</em></strong></p><ul><li>Creation of the Variable Object (VO) and the Scope Chain.</li><li>Determination of the value of this.</li><li>Setup of the outer environment reference.</li></ul><p><strong><em>Execution Phase:</em></strong></p><ul><li>Execution of code line by line.</li><li>Assignment of values to variables.</li><li>Invocation of functions.</li></ul><p><strong><em>Cleanup Phase:</em></strong></p><ul><li>Release of memory allocated to the execution context.</li><li>Removal of the context from the Call Stack.</li></ul><p><strong>Debugging Execution Contexts:</strong></p><p>Debugging JavaScript often involves analyzing execution contexts to understand variable scopes and identify runtime errors. Developers can leverage browser developer tools and debugging techniques such as:</p><ul><li>Console logging to inspect variable values.</li><li>Setting breakpoints to pause execution and examine context states.</li><li>Using tools like Chrome DevTools to visualize the Call Stack and context hierarchy.</li></ul><p><strong>Conclusion:</strong></p><p>Execution context is a fundamental concept in JavaScript that governs how code is executed and how variables are accessed within different scopes. By understanding the nuances of execution contexts, developers can write more robust and maintainable code. Mastery of this concept is essential for anyone looking to become proficient in JavaScript development.</p><p>In summary, remember that every piece of JavaScript code operates within an execution context, whether it’s the global context, function context, or an eval context. Understanding how these contexts work together is key to mastering JavaScript development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfd9231ed197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event Delegation — way to write scalable and maintainable Javascript code]]></title>
            <link>https://medium.com/@SejalPande1994/event-delegation-way-to-write-scalable-and-maintainable-javascript-code-acf33d76bdad?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/acf33d76bdad</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Thu, 08 Feb 2024 17:10:46 GMT</pubDate>
            <atom:updated>2024-02-08T17:10:46.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>Event Delegation — way to write scalable and maintainable Javascript code</h3><p>Event delegation is a powerful technique in JavaScript that allows you to efficiently handle events on multiple elements using a single event listener. This approach not only reduces the number of event handlers but also simplifies code maintenance and improves performance. In this article, we’ll explore the concept of event delegation, its benefits, and how to implement it with practical examples.</p><p><strong>Understanding Event Delegation:</strong></p><p>Event delegation involves attaching a single event listener to a parent element that will be responsible for handling events triggered by its child elements. When an event occurs, it bubbles up through the DOM hierarchy until it reaches the parent element, where the event listener is located. The event object then contains information about the target element that triggered the event, allowing you to perform the appropriate action.</p><p><strong>Benefits of Event Delegation:</strong></p><ol><li><strong><em>Improved Performance</em></strong>: By attaching fewer event listeners, event delegation reduces the overhead associated with managing event handlers, resulting in better performance, especially in applications with many dynamic elements.</li><li><strong><em>Simplified Code Structure:</em></strong> Event delegation simplifies the code structure by centralizing event handling logic within a single parent element, making it easier to maintain and debug.</li><li><strong><em>Dynamic Element Handling:</em></strong> Event delegation enables you to handle events on dynamically generated or added elements without the need to bind individual event listeners to each element.</li></ol><p><strong>Implementing Event Delegation:</strong></p><p>Let’s illustrate event delegation with an example:</p><p>Suppose we have an unordered list (&lt;ul&gt;) containing multiple list items (&lt;li&gt;), and we want to log a message when any list item is clicked.</p><pre>&lt;ul id=&quot;parentList&quot;&gt;<br> &lt;li&gt;Item 1&lt;/li&gt;<br> &lt;li&gt;Item 2&lt;/li&gt;<br> &lt;li&gt;Item 3&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>In JavaScript, we can implement event delegation as follows:</p><pre>const parentList = document.getElementById(&#39;parentList&#39;);<br>parentList.addEventListener(&#39;click&#39;, function(event) {<br>  if (event.target.tagName === &#39;LI&#39;) {<br>    console.log(`Clicked on: ${event.target.textContent}`);<br>  }<br>});</pre><p>In this example, we attach a click event listener to the parent list (&lt;ul&gt;) element. When a list item (&lt;li&gt;) is clicked, the event bubbles up to the parent list, where the event listener is located. We then check if the clicked element is an &lt;li&gt; using the event.target.tagName property and log the corresponding message.</p><p><strong>Benefits in Action:</strong></p><p>Imagine if we had hundreds of list items instead of just three. With event delegation, we only need to attach one event listener to the parent list, regardless of the number of list items. This results in cleaner and more efficient code.</p><p><strong>Conclusion:</strong></p><p>Event delegation is a valuable technique in JavaScript for handling events efficiently, especially in applications with dynamic content. By leveraging event delegation, you can streamline your code, improve performance, and enhance the user experience. Mastering this concept will empower you to write more scalable and maintainable JavaScript code.</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acf33d76bdad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering JavaScript’s Call, Apply, and Bind Methods]]></title>
            <link>https://medium.com/@SejalPande1994/mastering-javascripts-call-apply-and-bind-methods-c3f6a921e7b8?source=rss-b995bb39fdbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3f6a921e7b8</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sejal]]></dc:creator>
            <pubDate>Tue, 06 Feb 2024 16:35:26 GMT</pubDate>
            <atom:updated>2024-02-06T16:35:26.327Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript, being a versatile and dynamic language, provides developers with powerful tools to manipulate functions and their context. Among these tools are the call, apply, and bind methods, which allow for precise control over how functions are executed and what context they operate in.</p><p><strong>Understanding Call, Apply, and Bind:</strong></p><p><strong><em>1. Call Method:</em></strong><br>The call method allows you to invoke a function explicitly, specifying the value of this and passing arguments individually. It takes the context object as its first argument, followed by any number of arguments that will be passed to the function.</p><p>Example:</p><p>function sayHello(name) {<br>return `Hello, ${name}!`;<br>}</p><p>console.log(sayHello.call(null, ‘Bob’)); // Output: Hello, Bob!</p><p><strong><em>2. Apply Method:</em></strong><br>Similar to call, the apply method also invokes a function explicitly but accepts arguments as an array. This can be particularly useful when the number of <strong>arguments is dynamic or unknown</strong>.</p><p>Example:</p><p>function sayHello(name, age) {<br>return `Hello, ${name}! You are ${age} years old.`;<br>}</p><p>console.log(sayHello.apply(null, [‘Bob’, 30])); // Output: Hello, Bob! You are 30 years old.</p><p><em>3. Bind Method:</em><br>Unlike call and apply, the bind method creates a new function with a specified context (this) and optionally pre-defined arguments. This new function can then be invoked later.</p><p>Example:</p><p>const sayHello= function(name) {<br>return `Hello, ${name}!`;<br>}</p><p>const boundSayHello = sayHello.bind(null, ‘Bob’);<br>console.log(boundSayHello()); // Output: Hello, Bob!</p><p><strong>Common Use Cases:</strong></p><p><em>1. Context Switching:</em><br>call and apply are often used to invoke functions with a different context, especially in object-oriented programming where methods need to be borrowed or reused. Also know as <strong>Function Borrowing</strong>.<br><em>2. Function Currying:</em><br>bind is commonly used for creating partially applied functions, where some arguments are fixed in advance, creating a new function with a reduced arity (the number of arguments or operands taken by a function).<br><em>3. Callback Functions:</em><br>Callback functions passed to event listeners or asynchronous operations often need to preserve a specific context, which can be achieved using bind.</p><p><strong>Best Practices:</strong></p><p><em>1. Use Call and Apply for Immediate Invocation:</em><br>Use call and apply when you want to invoke a function immediately with a specific context and arguments.<br><em>2. Pre-bind Functions for Reusability:</em><br>Use bind to create new functions with a predefined context and arguments, making them reusable across your codebase.<br><em>3. Consider Performance Implications:</em><br>Be mindful of the performance overhead when using bind, as it creates a new function every time it’s called.</p><p>In conclusion, mastering JavaScript’s call, apply, and bind methods opens up a world of possibilities for function manipulation and context management. Understanding when and how to use these methods effectively can significantly enhance your coding skills and productivity as</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3f6a921e7b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>