<?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 Taha Jiruwala on Medium]]></title>
        <description><![CDATA[Stories by Taha Jiruwala on Medium]]></description>
        <link>https://medium.com/@tahajiru?source=rss-f2ea3479622b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lTEShtYgiuWvctsIcJuyfw.jpeg</url>
            <title>Stories by Taha Jiruwala on Medium</title>
            <link>https://medium.com/@tahajiru?source=rss-f2ea3479622b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 08:54:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tahajiru/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[Deep vs Shallow Copy in JavaScript]]></title>
            <link>https://medium.com/@tahajiru/deep-vs-shallow-copy-in-javascript-8f0a840a8654?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f0a840a8654</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Mon, 27 Jan 2025 04:49:42 GMT</pubDate>
            <atom:updated>2025-01-27T04:49:42.125Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/serious-female-office-worker-using-printer-in-workplace-3831873/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6r6fzSiBodpsr9AjR88lHA.png" /></a></figure><p>In JavaScript, when you’re dealing with objects and arrays, copying them isn’t as straightforward as with primitive types like strings or numbers.</p><p>Understanding deep and shallow copying will help you in scenarios where you need to duplicate objects or arrays without altering the original data unintentionally.</p><h3>Shallow Copy</h3><p>A shallow copy creates a new object or array and copies the references of the original elements.</p><p>This means that the new object or array holds references to the same underlying elements as the original one.</p><p>If the elements are primitive types, a shallow copy is sufficient because changes made to the copied elements won’t affect the original ones. However, if the elements are objects or arrays themselves, modifying them within the copied structure will reflect in the original structure as well.</p><p>For example</p><pre>const originalArray = [[1], [2], [3]];<br>const shallowCopy = [...originalArray];<br>shallowCopy[0].push(4);<br><br>console.log(originalArray); // Output: [[1, 4], [2], [3]]</pre><p>In JavaScript, you can create a shallow copy using various methods:</p><h3>1. Spread syntax (…)</h3><pre>const originalArray = [1, 2, 3];<br>const shallowCopy = [...originalArray];</pre><h3>2. Array.slice() method:</h3><pre>const originalArray = [1, 2, 3];<br>const shallowCopy = originalArray.slice();</pre><h3>3. Object.assign() (for objects):</h3><pre>const originalObj = { a: 1, b: 2 };<br>const shallowCopy = Object.assign({}, originalObj);</pre><h3>Deep Copy</h3><p>A deep copy, on the other hand, creates a completely new object or array and recursively copies all the elements within it.</p><p>This means that the new object or array and all its nested elements are independent of the original structure. Changes made to the copied structure won’t affect the original one, and vice versa.</p><p>For example</p><pre>const originalArray = [[1], [2], [3]];<br>const deepCopiedArray = deepCopy(originalArray);<br>deepCopiedArray[0].push(4);<br><br>console.log(originalArray); // Output: [[1], [2], [3]]</pre><p>Deep copying is more complex and typically requires custom logic, especially when dealing with nested objects or arrays. You can achieve deep copying using various techniques:</p><h3>1. Recursion</h3><pre>function deepCopy(obj) {<br>  if (typeof obj !== &quot;object&quot; || obj === null) {<br>    return obj;<br>  }<br>  let copy = Array.isArray(obj) ? [] : {};<br>  for (let key in obj) {<br>    if (obj.hasOwnProperty(key)) {<br>      copy[key] = deepCopy(obj[key]);<br>    }<br>  }<br>  return copy;<br>}</pre><h3>2. Using libraries like lodash</h3><pre>const lodash = require(&quot;lodash&quot;);<br>const originalArray = [{ a: 1 }, { b: 2 }];<br>const deepCopy = lodash.cloneDeep(originalArray);</pre><figure><a href="https://tahajiru.com/resources/higher-order-functions"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3E0zTRUUyoV9TONUhTCFg.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/deep-vs-shallow-copy-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f0a840a8654" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Can You Determine if Something Is a Deep Copy in JavaScript?]]></title>
            <link>https://medium.com/@tahajiru/how-can-you-determine-if-something-is-a-deep-copy-in-javascript-ba23541f97dd?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba23541f97dd</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 14:16:44 GMT</pubDate>
            <atom:updated>2025-01-24T14:16:44.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/sparrow-making-nest-885537/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_E0iblcIfrWcaQ-TZ7MzTQ.png" /></a></figure><p>Shallow copies only duplicate the top-level structure of an object, while deep copies create new instances of all nested objects and their properties.</p><p>By comparing the references of the nested objects (<strong>orig.nested === shallowCopy.nested</strong> and <strong>orig.nested === deepCopy.nested</strong>), we can determine whether a shallow or deep copy has been made.</p><pre>const orig = {<br>  nested: {<br>    value: 1,<br>  },<br>};<br><br>const shallowCopy = { ...orig };<br>const deepCopy = {<br>  ...orig,<br>  nested: { ...orig.nested },<br>};<br><br>console.log(orig.nested === shallowCopy.nested); // true - not a deep copy<br>console.log(orig.nested === deepCopy.nested); // false - deep copy created</pre><figure><a href="https://tahajiru.com/resources/promises"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXzPysFWKdmE54z3BqefdA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba23541f97dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Script Tag Positioning: Common Mistakes and How to Fix Them]]></title>
            <link>https://javascript.plainenglish.io/script-tag-positioning-common-mistakes-and-how-to-fix-them-562da6427137?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/562da6427137</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Sun, 19 Jan 2025 10:59:32 GMT</pubDate>
            <atom:updated>2025-01-20T05:53:10.448Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/woman-in-gray-long-sleeve-shirt-holding-brown-cardboard-on-wall-7218088/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bCxM4Qmq4WVgoAzDRyqGMA.png" /></a></figure><p>Suppose you are creating a webpage where you increment a number displayed on the screen by pressing a button.</p><p>You wrote the following code, but it doesn’t work — nothing happens when you press the button:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;Counter&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;index.css&quot; /&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;script src=&quot;index.js&quot;&gt;&lt;/script&gt;<br>    &lt;h1 id=&quot;counter&quot;&gt;&lt;/h1&gt;<br>    &lt;button onclick=&quot;increment()&quot;&gt;Increment&lt;/button&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>let count = 0;<br>let countEl = document.getElementById(&quot;counter&quot;);<br>function increment() {<br>  count += 1;<br>  countEl.innerText = count;<br>}</pre><p>However, when you change the countEl.innerText line to use the counter ID directly, as shown below, the code works:</p><pre>let count = 0;<br>let countEl = document.getElementById(&quot;counter&quot;);<br>function increment() {<br>  count += 1;<br>  counter.innerText = count; // Using &#39;counter&#39; directly<br>}</pre><h3>Can you spot the issue?</h3><p>The problem lies in the timing of when the script executes relative to when the DOM elements are created.</p><p>In the first version of the code, the &lt;script&gt; tag is placed <em>before</em> the &lt;h1&gt; element it tries to access.</p><p>When the script runs, it immediately attempts to find the element with the ID counter. At that point, the element hasn&#39;t been created yet, so document.getElementById(&quot;counter&quot;) returns null, and countEl remains null forever.</p><p>As a result, the increment function fails to update anything on the screen.</p><p>In the second version of the code, it works because the id=&quot;counter&quot; attribute creates a property on the window object with the same name ( window.counter).</p><p>This property is available even if the element doesn’t exist when the script executes. However, relying on this behaviour is considered bad practice and should be avoided.</p><p>To fix the issue properly, you should ensure the script runs only after the DOM is fully loaded. There are a few ways to do this:</p><ol><li><strong>Move the </strong><strong>&lt;script&gt; tag to the end of the </strong><strong>&lt;body&gt;</strong></li></ol><p>This ensures the script runs after all elements have been created.</p><p>2. <strong>Use the </strong><strong>defer attribute</strong> in the &lt;script&gt; tag:</p><pre>&lt;script src=&quot;index.js&quot; defer&gt;&lt;/script&gt;</pre><p>This tells the browser to wait until the entire HTML document is parsed before running the script.</p><p><strong>3. Add </strong><strong>type=&quot;module&quot; to the </strong><strong>&lt;script&gt; tag</strong>:</p><pre>&lt;script src=&quot;index.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;</pre><p>Using type=&quot;module&quot; not only treats the script as a module (which is recommended for modern JavaScript), but also defers its execution until the DOM is fully loaded.</p><p>Always ensure your JavaScript runs after the DOM is fully loaded to avoid issues like trying to access elements that don’t yet exist. Avoid relying on window properties created for id attributes, as this behaviour is unpredictable and can cause conflicts.</p><figure><a href="https://tahajiru.com/problems"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-WDMIozUNv3o0_MMLO91FQ.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/script-tag-positioning-common-mistakes-and-how-to-fix-them"><em>https://tahajiru.com</em></a><em>.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=562da6427137" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/script-tag-positioning-common-mistakes-and-how-to-fix-them-562da6427137">Script Tag Positioning: Common Mistakes and How to Fix Them</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Does JavaScript Support Dictionaries?]]></title>
            <link>https://javascript.plainenglish.io/does-javascript-support-dictionaries-5b4a00a2aa98?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b4a00a2aa98</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Thu, 16 Jan 2025 11:35:29 GMT</pubDate>
            <atom:updated>2025-01-20T05:48:46.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/a-girl-using-smartphone-in-the-classroom-8419515/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWPP4GNr3jXyvC0rtcgHWg.png" /></a></figure><p>Yes, JavaScript supports dictionaries, and you can use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a> to implement them effectively.</p><p>While Object was historically used to implement dictionaries due to their ability to associate keys with values, Map offer several advantages over Object when used as dictionaries:</p><ul><li><strong>Accidental Keys</strong>: A Map starts empty and only contains explicitly added key-value pairs. In contrast, Object have a prototype chain, potentially leading to accidental key collisions with inherited properties.</li><li><strong>Security</strong>: Map provide a safer option for handling user-provided keys and values, as they don&#39;t risk prototype pollution. Object may allow attackers to override prototypes, leading to security vulnerabilities.</li><li><strong>Key Types</strong>: Map accept any value as a key, including functions, objects, or primitives, while Object only allow strings or symbols as keys.</li><li><strong>Key Order</strong>: Map keys maintain the order of insertion, ensuring straightforward iteration. Though Object keys have become ordered in recent JavaScript versions, it&#39;s still best practice not to rely on this behaviour due to historical inconsistencies.</li><li><strong>Size</strong>: The number of items in a Map can be directly retrieved using its size property, while determining the size of an Object requires more complex and less efficient methods, such as the length of the array returned from Object.keys().</li><li><strong>Iteration</strong>: Map are iterable, meaning you can easily loop over their entries, keys, or values using standard JavaScript iteration methods. Object, on the other hand, don&#39;t natively support iteration, requiring workarounds like extracting keys with Object.keys().</li></ul><p>By using Map instead of Object, you can build dictionaries in JavaScript that are more secure and efficient.</p><figure><a href="https://tahajiru.com/resources/higher-order-functions"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3E0zTRUUyoV9TONUhTCFg.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/javascript-support-dictionaries"><em>https://tahajiru.com</em></a><em>.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b4a00a2aa98" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/does-javascript-support-dictionaries-5b4a00a2aa98">Does JavaScript Support Dictionaries?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Use ‘this’ Instead of the Object Name to Reference the Object’s Properties in JavaScript?]]></title>
            <link>https://medium.com/@tahajiru/why-use-this-instead-of-the-object-name-to-reference-the-object-s-properties-in-javascript-5e609eab1005?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e609eab1005</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Wed, 15 Jan 2025 12:01:50 GMT</pubDate>
            <atom:updated>2025-01-15T12:01:50.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/close-up-photo-of-programming-of-codes-546819/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CcGHJWZiTRDgcWvVw0rxQA.png" /></a></figure><p>When we’re working with objects in JavaScript, using this inside an object allows us to reference its properties.</p><p>But why is it preferred over simply using the object’s name to reference the same property?</p><p>For example, why is it better to write:</p><pre>const person = {<br>  name: &quot;John Doe&quot;,<br>  greet: function () {<br>    console.log(`Hello, my name is ${this.name}`);<br>  },<br>};</pre><p>Verses</p><pre>const person = {<br>  name: &quot;John Doe&quot;,<br>  greet: function () {<br>    console.log(`Hello, my name is ${person.name}`);<br>  },<br>};</pre><p>Here are a few reasons as why using this is preferred:</p><h3>1. Flexibility with Instances</h3><p>When you’re dealing with one-off objects like in the above example, it might seem unnecessary to use this. However, when you&#39;re working with classes or constructors to create multiple instances of objects, the importance of this becomes apparent.</p><p>Take this class-based example.</p><pre>class Person {<br>  constructor(name, age) {<br>    this.name = name;<br>    this.age = age;<br>  }<br>  sayHello() {<br>    console.log(`Hello, my name is ${this.name}!`);<br>  }<br>}<br><br>const stevePerson = new Person(&quot;Steve&quot;, 33);<br>const gregPerson = new Person(&quot;Greg&quot;, 33);<br><br>stevePerson.sayHello(); // Logs &quot;Hello, my name is Steve&quot;<br>gregPerson.sayHello(); // Logs &quot;Hello, my name is Greg&quot;</pre><p>Here, we can create multiple instances of the Person class, each with its unique name property. Inside the sayHello method, we don&#39;t need to worry about which instance is calling the function; this dynamically refers to the calling instance.</p><h3>2. Code Maintainability</h3><p>Using this promotes code that is easier to maintain and refactor.</p><p>If you decide to rename the object in the future, you only need to change it once if you’re using this consistently. In contrast, if you&#39;re directly referencing the object&#39;s name throughout your code, you&#39;ll need to update every instance of it.</p><h3>3. Clarity and Readability</h3><p>Using this enhances the readability of your code. It makes it clear that you&#39;re referring to a property of the current object, improving code comprehension.</p><figure><a href="https://tahajiru.com/resources/higher-order-functions"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3E0zTRUUyoV9TONUhTCFg.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/use-this-reference-object-properties-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e609eab1005" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference Between Named and Default Imports: Which One Should You Use?]]></title>
            <link>https://javascript.plainenglish.io/difference-between-named-and-default-imports-which-one-should-you-use-851fc5a6ae40?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/851fc5a6ae40</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Tue, 14 Jan 2025 15:33:45 GMT</pubDate>
            <atom:updated>2025-01-20T05:46:50.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/person-holding-a-chocolate-bar-and-granola-bar-8844389/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qkpr30L-b4XY_D6BYVEa0g.png" /></a></figure><p>When you have imports in curly braces, it&#39;s known as a <strong>named import</strong>.</p><p>import { speak } from &quot;cow&quot;;</p><p>When you don’t have curly braces and just the name, that&#39;s a <strong>default import</strong>.</p><p>import Cow from &quot;cow&quot;;</p><p>The main benefit with a named import is the exporter decides what its being called. The importer can rename it, but they still have to refer to the exported name in doing so.</p><p>import { speak as cowSpeak } from &quot;cow&quot;;</p><p>With the default export, it&#39;s entirely up to the importer to decide what name to use. The identifier Cow can be anything and there&#39;s nothing to tell you what it was intentionally supposed to be.</p><p>import Human from &quot;cow&quot;;</p><p>Because of this, it’s often recommended to always use named imports and not to use default imports. This adds consistency to your codebase because the same names are being used everywhere. And even if they aren’t due to renaming, there’s still an explicit reference to the original name in the import statement.</p><figure><a href="https://tahajiru.com/resources/async-await"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfhVwluk4JPYzy5qaX6zoQ.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/difference-named-default-imports-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=851fc5a6ae40" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/difference-between-named-and-default-imports-which-one-should-you-use-851fc5a6ae40">Difference Between Named and Default Imports: Which One Should You Use?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</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 Manage CPU-Intensive Tasks in JavaScript]]></title>
            <link>https://medium.com/@tahajiru/how-to-manage-cpu-intensive-tasks-in-javascript-3dc0de615550?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dc0de615550</guid>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Mon, 13 Jan 2025 04:52:28 GMT</pubDate>
            <atom:updated>2025-01-13T04:52:28.268Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/code-projected-over-woman-3861969/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4EcrtthXZuGx4T8nO0m6Q.png" /></a></figure><p>JavaScript is single-threaded, meaning it can execute only one task at a time.</p><p>Promises and async/await do enable JavaScript to execute asynchronous tasks, but they don&#39;t make JavaScript <em>multi-threaded</em>. Instead, they allow JavaScript to handle non-blocking operations without pausing the main thread.</p><p>It’s like a restaurant with a single cook — the chef can manage multiple dishes on the stove, in the oven, and in the microwave simultaneously, but when it comes to actively preparing ingredients or plating food, they can handle only one dish at a time.</p><p>This approach works particularly well for I/O or networking tasks, like fetching data from an API or reading files, where most of the waiting happens in external systems outside JavaScript itself.</p><p>But what happens when you have computation-heavy tasks-like processing a massive array or performing complex mathematical operations — that hog the CPU for a significant amount of time (1–2 minutes, for instance)?</p><p>For such CPU-intensive tasks, a single-threaded approach can become a bottleneck because the JavaScript engine is confined to executing one task at a time.</p><p>To handle such workloads efficiently, we need a way to offload tasks to multiple threads or CPU cores, allowing the load to be divided and processed concurrently.</p><p>Can JavaScript handle this kind of parallelism?</p><p>This can be addressed by using <strong>Web Workers</strong> (in browsers) or <strong>Worker Threads</strong> (in Node.js). These workers operate as separate threads that execute your CPU-intensive tasks in parallel, independent of the main thread.</p><p>This approach prevents your application from freezing or becoming unresponsive, as the main thread remains free to handle user interactions, rendering, or other tasks while the workers perform their computations.</p><p>By identifying tasks that are heavy on the CPU and offloading them to Workers, you can make your application faster and more responsive.</p><figure><a href="https://tahajiru.com/resources/promises"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXzPysFWKdmE54z3BqefdA.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/how-to-manage-cpu-intensive-tasks-in-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dc0de615550" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Do You Know If There’s a Built-In Method Instead of Writing Logic Yourself?]]></title>
            <link>https://medium.com/@tahajiru/how-do-you-know-if-theres-a-built-in-method-instead-of-writing-logic-yourself-9dc343ba5af8?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dc343ba5af8</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Sun, 12 Jan 2025 04:11:34 GMT</pubDate>
            <atom:updated>2025-01-12T04:11:34.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/unrecognizable-hacker-with-smartphone-typing-on-laptop-at-desk-5935791/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5qQiFDYt5DN7EJR-UvStA.png" /></a></figure><p>Consider a scenario where you have an array of numbers, and you need to determine if a specific number exists within that array. A common approach might be to write a loop that iterates over the array, checking each element against the target value.</p><pre>let numbers = [1, 2, 3, 4, 5];<br>let target = 3;<br>let found = false;<br><br>for (let i = 0; i &lt; numbers.length; i++) {<br>  if (numbers[i] === target) {<br>    found = true;<br>    break;<br>  }<br>}<br><br>console.log(found); // Outputs: true</pre><p>While this code is functional, it’s somewhat verbose. We could have used a built-in method called includes() that checks if an array contains a specific value. This method abstracts away the need for a loop, providing a more concise and readable solution:</p><pre>let numbers = [1, 2, 3, 4, 5];<br>let target = 3;<br><br>console.log(numbers.includes(target)); // Outputs: true</pre><p>The includes() method is not only simpler and easier to read, but it&#39;s also likely more efficient, as it&#39;s optimized by the JavaScript engine.</p><h3>How to discover if there exists a built-in method for your task?</h3><p>Here are some strategies that I use to figure out if a Built-in Method exists-</p><h3>1. Read the documentation</h3><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">MDN Web Docs</a> is an excellent resource for learning about JavaScript’s built-in methods. It provides comprehensive documentation on the language’s features, including methods, operators, statements, and more.</p><h3>2. Use an IDE with IntelliSense</h3><p>IDEs like Visual Studio Code offer IntelliSense, a feature that provides smart completions based on variable types, function definitions, and imported modules.</p><p>As you type, IntelliSense suggests methods and properties, helping you discover built-in methods you might not be aware of.</p><h3>3. Search online</h3><p>If you’re trying to accomplish a specific task, a quick online search can often lead you to a built-in method that fits your needs.</p><p>Websites like Stack Overflow are filled with questions and answers from other developers, providing a wealth of information on best practices and efficient solutions.</p><p>While it’s possible to write custom logic for most tasks, in many cases, built-in methods can make your code cleaner, simpler, and more efficient. So, before you start writing your code, take a moment to check if there’s a built-in method that could do the job for you. Your future self (and anyone else reading your code) will thank you.</p><figure><a href="https://tahajiru.com/resources/promises"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXzPysFWKdmE54z3BqefdA.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/know-built-in-method-instead-writing-logic-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dc343ba5af8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Why a Loop Might Freeze Your Browser]]></title>
            <link>https://javascript.plainenglish.io/understanding-why-a-loop-might-freeze-your-browser-b997fdadf335?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b997fdadf335</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Sat, 11 Jan 2025 05:36:18 GMT</pubDate>
            <atom:updated>2025-01-13T08:02:57.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/selective-focus-of-frozen-tree-twigs-436792/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WuJV4_6WcFale3aFnH1BLg.png" /></a></figure><p>While working with JavaScript, you might have encountered a situation where a loop causes your browser to freeze. This is a frustrating experience, especially if you’re not sure why it’s happening.</p><p>Let’s try to understand why this happens.</p><h3>The Infinite Loop</h3><p>The most common reason for a loop to freeze a browser is an infinite loop. An infinite loop occurs when the loop’s condition never becomes false, causing the loop to run indefinitely. Here’s an example:</p><pre>for (let i = 0; i &gt;= 0; i++) {<br>  console.log(i);<br>}</pre><p>In this example, the condition i &gt;= 0 will always be true because i is always increasing. This creates an infinite loop that will run forever, causing the browser to freeze.</p><p>JavaScript is a single-threaded language, which means it can only do one thing at a time. When a loop runs indefinitely, it monopolizes the JavaScript engine, preventing it from doing anything else. This includes updating the browser’s user interface, which is why the browser appears to freeze.</p><h3>Preventing Infinite Loops</h3><p>To prevent infinite loops, you need to ensure that the loop’s condition will eventually become false. This usually involves updating a variable within the loop so that it will eventually satisfy the exit condition. Here’s a corrected version of the previous example:</p><pre>for (let i = 0; i &lt; 10; i++) {<br>  console.log(i);<br>}</pre><p>In this example, i increases with each iteration of the loop. Once i reaches 10, the condition i &lt; 10 becomes false, and the loop stops running.</p><p>Another way to prevent infinite loops is to use a break statement. A break statement immediately exits the loop, regardless of the loop&#39;s condition. Here&#39;s an example:</p><pre>for (let i = 0; ; i++) {<br>  console.log(i);<br><br>  if (i &gt;= 10) {<br>    break;<br>  }<br>}</pre><p>In this example, the loop’s condition is always true, creating a potential infinite loop. However, the if statement inside the loop checks if i is greater than or equal to 10. If it is, the break statement is executed, and the loop is immediately exited.</p><p>Understanding how loops work and ensuring that your loops have a valid exit condition, you can prevent infinite loops and keep your browser running smoothly.</p><figure><a href="https://tahajiru.com/resources/async-await"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfhVwluk4JPYzy5qaX6zoQ.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/understanding-loop-freeze-browser"><em>https://tahajiru.com</em></a><em>.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b997fdadf335" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/understanding-why-a-loop-might-freeze-your-browser-b997fdadf335">Understanding Why a Loop Might Freeze Your Browser</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Purpose of Array.of in JavaScript]]></title>
            <link>https://javascript.plainenglish.io/understanding-the-purpose-of-array-of-in-javascript-dd763d1eaca3?source=rss-f2ea3479622b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd763d1eaca3</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Taha Jiruwala]]></dc:creator>
            <pubDate>Fri, 10 Jan 2025 15:26:03 GMT</pubDate>
            <atom:updated>2025-01-13T07:57:35.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="https://www.pexels.com/photo/colorful-cutouts-of-the-word-purpose-4116640/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TqnR--u5_8GVAZsZNJniog.png" /></a></figure><p>In JavaScript, the Array.of method was introduced as part of the ES6 (ECMAScript 2015) specification. At first glance, it might seem redundant. After all, why use Array.of(1, 2, 3) when you can simply declare and initialize an array like this: [1, 2, 3]?</p><p>The answer lies in a specific quirk of the Array constructor.</p><h3>The Quirk of the Array Constructor</h3><p>In JavaScript, the Array constructor behaves differently based on the number of arguments passed to it. If you pass multiple arguments or a single argument that is not a number, it creates an array with those arguments as elements:</p><pre>let array = new Array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;);<br>console.log(array); // Outputs: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]</pre><p>However, if you pass a single number to the Array constructor, it creates an array with a length equal to that number, and the array is filled with undefined:</p><pre>let array = new Array(3);<br>console.log(array); // Outputs: [undefined, undefined, undefined]</pre><p>This behavior can lead to confusion and bugs in your code.</p><h3>The Consistency of Array.of</h3><p>The Array.of method was introduced to address this quirk. Regardless of the number or type of arguments, Array.of creates a new array instance with the given arguments as elements:</p><pre>let array = Array.of(3);<br>console.log(array); // Outputs: [3]</pre><p>In this case, Array.of(3) creates an array with a single element, 3, which is more intuitive and less error-prone than the Array constructor&#39;s behavior.</p><p>In conclusion, while it’s true that for most use cases, simply declaring and initializing an array with bracket notation ([1, 2, 3]) is simpler and more common, Array.of provides a consistent and less error-prone alternative to the Array constructor when you need to create an array from a dynamic list of arguments.</p><figure><a href="https://tahajiru.com/resources/promises"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXzPysFWKdmE54z3BqefdA.png" /></a></figure><p><em>Originally published at </em><a href="https://tahajiru.com/article/purpose-array-of-javascript"><em>https://tahajiru.com</em></a><em>.</em></p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://cofeed.app/"><strong>Check out CoFeed, the smart way to stay up-to-date with the latest in tech</strong></a> <strong>🧪</strong></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd763d1eaca3" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/understanding-the-purpose-of-array-of-in-javascript-dd763d1eaca3">Understanding the Purpose of Array.of in JavaScript</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>