<?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 Shrey Saroch on Medium]]></title>
        <description><![CDATA[Stories by Shrey Saroch on Medium]]></description>
        <link>https://medium.com/@shreysaroch?source=rss-b07902b07e16------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*umv4mD8wVC9pNSnCnhashA.jpeg</url>
            <title>Stories by Shrey Saroch on Medium</title>
            <link>https://medium.com/@shreysaroch?source=rss-b07902b07e16------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 09:56:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shreysaroch/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[What the heck are pure functions in Javascript?]]></title>
            <link>https://medium.com/@shreysaroch/what-the-heck-are-pure-functions-in-javascript-20040202f984?source=rss-b07902b07e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/20040202f984</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pure-function]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Shrey Saroch]]></dc:creator>
            <pubDate>Fri, 30 Aug 2019 13:13:00 GMT</pubDate>
            <atom:updated>2023-03-17T07:17:33.959Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*b_TwEsmzfTsB89J47tQhNQ.png" /><figcaption>Image is for representational purpose only — Getty Images</figcaption></figure><blockquote>This article intends to explain pure functions in the simplest manner possible!</blockquote><blockquote>A function is called a <em>pure</em> function when the below conditions are met:</blockquote><ol><li>The function should not produce any side-effects.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*rXMk_uTqKThzxr_azmBEsw.png" /></figure><p>2. The function should be dependent only on the input parameters</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AR6VzhI0w9eaXHmas-1wgQ.png" /></figure><h3>Observable side-effects are:</h3><ol><li>Making a network call</li><li>DOM manipulation</li><li>Math.Random</li><li>Making a network call</li><li>Getting current time</li><li>Mutating data</li></ol><h3>Examples of impure &amp; pure functions:</h3><figure><img alt="example of an impure function" src="https://cdn-images-1.medium.com/max/1024/1*TqKjx8zlKm0W3Ftl4Rto-g.png" /><figcaption>Example of an impure function as it is dependent on the external parameter foo</figcaption></figure><figure><img alt="Example of a pure function" src="https://cdn-images-1.medium.com/max/1024/1*R4kQ9Cx7HjW2WWhgZKLkZA.png" /><figcaption>Example of a pure function as it is dependent only on the input params</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbyiQAe-tncfpvOMlftReg.png" /><figcaption>Example of an impure function because the function is modifying the object car</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*odUU01lt2_LLJJu1QYW8gA.png" /></figure><h3>What are the benefits of pure functions?</h3><ol><li>No side effects</li><li>Maintainable</li><li>Testable</li></ol><h3>Why are pure functions important in Javascript?</h3><ol><li>Pure functions are heavily used in functional programming in javascript</li><li>It is preferable to use pure functions in libraries like React &amp; Redux</li><li>Not all functions need to be or should be, pure. We can mix pure and impure functions as per our requirements.</li></ol><p>I hope you now have the basic idea of how pure functions work in javascript. If you liked the article, feel free to <a href="https://www.paypal.com/paypalme/shreysaroch/5">buy me a coffee</a>!</p><p><em>Shrey is a full-time software developer, who likes to cook in his free time and is a pro in FIFA on PlayStation 5. He goes out of the way for the thing he loves.</em></p><blockquote><em>I’d like to propose a question. Can machines think?</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20040202f984" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>