<?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 Aliajam on Medium]]></title>
        <description><![CDATA[Stories by Aliajam on Medium]]></description>
        <link>https://medium.com/@aliajam?source=rss-c015c4bf25ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xjEUUrQPOrlT0xHp</url>
            <title>Stories by Aliajam on Medium</title>
            <link>https://medium.com/@aliajam?source=rss-c015c4bf25ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 13:22:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliajam/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[Concurrency In JavaScript]]></title>
            <link>https://medium.com/@aliajam/concurrency-in-javascript-9267227ca76b?source=rss-c015c4bf25ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/9267227ca76b</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aliajam]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 03:21:28 GMT</pubDate>
            <atom:updated>2020-03-06T03:21:28.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dEjygP60rrqHtG4JvYbOyw.jpeg" /></figure><p><strong>Javascript </strong>is a single threaded language. This means it has one call stack and one memory heap. As expected, it executes code in order and must finish executing a piece code before moving onto the next. So how does concurrency work in javascript without blocking other functions from executing? before we answer to this question let’s make sure you know the difference between <strong>concurrency</strong> and <strong>parallelism</strong>, a related but quite distinct concept.</p><ul><li><strong>Concurrency</strong> refers to things happening in some unspecified order. Multitasking — executing multiple programs by interleaving instructions via time slicing — is a good way to think about this sense of concurrency.</li><li><strong>Parallelism</strong> (or “true” parallelism) refers to things happening at literally the same time. This requires hardware support (coprocessors, multi-core processors, networked machines, etc.). All parallelism is concurrent, but not all concurrency is parallel.</li></ul><p>So, how do we implement concurrency tasks? Well, there are typically 2 ways, to tackle this:</p><ul><li><strong>blocking</strong> (synchronous). This pattern heavily relies on multithreading as it needs to continue to serve user requests independently if one of the threads in the list is blocked or not. The blocking style basically stops the execution of a thread and waits for the task to be completed before moving on with that thread. <strong>PHP</strong>, <strong>Ruby</strong> and most server-side technologies implement this approach. Since everything is done sequentially, code written following this pattern is readable and also easier to be implemented and maintained.</li><li><strong>non-blocking </strong>(event loop). This style relies on a single thread — everything runs in that one thread — which means we cannot block the thread, otherwise the program would stale until the thread is unblocked. This pattern is especially good because we get very high concurrency with low memory consumption. It is also very good for user experiences, as there is always a continuous flow in the application. Thus, that’s why it’s the pattern style adopted by browsers and of course, by JavaScript.</li></ul><p>Let’s explain non-blocking (<strong>JavaScript way</strong>) by using an example, imagine you need to show user details in their profile which includes DOB, location, age but you saved these data in different branches of your database, so you need to send multiple HTTP requests to fetch all the data you need (this is not how you usually save data in database but trying to make a point).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEL7uchh8wl4_uC493sRhw.png" /></figure><p>Let’s see why we are only getting location and age but not dob.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*jjy32PxuQf3bCy5NKsmVig.png" /></figure><p>Although they run sequentially but that doesn&#39;t mean we get the data before we run the next function. In order to fix this, we need to understand <strong>await/async</strong> and <strong>promise.all</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wPp1KVi4OVe9K5gUlxeWfw.png" /></figure><p>The word <strong>async</strong> before a function means a function always returns a promise. Other values are wrapped in a resolved promise automatically.</p><p>The keyword <strong>await</strong> makes JavaScript wait until that promise settles and returns its result.</p><p>When we need to wait for multiple promises, we can wrap them in <strong>Promise.all </strong>and then await.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9267227ca76b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Array Functions]]></title>
            <link>https://medium.com/@aliajam/javascript-array-functions-655b4535fe54?source=rss-c015c4bf25ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/655b4535fe54</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[array-methods]]></category>
            <dc:creator><![CDATA[Aliajam]]></dc:creator>
            <pubDate>Sun, 01 Mar 2020 23:07:44 GMT</pubDate>
            <atom:updated>2020-03-01T23:07:44.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dEjygP60rrqHtG4JvYbOyw.jpeg" /></figure><p>Learn how to use <strong>map</strong>, <strong>filter</strong>, <strong>reduce,</strong> <strong>some</strong>, <strong>every</strong>, <strong>sort</strong>, and<strong> splice</strong> in JavaScript.</p><h3>Map</h3><p>The map() method is used for creating a new array with the same length from an existing one, applying a function to each one of the elements of the first array.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*-fMqmbj12VL5g9m35nI8eA.png" /></figure><h3>Filter</h3><p>The filter() method takes each element in an array and it applies a conditional statement against it. If this conditional returns true, the element gets pushed to the output array. If the condition returns false, the element does not get pushed to the output array.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*qlNxwb0pJWK7YEclOFgzfg.png" /></figure><h3>Reduce</h3><p>The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7E97s2SzYfBpLHzMwhgUYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mv5tM-oAof6qlW6IBYBT8w.png" /></figure><h3>Sort</h3><p>The sort() method sorts the elements of an array in place and returns the sorted array.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*VOSrXZQL1PnB9Xs0Y1oFUA.png" /></figure><h3>Some</h3><p>The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*SSuWIkhpEdbyZ6Rzrkz9Ew.png" /></figure><h3>Every</h3><p>The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*FHFRvC2ZroRikhbPvvR7xw.png" /></figure><h3>Splice</h3><p>The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.</p><h3>Syntax</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*u3gHtPaLb4O1SgbwBFjowA.png" /></figure><p>The index at which to start changing the array.</p><p>deleteCount is an integer indicating the number of elements in the array to remove from start. If 0 will insert new element to the array</p><h3>Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*YxqqCblsJeFZqL-UqOlhvQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=655b4535fe54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript for loops]]></title>
            <link>https://medium.com/@aliajam/javascript-for-loops-4f2a48d600f9?source=rss-c015c4bf25ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f2a48d600f9</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aliajam]]></dc:creator>
            <pubDate>Fri, 28 Feb 2020 03:06:48 GMT</pubDate>
            <atom:updated>2020-02-28T03:06:48.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vzosTRnbhI2GmFD1zDZU0Q.jpeg" /></figure><p>JavaScript supports different kinds of loops which I’ll explain in this article, and we will also analyze which one is faster and how they work.</p><ol><li><strong>Traditional</strong> for loop:</li></ol><figure><img alt="javascript loops" src="https://cdn-images-1.medium.com/max/914/1*7RwEitNLWBlRQvrW_4DHxQ.png" /></figure><p>set a variable before the loop starts (i = 0).</p><p>define the condition for the loop to run (i must be less than the length of the array).</p><p>Increases a value (i++) each time the code block in the loop has been executed.</p><p>It takes 4.194ms to run this loop on my computer. If instead of arr.length we pass the array directly it will run 1 ms faster</p><p>the reason is in i &lt; arr.length checks in every loop if i is smaller than the <strong>length</strong> of arr</p><p>but in i &lt; arr every loop cycle checks if arr at <strong>position</strong> i is truthy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*cuaeytJS_9sscsCbyS5Oyg.png" /></figure><p>Now let’s check other for loops and see which one is faster.</p><p>2.<strong> for/of </strong>loops through the values of an iterable object.</p><p>For/of lets you loop over data structures that are iterable such as Arrays, Strings, Maps, NodeLists, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*se5HBpjowmqs3KWAk1_fzA.png" /></figure><p>As you can see, for/of loop is almost 8 times slower than other forms of loops.</p><p><strong>ForEach</strong>: forEach() calls a provided callback function once for each element in an array in ascending order. It is not invoked for index properties that have been deleted or are uninitialized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*PtN8t9IQei8YZcBgd_C3gA.png" /></figure><p>2.958ms which has way better performance over other loops.</p><p><strong>Loops over objects: </strong>Objects are not iterable unless they implement the iterable protocol. Therefore, you cannot use for…of to iterate over the properties of an object. Instead, you have to use Object.keys or Object.entries, to iterate over the properties or entries of an object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PW6Q7LhyAXIQoKPoPgQdBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWsAxK3v20s_Ha_3Nb6AKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*FcX5gkDTPyFXi2mitK4dDw.png" /></figure><p>Another option for this use case might be to use a <strong>Map</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VMLS5efZLijhRqDYj2PdhQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f2a48d600f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>