<?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 Akshay Shekokar on Medium]]></title>
        <description><![CDATA[Stories by Akshay Shekokar on Medium]]></description>
        <link>https://medium.com/@akshayshekokar?source=rss-ec9253e0693f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KZHxmXOf1BN8cTNp.</url>
            <title>Stories by Akshay Shekokar on Medium</title>
            <link>https://medium.com/@akshayshekokar?source=rss-ec9253e0693f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 01:39:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshayshekokar/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[JS Array: ‘includes’ vs ‘indexOf’]]></title>
            <link>https://medium.com/@akshayshekokar/js-array-includes-vs-indexof-994e62116bd3?source=rss-ec9253e0693f------2</link>
            <guid isPermaLink="false">https://medium.com/p/994e62116bd3</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Akshay Shekokar]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 15:28:45 GMT</pubDate>
            <atom:updated>2021-10-06T16:21:45.578Z</atom:updated>
            <content:encoded><![CDATA[<p>These two array methods are very common in use. People often get confused which one to use out of these two. This article mainly focus on its usage and advantages of one over another.</p><p>Let’s get started with knowing these methods and its usage.</p><p><strong>includes: </strong>This array method is mainly used to know if the particular item is present in the array or not. It returns ‘true’ if item is present in array or else it will return ‘false’. For Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*_A3z2r0Kvuty7arAuS2v0Q.png" /><figcaption>Example of ‘includes’</figcaption></figure><p><strong>indexOf: </strong>This array method is mainly used to know the index of particular item from the array. For Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*WfA_rRnx7ibcsRLKm28yJA.png" /><figcaption>Example of ‘indexOf’</figcaption></figure><p>Few people use ‘indexOf’ method to check whether particular element is present in array or not. It is done like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*kozhJSlWcwpeWag5SEPgew.png" /></figure><p>Now, we know, we can use both the methods to check item’s presence in the array. <strong>However, ‘includes’ method is better option than ‘indexOf’ for</strong> <strong>this purpose</strong>. Let’s see how…</p><p><strong>‘includes’ is better than ‘indexOf’:</strong></p><ol><li>In case of ‘indexOf’, first its finding index of item and then comparing it with -1, so basically performing two operations. However, for includes, its only checking if the element is present or not, no additional comparison is required.</li><li>This second case is for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining">optional chaining</a>. Let’s understand it with example.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNiiuOyjyZT4_YRcIAiwXw.png" /></figure><p>Will ‘if’ block get executed? No? <br>If you are thinking ‘No, if block won’t be executed’ then it’s wrong.</p><p><strong>How?</strong><br>Note that, numList1 is ‘undefined’, and hence value for ‘numList1?.indexOf?.(10)’ will be returned as ‘undefined’ and expression will evaluate to<br>‘undefined !== -1’ // which is ‘true’ and hence ‘if’ block will be executed</p><p><strong>Solution:<br></strong>To avoid such problem, we should use ‘includes’ method. Let’s see how it work in above mentioned scenario</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxnH2OItsObqab1YRU0bYA.png" /></figure><p>Here, output will be ‘undefined’ which is ‘falsy’ value, and hence ‘if’ block won’t get executed.</p><h3>Conclusion:</h3><p>If you are looking an array method to check if the item exist in array or not then always go for ‘includes’ method.</p><p>Please comment below your thoughts or give claps if you agree ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=994e62116bd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling Error/Rejection with async…await]]></title>
            <link>https://medium.com/@akshayshekokar/handling-error-rejection-with-async-await-ccc9d40058be?source=rss-ec9253e0693f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccc9d40058be</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[rejection]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Akshay Shekokar]]></dc:creator>
            <pubDate>Sun, 16 Aug 2020 09:26:51 GMT</pubDate>
            <atom:updated>2020-08-16T09:26:51.447Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Brief about Async Await:<br></strong>This is the new feature added to Javascript. It made asynchronous programming much easier to understand and write code.</p><p>Suppose, we have to make any asynchronous function to work in synchronous manner. Then simply add async keyword before the definition and use await keyword before calling the function, and then your method executes synchronously.</p><p>Lets see this step by step and then we will move to the part of handling error/rejection with async...await</p><p>We have a Greet function which returns PromiseThis Promise will be resolved after 1 sec. We are expecting the output like this:<br>Execution Started<br>Welcome<br>Exceution Ended</p><p>Lets execute the below program:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*WpITstFSmFV-GJ6QeLcBLw.png" /></figure><p>Output is not what we expected. So let’s refactor it using async...await</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oAgUaiTGc8Yy9H61pqzuFg.png" /></figure><p><strong>Handling Error with Async…await:</strong></p><p>Now, lets come to our original concept, what if we get error/rejection from our promise. For ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWy7_LuHN7NirrP65zaF4w.png" /></figure><p>It’s obvious that we think of using try... catch like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOCUpvgGuvaeIR9TFJ3hig.png" /></figure><p>But what if we have multiple await statement It is not good thing to add try..catch for each and every statement, and if we think of wrapping all the await statement in single try...catch then our catch block will become more generic and if any await statement fails then nothing will get execute from that block.</p><p><strong>catch comes to the rescue:</strong></p><p>If we look properly at await statement. The statement after await keyword is nothing but the promise. And if you remember methods of promise then you must be aware of its catch function.</p><p>We can make use of this function to handle errors/rejection from promise like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bS6pe0jxTuF9t3DNvbswJw.png" /></figure><p>I hope it will help you in your projects while working with async…await.</p><p>Let me know your doubts/question in comments. I will be happy to address them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccc9d40058be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fibonacci Series with Iterators]]></title>
            <link>https://medium.com/@akshayshekokar/fibonacci-series-with-iterators-90a8b3dd0d92?source=rss-ec9253e0693f------2</link>
            <guid isPermaLink="false">https://medium.com/p/90a8b3dd0d92</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[iterators]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Akshay Shekokar]]></dc:creator>
            <pubDate>Fri, 28 Feb 2020 12:55:59 GMT</pubDate>
            <atom:updated>2020-02-28T12:55:59.072Z</atom:updated>
            <content:encoded><![CDATA[<p>Before learning to create Fibonacci series with Iterators, it is important to know Iterators and how we can make any object Iterable.</p><p>Processing each of the items in a collection is a very common operation. JavaScript provides a number of ways of iterating over a collection, from simple <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for">for</a> loops to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map">map()</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">filter()</a>.</p><p>Iterators and Generators bring the concept of iteration directly into the core language and provide a mechanism for customizing the behavior of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a> loops.(More about Basics of Iterators: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators</a>)</p><p>Not all the objects are Iterables. To make any objects Iterable, we need to take care of below things</p><ol><li>The object is called as Iterable only if, it does have Iterator method defined in it. <br>To add Iterator method, add it using Symbol like [Symbol.iterator] It does add <strong>@@iterator </strong>method to your object</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*jWkhPjuGnauFpa2M4QClHw.png" /></figure><p>2. Your <strong>@@iterator</strong> method should return a object, with method next defined in it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*7q4htW_s-RWHAM3WHDw80A.png" /></figure><p>3. next method should return an object with field value and done. value is the actual value that you will get in your for...of loop or in spread operator. done is the Boolean value which tells when to stop your loop.</p><p>If value of done is true then loop will stop its iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*BA-QRqc_d1GT3bcikVMyIA.png" /></figure><p>By following above steps, you will be able to make any object as Iterable.</p><h3>Fibonacci Series:</h3><p>Lets see few implementation of Fibonacci Series with Iterators</p><h4>First Approach:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*qozj1VXqnQaeVEciSIb8-w.png" /></figure><h4>Second Approach:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*lwyxxsO01nLedL23-i5amQ.png" /></figure><p>You can pick any approach or implement your own. At the end its just your logic. Only important thing here is to create Iterable.</p><p>Let me know if you have any question over it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90a8b3dd0d92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS: Function Currying Interview Questions]]></title>
            <link>https://medium.com/@akshayshekokar/js-function-currying-interview-questions-5b552929f91a?source=rss-ec9253e0693f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b552929f91a</guid>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Akshay Shekokar]]></dc:creator>
            <pubDate>Sat, 08 Feb 2020 06:07:47 GMT</pubDate>
            <atom:updated>2020-02-08T06:07:47.600Z</atom:updated>
            <content:encoded><![CDATA[<p>JS: We are aware of function currying and commonly asked interview question like sum(2)(3). Almost everyone knows the answer.</p><p>However, if we modify the question a bit, people find it difficult to answer.<br>Such questions:<br>1. add(2)(3)…(n)<br>2. add(2)(3)…(n)()<br>3. add(2,3)(4) / add(2)(3,5)<br>4. add(2)(3,5)(4,5,6)….(n+..+m)</p><p>Answer for such questions:<br>1. add(2)(3)…(n)</p><p>const add = (num1) =&gt; {<br> let sum = num1;<br> const fun = (num2) =&gt; {<br> sum += num2;<br> return fun<br> } <br> fun.valueOf = () =&gt; sum<br> return fun;<br>}</p><p>console.log(+add(1)(2)(3));</p><p>2. add(2)(3)…(n)()</p><p>const add = (num1) =&gt; {<br> let sum = num1;<br> const fun = (num2) =&gt; {<br> if(num2 === undefined)<br> return sum;<br> <br> sum += num2;<br> return fun<br> } <br> return fun;<br>}<br>console.log(add(1)(2)(3)());</p><p>3. add(2)(3,5)(4,5,6)….(n+..+m)</p><p>const add = (…num1) =&gt; {<br> const getSum = (num) =&gt; num.reduce((a, n)=&gt; a + n);<br> let sum = getSum(num1);<br> const fun = (…num2) =&gt; {<br> sum += getSum(num2);<br> return fun<br> } <br> fun.valueOf = () =&gt; sum<br> return fun;<br>}</p><p>console.log(+add(1)(2,3)(3,4,5));</p><p>Let me know your thoughts or questions on it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b552929f91a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>