<?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 Prabhash Kumar on Medium]]></title>
        <description><![CDATA[Stories by Prabhash Kumar on Medium]]></description>
        <link>https://medium.com/@binaryprabhash.dev?source=rss-76ecbb325e12------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gXYeQnCqtdUVQWfR</url>
            <title>Stories by Prabhash Kumar on Medium</title>
            <link>https://medium.com/@binaryprabhash.dev?source=rss-76ecbb325e12------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:39:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@binaryprabhash.dev/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 Advanced TypeScript: Generics, Type Guards, and Utility Types]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Welcome to Part 4 of the TypeScript Starter Series!
&#xA0;In Part 3, we explored functions, classes, and modules. Now it&#x2019;s time to unlock&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@binaryprabhash.dev/mastering-advanced-typescript-generics-type-guards-and-utility-types-344440d6bfe7?source=rss-76ecbb325e12------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@binaryprabhash.dev/mastering-advanced-typescript-generics-type-guards-and-utility-types-344440d6bfe7?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/344440d6bfe7</guid>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 06:43:07 GMT</pubDate>
            <atom:updated>2025-06-24T06:43:07.473Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ TypeScript in Action: Functions, Classes, and Modules]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Welcome to Part 3 of the TypeScript Starter Series!
&#xA0;In Part 2, we explored basic types and interfaces. Now let&#x2019;s move one step closer to&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@binaryprabhash.dev/typescript-in-action-functions-classes-and-modules-e8145d7d67eb?source=rss-76ecbb325e12------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@binaryprabhash.dev/typescript-in-action-functions-classes-and-modules-e8145d7d67eb?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8145d7d67eb</guid>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 06:34:19 GMT</pubDate>
            <atom:updated>2025-06-24T06:34:19.717Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ TypeScript Basics: Types, Interfaces, and Beyond]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">So you&#x2019;ve written your first TypeScript file in Article 1: &#x201C;Why TypeScript? A Beginner&#x2019;s Guide to Stronger JavaScript&#x201D;. But what makes&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@binaryprabhash.dev/typescript-basics-types-interfaces-and-beyond-ece99f35436d?source=rss-76ecbb325e12------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@binaryprabhash.dev/typescript-basics-types-interfaces-and-beyond-ece99f35436d?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/ece99f35436d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Tue, 27 May 2025 06:48:48 GMT</pubDate>
            <atom:updated>2025-06-24T06:24:46.733Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[ Why TypeScript? A Beginner’s Guide to Stronger JavaScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">JavaScript is everywhere&#x200A;&#x2014;&#x200A;from websites to mobile apps, even server-side development. But as your codebase grows, so does the complexity&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@binaryprabhash.dev/why-typescript-a-beginners-guide-to-stronger-javascript-b49efe8eda8f?source=rss-76ecbb325e12------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@binaryprabhash.dev/why-typescript-a-beginners-guide-to-stronger-javascript-b49efe8eda8f?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/b49efe8eda8f</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Tue, 27 May 2025 06:22:30 GMT</pubDate>
            <atom:updated>2025-06-24T05:58:15.436Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Using Event Emitters for Cross-Component Communication in JavaScript Frameworks]]></title>
            <link>https://medium.com/@binaryprabhash.dev/using-event-emitters-for-cross-component-communication-in-javascript-frameworks-7ff7934582d3?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ff7934582d3</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[code-reusability]]></category>
            <category><![CDATA[eventemitter]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[code-modularity]]></category>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Thu, 12 Dec 2024 08:01:44 GMT</pubDate>
            <atom:updated>2024-12-12T08:01:44.060Z</atom:updated>
            <content:encoded><![CDATA[<p>When building modern web applications, you often encounter scenarios where multiple components need to react to the same event. For instance, when a user logs in, one component might display their name, another might reveal a sidebar, and yet another might show a welcome notification. Handling such scenarios efficiently can be tricky if you rely solely on tightly coupled function calls or direct parent-child communication.</p><p>This is where <strong>Event Emitters</strong> shine. By leveraging an event-driven architecture, you can decouple components, making your application easier to manage and scale.</p><h4>What is an Event Emitter?</h4><p>An Event Emitter is an object that allows you to define custom events and register listeners for those events. When an event is emitted, all registered listeners are called. This enables multiple actions to occur independently in response to the same event.</p><h4>Why Use Event Emitters?</h4><p><strong>1. Decoupled Communication:</strong> Components can respond to events without being aware of each other’s existence.<br><strong>2. Scalability:</strong> Easily add or remove listeners for events without modifying the core logic.<br><strong>3. Reusable Logic:</strong> Listeners can be reused across multiple components or parts of the app.<br><strong>4. Flexibility:</strong> Events can be emitted from anywhere in the application, triggering reactions in any interested component.</p><h4>Example Scenario: User Login</h4><p>Imagine a web application with the following components:<br>1. A <strong>Header</strong> that displays the user’s name after login.<br>2. A <strong>Sidebar </strong>that becomes visible after login.<br>3. A <strong>Notification</strong> component that shows a “Welcome back” message upon login.</p><p>Each of these components needs to respond to the same event: a <em>login</em> event.</p><h4>Step 1: Create a Shared Event Emitter</h4><p>To centralize event management, you can create a shared instance of an Event Emitter. Here’s how you can set it up:</p><pre>import { EventEmitter } from &#39;events&#39;;<br>// Export a shared instance of EventEmitter<br>export const appEvents = new EventEmitter();</pre><p>This <em>appEvents</em> object will act as the communication hub for your application.</p><h4>Step 2: Components Reacting to the `login` Event</h4><p><strong>Header Component</strong><br>The Header updates to display the user’s name when the `login` event is emitted.</p><pre>import { appEvents } from &#39;./eventEmitter&#39;;<br>// Initialize user name<br>let userName = &#39;&#39;;<br>const handleLogin = (user) =&gt; {<br> userName = user.name;<br> console.log(`Header updated: Welcome, ${userName}`);<br>};<br>// Register the event listener<br>appEvents.on(&#39;login&#39;, handleLogin);</pre><p><strong>Sidebar Component</strong><br>The Sidebar becomes visible after the user logs in.</p><pre>import { appEvents } from &#39;./eventEmitter&#39;;<br>let isVisible = false;<br>const handleLogin = () =&gt; {<br> isVisible = true;<br> console.log(&#39;Sidebar is now visible&#39;);<br>};<br>appEvents.on(&#39;login&#39;, handleLogin);</pre><p><strong>Notification Component</strong><br>The Notification component shows a welcome message on login.</p><pre>import { appEvents } from &#39;./eventEmitter&#39;;<br>let message = &#39;&#39;;<br>const handleLogin = (user) =&gt; {<br> message = `Welcome back, ${user.name}!`;<br> console.log(message);<br> setTimeout(() =&gt; {<br> message = &#39;&#39;; // Clear the message after 3 seconds<br> }, 3000);<br>};<br>appEvents.on(&#39;login&#39;, handleLogin);</pre><h4>Step 3: Emitting the login Event</h4><p>When the user logs in, you emit the <em>login</em> event, passing relevant data (like the user object).</p><pre>import { appEvents } from &#39;./eventEmitter&#39;;<br>function loginUser() {<br> const user = { name: &#39;Alice&#39;, id: 1 }; // Mock user data<br> console.log(&#39;User logging in…&#39;);<br> appEvents.emit(&#39;login&#39;, user);<br>}<br>// Simulate a login button click<br>loginUser();</pre><p><strong>Output</strong><br>When the <em>login </em>event is emitted, all registered listeners react independently:</p><pre>User logging in…<br>Header updated: Welcome, Alice<br>Sidebar is now visible<br>Welcome back, Alice!</pre><h4>Why This Approach Works Well</h4><p><strong>1. Modularity:</strong> Each component focuses only on its own responsibility, reacting to the <em>login</em> event without knowing or caring about other components.<br><strong>2. Reusability:</strong> The <em>login</em> event can be emitted from anywhere — a login form, an API callback, or even test scripts.<br><strong>3. Dynamic Control:</strong> You can add or remove listeners at runtime using <em>appEvents.on</em> and <em>appEvents.off</em>.</p><p>For example:</p><pre>// Dynamically remove the Header listener<br>appEvents.off(&#39;login&#39;, handleLogin);</pre><h4>Final Thoughts</h4><p>Using an Event Emitter for cross-component communication is a powerful way to decouple your code and improve maintainability in component-based frameworks like React, Svelte, Angular, or even vanilla JavaScript applications. By centralizing event handling, you can manage complex interactions across your app with ease.</p><p>Next time you face a scenario where multiple components need to respond to the same event, consider reaching for an Event Emitter — it might be just the tool you need!</p><p>Happy Coding!❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ff7934582d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CommonJS vs ESM: Understanding JavaScript Modules]]></title>
            <link>https://medium.com/@binaryprabhash.dev/commonjs-vs-esm-understanding-javascript-modules-48318077b5d9?source=rss-76ecbb325e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/48318077b5d9</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Prabhash Kumar]]></dc:creator>
            <pubDate>Thu, 12 Dec 2024 07:17:44 GMT</pubDate>
            <atom:updated>2024-12-12T07:17:44.508Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript has two primary module systems: <strong>CommonJS (CJS)</strong> and <strong>ECMAScript Modules (ESM)</strong>. Both serve the same purpose — to organize and reuse code — but they differ significantly in syntax, behavior, and use cases. This article breaks down these differences with examples to help you decide which one suits your project.</p><h4>CommonJS (CJS)</h4><p><strong>Introduction</strong>: CommonJS was the default module system for Node.js before ECMAScript Modules were introduced. It is synchronous and uses require to import and module.exports to export.</p><p><strong>Syntax</strong>:</p><pre><br>// Exporting in CommonJS<br>const greet = (name) =&gt; `Hello, ${name}!`;<br>module.exports = greet;<br><br>// Importing in CommonJS<br>const greet = require(&#39;./greet&#39;);<br>console.log(greet(&#39;Alice&#39;)); // Hello, Alice!</pre><p><strong>Characteristics</strong>:</p><ul><li><strong>Synchronous Loading</strong>: Modules are loaded synchronously, making it unsuitable for environments like browsers where asynchronous behavior is preferred.</li><li><strong>Dynamic Imports</strong>: You can dynamically import modules using conditional logic.</li></ul><p><strong>Example</strong>:</p><pre>if (process.env.ENV === &#39;development&#39;) {<br>    const devTool = require(&#39;./devTool&#39;);<br>    devTool.init();<br>}</pre><h4>ECMAScript Modules (ESM)</h4><p><strong>Introduction</strong>: ESM is the official standard for JavaScript modules, introduced in ES6 (2015). It uses import and export keywords and is supported in modern JavaScript runtimes, including browsers and Node.js (from version 12+ with .mjs or &quot;type&quot;: &quot;module&quot; in package.json).</p><p><strong>Syntax</strong>:</p><pre>// Exporting in ESM<br>export const greet = (name) =&gt; `Hello, ${name}!`;<br><br>// Importing in ESM<br>import { greet } from &#39;./greet.js&#39;;<br>console.log(greet(&#39;Alice&#39;)); // Hello, Alice!</pre><p><strong>Characteristics</strong>:</p><ul><li><strong>Asynchronous Loading</strong>: Modules are loaded asynchronously, making it ideal for web environments.</li><li><strong>Static Structure</strong>: The structure of ESM is static, allowing for better optimization like tree-shaking.</li></ul><pre>// Exporting in ESM<br>export const greet = (name) =&gt; `Hello, ${name}!`;<br><br>// Importing in ESM<br>import { greet } from &#39;./greet.js&#39;;<br>console.log(greet(&#39;Alice&#39;)); // Hello, Alice!</pre><p><strong>Characteristics</strong>:</p><ul><li><strong>Asynchronous Loading</strong>: Modules are loaded asynchronously, making it ideal for web environments.</li><li><strong>Static Structure</strong>: The structure of ESM is static, allowing for better optimization like tree-shaking.</li></ul><p><strong>Example</strong>:</p><pre>// Exporting multiple items<br>export const add = (a, b) =&gt; a + b;<br>export const subtract = (a, b) =&gt; a - b;<br><br>// Importing multiple items<br>import { add, subtract } from &#39;./math.js&#39;;<br>console.log(add(5, 3)); // 8<br>console.log(subtract(5, 3)); // 2</pre><h4>Choosing Between CommonJS and ESM</h4><p><strong>Use CommonJS if:</strong></p><ul><li>You are working on a Node.js project with no plans to use modern ESM features.</li><li>You need dynamic imports extensively.</li></ul><p><strong>Use ESM if:</strong></p><ul><li>You want to leverage modern JavaScript features like tree-shaking.</li><li>Your code will run in a browser environment.</li><li>You aim for better compatibility with modern JavaScript tooling.</li></ul><h4>Transitioning from CJS to ESM</h4><p>If you’re migrating a project from CommonJS to ESM, follow these steps:</p><ol><li>Rename files from .js to .mjs, or add &quot;type&quot;: &quot;module&quot; to your package.json.</li><li>Replace require with import and module.exports with export.</li><li>Test the module functionality thoroughly to ensure compatibility.</li></ol><p>Example:</p><pre>// CommonJS<br>const greet = require(&#39;./greet&#39;);<br>module.exports = greet;<br><br>// ESM<br>import { greet } from &#39;./greet.js&#39;;<br>export { greet };</pre><h4>Conclusion</h4><p>Both CommonJS and ESM have their strengths and weaknesses. While CommonJS remains widely used in older Node.js projects, ESM is the future of JavaScript modules. By understanding their differences, you can make an informed decision that aligns with your project’s goals and environment.</p><p>Happy coding!❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48318077b5d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>