<?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 Nirmal Jasmatiya on Medium]]></title>
        <description><![CDATA[Stories by Nirmal Jasmatiya on Medium]]></description>
        <link>https://medium.com/@nir_jaz?source=rss-ab70d6aa912f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Cizxcf_L5T1RbjEvGyRSmg@2x.jpeg</url>
            <title>Stories by Nirmal Jasmatiya on Medium</title>
            <link>https://medium.com/@nir_jaz?source=rss-ab70d6aa912f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:22:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nir_jaz/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[RAG Finally Clicked for Me]]></title>
            <link>https://medium.com/@nir_jaz/rag-finally-clicked-for-me-319a8d2502ec?source=rss-ab70d6aa912f------2</link>
            <guid isPermaLink="false">https://medium.com/p/319a8d2502ec</guid>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[token]]></category>
            <dc:creator><![CDATA[Nirmal Jasmatiya]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 07:14:51 GMT</pubDate>
            <atom:updated>2026-06-25T07:14:51.614Z</atom:updated>
            <content:encoded><![CDATA[<h3>RAG Finally Clicked for Me: Understanding Tokens, Embeddings, and Vector Databases</h3><p>Recently, I’ve been building Atlas, a personal knowledge assistant that lets me upload documents and ask questions about them. What started as a side project quickly turned into a crash course on RAG, embeddings, vector databases, and semantic search. Along the way, a lot of concepts I’d previously learned in isolation finally started making sense.</p><p>Like many engineers getting into AI, I’d heard these terms countless times before. I could explain them individually, but if someone had asked me how they all fit together in a real system, I wouldn’t have had a great answer.</p><p>Building Atlas forced me to understand how modern AI systems actually work under the hood. What surprised me most was that none of these concepts are particularly complicated on their own. The challenge is understanding how they fit together.</p><p>This post is the explanation I wish I had when I started.</p><h3>The Real Problem</h3><p>Let’s start with a simple question. Imagine you upload your resume and ask an LLM:</p><blockquote><em>What technologies have I used in production?</em></blockquote><p>The model can answer correctly if your resume is included in the prompt. But what happens when you upload hundreds of documents?</p><p>Your resume.</p><p>Meeting notes.</p><p>Project documentation.</p><p>Architecture decisions.</p><p>Personal notes.</p><p>Soon, the amount of information exceeds the model’s context window.</p><p>The model doesn’t actually “remember” your documents. It only knows what you provide in the current conversation. This is the problem RAG solves.</p><h3>First: What Are Tokens?</h3><p>Humans read words. Language models read tokens. A token is a small chunk of text.</p><p>Take a simple sentence:</p><blockquote><em>Substack is awesome</em></blockquote><p>To us, that’s three words. To a language model, it’s a sequence of tokens.</p><p>Depending on the <a href="https://huggingface.co/docs/transformers/en/main_classes/tokenizer">tokenizer</a>, the sentence might be split into something like:</p><pre>[&quot;Substack&quot;, &quot; is&quot;, &quot; awesome&quot;]</pre><p>or:</p><pre>[&quot;Sub&quot;, &quot;stack&quot;, &quot; is&quot;, &quot; awesome&quot;]</pre><p>The exact tokenization isn’t important. What matters is that every piece of text must be converted into tokens before the model can process it.</p><p>This is also how context limits are measured. Models don’t think in pages, paragraphs, or documents. They think in tokens.</p><p>If a model supports 128,000 tokens, anything beyond that limit must be removed or ignored. This means we cannot simply dump an entire knowledge base into every prompt. We need a way to retrieve only the relevant information.</p><p>That’s where embeddings come in.</p><h3>Embeddings: Turning Meaning Into Numbers</h3><p>This was the biggest mental shift for me.</p><p>Most explanations describe embeddings as:</p><blockquote><em>A numerical representation of text.</em></blockquote><p>Technically that’s correct, but it didn’t really help me.</p><p>Suppose we have two sentences:</p><blockquote><em>“How do I deploy my application?”</em></blockquote><blockquote><em>“What’s the process for releasing software?”</em></blockquote><p>The wording is different. The meaning is similar.</p><p>Traditional text search struggles with this because it looks for matching words.</p><p>Embeddings solve this problem. An embedding model converts text into a list of numbers. Something like:</p><pre>[0.12, -0.43, 0.91, ...]</pre><p>In reality, there might be hundreds or thousands of dimensions.</p><p>The important part is that semantically similar sentences produce vectors that are close together in vector space.</p><p>This means:</p><blockquote><em>“How do I deploy my app?”</em></blockquote><blockquote><em>“How do I release software?”</em></blockquote><p>end up near each other.</p><p>While:</p><blockquote><em>“How do I cook pasta?”</em></blockquote><p>ends up far away.</p><p>The model is no longer matching words. It’s matching meaning. That is the superpower of embeddings.</p><h3>Why a Normal Database Isn’t Enough</h3><p>My first thought was:</p><p>Can’t I just store embeddings in PostgreSQL as JSON?</p><p>Technically, yes.</p><p>Practically, no.</p><p>Imagine storing millions of vectors and comparing each one against a user’s query. That becomes expensive very quickly. You need efficient similarity search.</p><p>This is where vector databases come in.</p><p>Popular options include:</p><ul><li><a href="https://www.pinecone.io/">Pinecone</a></li><li><a href="https://github.com/weaviate/weaviate">Weaviate</a></li><li><a href="https://github.com/qdrant/qdrant">Qdrant</a></li><li><a href="https://github.com/milvus-io/milvus">Milvus</a></li><li>PostgreSQL (via <a href="https://github.com/pgvector/pgvector">pgvector</a>)</li></ul><p>These systems are optimized for questions like:</p><blockquote><em>“Show me the 5 pieces of content most similar to this query.”</em></blockquote><p>instead of:</p><blockquote><em>“Show me rows where name = ‘John’.”</em></blockquote><p>Traditional databases excel at exact matching. Vector databases excel at semantic matching.</p><h3>Putting It All Together: What Is RAG?</h3><p>Once I understood tokens, embeddings, and vector databases, RAG suddenly became much simpler.</p><p>Let’s walk through the flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PbBkQ9VteexK_ykQ.png" /><figcaption>RAG in a Nutshell</figcaption></figure><h4>Step 1: Upload Documents</h4><p>We start by uploading documents into the system.</p><p>These could be PDFs, notes, resumes, meeting summaries, or technical documentation.</p><h4>Step 2: Split Documents Into Chunks</h4><p>Large documents are broken into smaller pieces called chunks.</p><p>Instead of storing a 20-page document as one giant block, we split it into smaller sections that can be retrieved independently.</p><h4>Step 3: Generate Embeddings</h4><p>Each chunk is converted into an embedding vector.</p><p>Now every piece of content has a semantic representation.</p><h4>Step 4: Store in a Vector Database</h4><p>The embeddings, along with metadata about the source document, are stored in a vector database.</p><h4>Step 5: Convert the User Question Into an Embedding</h4><p>For example:</p><blockquote><em>“What backend technologies have I used?”</em></blockquote><p>The question itself is converted into an embedding.</p><h4>Step 6: Retrieve Similar Chunks</h4><p>The vector database finds the most relevant chunks.</p><p>Maybe:</p><ul><li>Resume skills section</li><li>Project experience section</li><li>Architecture notes</li></ul><h4>Step 7: Send Retrieved Context to the LLM</h4><p>Only the relevant chunks are added to the prompt. Instead of sending thousands of documents, we send just the few pieces of information that matter.</p><p>The model now answers using the retrieved information.</p><p>This is Retrieval-Augmented Generation.</p><p>Not magic.</p><p>Just retrieval plus generation.</p><h3>The Biggest Misconception I Had About RAG</h3><p>When I first started learning about RAG, I assumed the difficult part was the LLM.</p><p>I was wrong.</p><p>The LLM is often the easiest part of the system.</p><p>The difficult questions are:</p><ul><li>How should documents be chunked?</li><li>How much context should be retrieved?</li><li>How do we measure retrieval quality?</li><li>What metadata should be stored?</li><li>How do we evaluate whether retrieval is working correctly?</li></ul><p>Most production RAG systems succeed or fail based on retrieval quality, not model quality. That’s something I didn’t appreciate until I started building one myself.</p><h3>Building Atlas Changed How I Think About Search</h3><p>Before building Atlas, I thought of search as:</p><pre>Keyword -&gt; Results</pre><p>Now I think of it as:</p><pre>Meaning -&gt; Similar Meaning</pre><p>That’s the real shift.</p><p>Embeddings allow us to search for meaning rather than words. Vector databases make that search fast. RAG combines retrieval and generation so that language models can answer questions using information they were never trained on.</p><p>Once those pieces clicked together, a lot of modern AI applications suddenly made much more sense to me.</p><p>Not because the models became simpler, but because I finally understood the systems around them.</p><h3>What’s Next?</h3><p>This is the first post in what will probably become a series documenting my journey building Atlas.</p><p>In future posts, I plan to dive deeper into:</p><ul><li>Chunking strategies and tradeoffs</li><li>Similarity scores and vector search</li><li>Why top-k retrieval matters</li><li>Common RAG failure modes</li><li>Evaluating retrieval quality</li></ul><p>Because understanding RAG isn’t about memorizing definitions. It’s about understanding how meaning flows through a system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=319a8d2502ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Distributed Systems Easy with Temporal: A Guide for Every Developer]]></title>
            <link>https://medium.com/@nir_jaz/making-distributed-systems-easy-with-temporal-a-guide-for-every-developer-8cb6247be7c6?source=rss-ab70d6aa912f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cb6247be7c6</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Nirmal Jasmatiya]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 11:59:37 GMT</pubDate>
            <atom:updated>2024-02-13T11:59:37.938Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_l2IWcC8Eqe7a72motQWA.png" /></figure><p>In the world of software development, handling distributed systems is like tackling a giant puzzle. These systems are complex because they involve many moving parts working together over the internet. But, ensuring these systems are reliable, can handle lots of work, and can recover from mistakes is a big challenge. That’s where <a href="https://temporal.io/"><strong>Temporal</strong></a> comes in — it’s like a magic tool that makes managing these complicated systems much simpler. Let’s dive into how Temporal makes the life of a developer easier and more fun.</p><h3>🤦‍♂️ The Big Challenge of Distributed Systems</h3><p>Imagine you’re creating an app that needs to handle lots of users at the same time, doing different things like shopping, paying, or chatting. Each user’s action might involve several steps and systems talking to each other. If one step fails, it can mess up the whole process. Traditional ways to manage these workflows often feel like you’re constantly fixing problems, making sure everything talks correctly to each other, and keeping track of where each process is at.</p><h3>🦸‍♂ Temporal to the Rescue</h3><p>Temporal is like a superhero for developers. It was made by people at Uber who needed a better way to manage complex tasks that involve many steps and systems. Temporal helps you organize these tasks, keep track of them, and make sure they can handle problems like errors or delays without needing a lot of extra code to manage these issues.</p><h3>✨ What Makes Temporal Special?</h3><ul><li><strong>Workflows and Activities:</strong> Think of your app’s tasks as workflows, broken down into smaller tasks called activities. Temporal keeps track of these, even if there’s a problem or if you need to restart something.</li><li><strong>Workers:</strong> These are the workhorses that do the tasks you’ve defined. You can have as many as you need to handle your app’s workload.</li><li><strong>Temporal Server:</strong> This is the brain of the operation, keeping everything running smoothly, tracking all the workflows, and making sure they’re doing what they’re supposed to do.</li></ul><h3>Why You’ll ❤️ Temporal</h3><h4>🧑‍💻 Handling Mistakes Like a Pro</h4><p>One of the best things about Temporal is how it deals with errors. It remembers what each part of your app is supposed to do, so if something goes wrong, it can retry or handle the problem based on how you’ve set things up. This means less headache for you trying to figure out how to keep everything running smoothly.</p><h4>👀 Keeping an Eye on Everything</h4><p>Temporal gives you a clear view of what’s happening in your app with a user-friendly dashboard. You can see how tasks are progressing, find issues quickly, and fix them, which is great for keeping your app running well.</p><h4>&lt;/&gt; Works with Your Favourite Programming Language</h4><p>No matter if you like writing code in Java, Go, Python, Node JS or PHP, Temporal works with many programming languages. This means you can start using it without having to learn a new language first.</p><h3>🌏 Real-World Uses</h3><p>Temporal isn’t just theory; it’s being used by all kinds of apps and services to do things like:</p><ul><li><strong>E-commerce:</strong> Managing orders, stock, and delivery across different services.</li><li><strong>Financial Services:</strong> Running complex transactions smoothly.</li><li><strong>Media Processing:</strong> Handling video uploads, editing, and distribution without a hitch.</li></ul><h3>🚀 Getting Started with Temporal</h3><p>Jumping into Temporal is <a href="https://docs.temporal.io/getting-started">straightforward</a>. You set it up, define your tasks and how they fit together, and then let Temporal handle the heavy lifting. You’ll write less code for managing errors and more code that does what your app is really about.</p><h3>📦 Wrapping Up</h3><p>Temporal is changing the game for developers working on distributed systems. It takes away the pain of managing complex tasks, so you can focus on building features that matter. If you’re tired of dealing with the headaches of distributed systems, give Temporal a try and see how much simpler your life can be.</p><h3>👨🏻‍💻 About Me</h3><p>I’m a product engineer who loves finding simple solutions to big challenges. I’ve worked on building apps that need to serve millions of users and believe that good technology can make our work a lot easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cb6247be7c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Tale of Two Monitoring Giants: Navigating Datadog and New Relic]]></title>
            <link>https://medium.com/@nir_jaz/a-tale-of-two-monitoring-giants-navigating-datadog-and-new-relic-2e54c02194b5?source=rss-ab70d6aa912f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e54c02194b5</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Nirmal Jasmatiya]]></dc:creator>
            <pubDate>Mon, 20 Nov 2023 21:17:01 GMT</pubDate>
            <atom:updated>2023-11-20T21:17:01.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>In the dynamic landscape of application monitoring, choosing the right tool can make all the difference. Having navigated the realms of both Datadog and New Relic, I found myself leaning towards the latter for a myriad of reasons. Let’s delve into a comparative exploration of these two monitoring juggernauts.</p><h3>User Interface and Experience:</h3><p>New Relic’s sleek and intuitive interface has always stood out to me, providing a seamless user experience. While Datadog boasts a robust platform, New Relic’s UI shines with its simplicity, making it a pleasure to navigate even for complex monitoring tasks.</p><h3>Customization and Flexibility:</h3><p>One of the aspects I admired about New Relic was its flexibility in adapting to diverse monitoring needs. From custom dashboards to tailored alerting mechanisms, New Relic empowers users to mold their monitoring environment to fit the unique demands of their applications.</p><h3>Alerting and Notification Systems:</h3><p>In the realm of alerting, New Relic’s alert policies and notification systems felt more straightforward and efficient to set up. The ease of configuring alerts ensures timely responses to potential issues, a critical factor in maintaining the health of any application.</p><h3>Integration Ecosystem:</h3><p>While both Datadog and New Relic boast extensive integrations, New Relic’s seamless compatibility with a wide array of technologies and frameworks impressed me. It seamlessly integrated with my tech stack, reducing the complexity of implementation and enhancing overall monitoring efficiency.</p><h3>Cost Considerations:</h3><p>Cost is a significant factor in any monitoring solution decision. New Relic’s transparent pricing model and ease of scaling made it easier for me to manage costs effectively. Datadog, while powerful, can sometimes present challenges in predicting costs, especially as your infrastructure scales.</p><h3>Community and Support:</h3><p>New Relic’s robust community and responsive support added a layer of confidence to my monitoring endeavors. The wealth of resources and the active community played a pivotal role in troubleshooting and optimizing my monitoring setup.</p><h3>Conclusion:</h3><p>In the realm of Datadog vs. New Relic, personal preference often plays a substantial role. While Datadog boasts a powerful suite of monitoring tools, my experiences have led me to favor New Relic for its user-friendly interface, customization capabilities, and seamless integrations. As you navigate your monitoring journey, consider your specific requirements and preferences to determine which platform aligns best with your needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e54c02194b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Destructuring assignment in JavaScript — Part 1]]></title>
            <link>https://medium.com/getpowerplay/destructuring-assignment-in-javascript-part-1-98537a644964?source=rss-ab70d6aa912f------2</link>
            <guid isPermaLink="false">https://medium.com/p/98537a644964</guid>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Nirmal Jasmatiya]]></dc:creator>
            <pubDate>Sun, 20 Feb 2022 10:17:16 GMT</pubDate>
            <atom:updated>2022-03-02T17:33:09.726Z</atom:updated>
            <content:encoded><![CDATA[<h3>Destructuring assignment in JavaScript</h3><p><strong>Destructuring assignment</strong> syntax (Introduced in ES6) is a JavaScript expression that allows us to extract data from arrays, objects, and maps and set them into new, distinct variables. For example,</p><h4>Before ES6:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzMsKRjOhwTeL2N6deYvow.png" /></figure><h4>From ES6:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hlnSNTq7veHbcMw8idJqhA.png" /></figure><blockquote><strong><em>Note:</em></strong><em> When destructuring objects, you should use a variable name corresponding to the object key. The order of the name does not matter in object destructuring.</em></blockquote><p>If you want to assign different variable names for the object key, you can use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-eSVE-5YdGkqbs3_No1Hfw.png" /></figure><h4>Array Destructuring</h4><p>You can also similarly perform array destructuring. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrXenp5JZK4AjGuUzQYKnA.png" /></figure><h4>Assign Default Values</h4><p>You can assign the default values for variables while using destructuring. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-_N39DCf32wdDNPLdrdiw.png" /></figure><p>In the above program, tags have only one element. Hence, the variable <strong><em>tag1</em></strong> will be Tower A, and variable <strong><em>tag2</em></strong> takes the default value Flooring.</p><p>In object destructuring, you can similarly pass default values. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcf_WAg7fXKFEEScpag9bQ.png" /></figure><h4>Assignment separate from declaration</h4><p>A variable can be assigned its value via destructuring, separate from the variable’s declaration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k4S7Mkv6xnK8-Eu5cFbvWA.png" /></figure><blockquote><strong>Note:</strong> The parentheses <strong>( … )</strong> around the assignment statement are required when using object literal destructuring assignment without a declaration.</blockquote><blockquote>Your<strong> ( … ) </strong>expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.</blockquote><h4>Swapping Variables</h4><p>By using destructuring assignment syntax, you can easily swap values of two variables in one expression. Without destructuring assignment, you need a temporary variable to swap values of two variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNKhokQ60XRf6S5gvMqeIw.png" /></figure><h4>Ignore values</h4><p>You can ignore unwanted values in an array without assigning them to local variables. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YHZ681Wz69r3KCL31itx5Q.png" /></figure><h4>Assigning the rest of object and array to a variable</h4><p>When destructuring an object and array, you can unpack and assign the remaining part of an object and array to a variable using the rest pattern. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1kiF4n59WRdxH96P8S1Ew.png" /></figure><blockquote><em>Note: Always consider using the rest </em><strong><em>(…)</em></strong><em> operator as the last element. </em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError"><strong><em>SyntaxError</em></strong></a><em> will be thrown if a trailing comma is used on the right-hand side of a rest element.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9uo0_QcZyjUWYlDNb2OTWg.png" /></figure><h4>Nested object and array destructuring</h4><p>You can also perform nested destructuring on object and array. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRYyiFIM_WQ1rBDT0R81AQ.png" /></figure><p>In the above example, the variables <strong><em>start_date</em></strong> and <strong><em>end_date</em></strong> are nested properties of object task and the variables <strong><em>tag3</em></strong> and <strong><em>tag4</em></strong> are nested elements of tags.</p><p>To execute the nested destructuring assignment for objects, you have to enclose the variables in an object structure (by enclosing inside <strong><em>{}</em></strong>) and <strong><em>[]</em></strong> for an array.</p><p><strong>Resources:</strong></p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">Destructuring assignment - JavaScript | MDN</a></p><p>I hope by now you must have got a clear understanding of how destructuring works in JavaScript. So we know that destructuring sneaks into your everyday use of the language, quietly making your code a bit shorter and cleaner all over the place.</p><p>I’d love to hear your thoughts on using destructuring in other ways. You can also share a snippet in the comments below to help your fellow developers. Stay tuned for <strong>Part 2</strong> to get in-depth Knowledge about Destructuring &amp; Its applications.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98537a644964" width="1" height="1" alt=""><hr><p><a href="https://medium.com/getpowerplay/destructuring-assignment-in-javascript-part-1-98537a644964">Destructuring assignment in JavaScript — Part 1</a> was originally published in <a href="https://medium.com/getpowerplay">Powerplay</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Object Literals in JavaScript to write complex conditions?]]></title>
            <link>https://medium.com/@nir_jaz/how-to-use-object-literals-in-javascript-to-write-complex-conditions-94acadb0c2?source=rss-ab70d6aa912f------2</link>
            <guid isPermaLink="false">https://medium.com/p/94acadb0c2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Nirmal Jasmatiya]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 11:00:10 GMT</pubDate>
            <atom:updated>2021-10-10T06:40:55.873Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing complex conditions in JavaScript has always had the potential to create some untidy code. A long list of if/else statements or switch cases can get bloated fast.</p><p>When there are multiple conditions, I find object literals to be the most readable way of structuring code. Let’s have a look at how they work.</p><p>As an example, let’s say we have a function that takes a dog breed and returns the quote. Using if/else statements, it would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jEXHUHJiuAr2QPa2dGI6ng.png" /></figure><p>This isn’t great. Not only is it not very readable, but we are also repeating toLowerCase() for every statement.</p><p>We could avoid that repetition by assigning the lowercased breed to a variable at the start of the function or alternatively use a switch statement, which would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qp8LUcRE6OKhCLgS95OhFw.png" /></figure><p>We are now only calling toLowerCase() once, but this still doesn’t feel that readable. switch statements can also be prone to errors. In this case, we are just returning a value, but when you have more complex functionality, it can be easy to miss a break statement and introduce bugs.</p><h3>An Alternative</h3><p>You can use an object to achieve the same functionality as above in a much neater way. Let’s have a look at an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzcqpa6Iee_DZkJXv29ZWg.png" /></figure><p>We have an object where the keys are the conditions and the values are the responses. Then we can use the square bracket notation to select the correct value of the object from the breed passed in.</p><p>The final part of line 10 (?? &quot;Quote not found&quot;) uses <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator">nullish coalescing</a> to assign a default response. This means that if breeds[breed.toLowercase()]is null or undefined (but not false or 0 ), then the default string “Quote not found” is returned. This is important because we might legitimately want to return false or 0 from our conditional. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NCBf4XVxygt66W651q0XPQ.png" /></figure><p>This is a very contrived example, but hopefully, it illustrates how nullish coalescing can help avoid introducing bugs!</p><h3>More Complex Logic</h3><p>There are times when you might need to do some more complex logic inside your conditions. To achieve this, you can pass a function as the value to your object keys and execute the response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sp6JEg3Yzxl4u3PgI1ODag.png" /></figure><p>We are selecting the calculation we want to do and executing the response, passing the two numbers. You can use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining">optional chaining</a> (the ?. in JavaScript, is a new feature introduced in ES2020.) to only execute the response if it is defined. Otherwise, fall through to the default return string.</p><h3>Conclusion</h3><p>Writing conditionals will always be a matter of taste, and certain situations will require a different approach. However, I find that when I have several conditions to check against, object literals are the most readable and maintainable way.</p><p>I’d love to hear your thoughts or if you have a different approach than the ones outlined above!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94acadb0c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>