<?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 Aquib Afzal on Medium]]></title>
        <description><![CDATA[Stories by Aquib Afzal on Medium]]></description>
        <link>https://medium.com/@aquibafzal?source=rss-b34241cd11a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QRBBw_wMzKwrhMBLv3DIyg.jpeg</url>
            <title>Stories by Aquib Afzal on Medium</title>
            <link>https://medium.com/@aquibafzal?source=rss-b34241cd11a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:09:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aquibafzal/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[Mastering Frontend Performance Optimization: A Deep Dive into Lighthouse Metrics (Part 2)]]></title>
            <link>https://javascript.plainenglish.io/mastering-frontend-performance-optimization-a-deep-dive-into-lighthouse-metrics-part-2-bc648166633c?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc648166633c</guid>
            <category><![CDATA[advanced-web-development]]></category>
            <category><![CDATA[metrics-and-analytics]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 08:47:08 GMT</pubDate>
            <atom:updated>2023-08-24T12:47:59.352Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Frontend Performance Optimization: A Deep Dive into Lighthouse Metrics</h3><h4>Part 2</h4><figure><img alt="metrics" src="https://cdn-images-1.medium.com/max/1024/0*uQGnLhGEY3To8y0d" /><figcaption>Photo by <a href="https://unsplash.com/@sebastiaanstam?utm_source=medium&amp;utm_medium=referral">sebastiaan stam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://aquibafzal.medium.com/list/08caa7c990f9">Frontend Performance optimization</a></p><p>In my previous blog <a href="https://aquibafzal.medium.com/mastering-frontend-performance-optimization-test-website-performance-part-1-cad551c1861">Mastering Frontend Performance Optimization: Test website performance (Part 1)</a>, I discussed the importance of Performance Optimization and How to use Google Lighthouse — tools for measuring performance of a website.</p><p>In this blog, we will deep dive into the lighthouse metrics. The performance score is a weighted average of the metrics. Obviously, metrics with more weightage will impact more performance and vice-versa.</p><blockquote>Check <a href="https://googlechrome.github.io/lighthouse/scorecalc/">Lighthouse Scoring Calculator</a></blockquote><h3>Lighthouse Metrics 🎛️</h3><figure><img alt="lighthouse metrics" src="https://cdn-images-1.medium.com/max/966/1*pgiQTy4W-8Mp3BN8WMGXfQ.png" /><figcaption>metrics in chrome v10</figcaption></figure><p>For chrome version 10, these are the five metrics that contribute to the overall performance score —</p><ol><li>First Contentful Paint (FCP) ️️🖌️</li><li>Largest Contentful Paint (LCP) 🖼️</li><li>Total Blocking Time (TBT) ⏳</li><li>Cumulative Layout Shift (CLS) 🎞️</li><li>Speed Index (SI) 🕓</li></ol><h3>First Contentful Paint (FCP) ️️🖌️</h3><ul><li>It measures how quickly a web page shows you the <strong><em>First Important Thing</em></strong> when you load the page.</li><li>The <em>First Important Thing</em> can be <strong><br> — </strong>picture<br> — text <br> — background colour etc <br> — Except component inside <em>iframe</em> appear on your screen.</li></ul><figure><img alt="FCP timeline frame" src="https://cdn-images-1.medium.com/max/765/1*9GHTRNmBbAJzTRKdwDs5kg.png" /><figcaption>FCP timeline frame</figcaption></figure><ul><li>In the above timeline image, FCP happens in the second frame, as it is the frame in which first text and image elements are rendered.</li></ul><h4><strong>Weightage</strong></h4><p><strong>10%</strong> weightage of overall performance score.​</p><h4><strong>Good FCP Score</strong></h4><figure><img alt="good fcp" src="https://cdn-images-1.medium.com/max/855/1*IlMVgc8yhB1pxIxbzqTTlQ.png" /><figcaption>good fcp</figcaption></figure><p>To provide a good user experience, sites should have a First Contentful Paint of <strong>1.8 seconds</strong> or less.</p><blockquote><a href="https://web.dev/fcp/">fcp reference</a></blockquote><h3>Largest Contentful Paint (LCP) 🖼️</h3><ul><li>The Largest Contentful Paint (LCP) metric reports the loading speed of <em>the largest and most important element</em> in a viewport. This indicates the time it takes for that element to become visible to the user.</li><li><em>The largest and most important element</em> is determined on the basis of <strong>size</strong>, <strong>visibility</strong>, and <strong>significance</strong>. <br>Example — hero images, large text blocks, or prominent sections.</li></ul><figure><img alt="lcp example" src="https://cdn-images-1.medium.com/max/1024/1*bAaAHbpgm8Q8VPqr_mRxpw.png" /><figcaption>lcp example</figcaption></figure><ul><li>In the first timeline, the Largest Contentful Paint (LCP) undergoes a transformation from text to an image. Within this timeline, the segment highlighted in green represents the evolving LCP, which dynamically changes during the page loading process. Initially, a small text resided within the green box; subsequently, a heading with a larger font loaded, superseding the text as the LCP. Finally, the largest and most visually significant element, a banner image, loaded and took over as the ultimate LCP.<br>In the second timeline, Instagram logo is not highlighted for the initial LCP as it is svg. Svg is not considered LCP.</li></ul><h4><strong>Weightage</strong></h4><p><strong>25%</strong> weightage of overall performance score.​</p><h4><strong>Good LCP Score</strong></h4><figure><img alt="c" src="https://cdn-images-1.medium.com/max/594/1*N5CAB9dhV7HnYTuwJfLOVA.png" /><figcaption>Good LCP</figcaption></figure><p>To provide a good user experience, sites should have the Largest Contentful Paint of <strong>2.5 seconds</strong> or less.</p><blockquote><a href="https://web.dev/lcp/">lcp reference</a></blockquote><h3>Total Blocking Time (TBT) ⏳</h3><figure><img alt="unresponsive" src="https://cdn-images-1.medium.com/max/1024/0*xIamHy_xXzL1lm4k" /></figure><ul><li>The Total Blocking Time (TBT) metric serves as a crucial indicator of a web page’s responsiveness during its loading phase.It measures the duration for which the page remains <em>unresponsive to user interactions</em>, encompassing clicks, scrolls, and various other events.</li><li>Unresponsiveness is due to the fact that the main thread is hindered by extensive tasks, commonly known as “<strong>long tasks</strong>.” A long task is defined as any task demanding more than 50 milliseconds to complete. The TBT metric is derived from the cumulative blocking time incurred by each of these long tasks.</li></ul><h4>Let’s calculate TBT</h4><figure><img alt="task duration" src="https://cdn-images-1.medium.com/max/990/1*qAD70lArBAV7u6se36m5GA.png" /><figcaption>task timing</figcaption></figure><p>The above image has five tasks, three of which are Long Tasks as their duration exceeds 50 ms. So the <strong>total task time</strong> is the sum of all the task time which is <strong>560 ms</strong>.</p><figure><img alt="task blocking time" src="https://cdn-images-1.medium.com/max/1011/1*P5B4TgBEbZk8JIUveVcuDw.png" /><figcaption>task blocking time</figcaption></figure><p>The first task consumes a total of 250 ms, out of which 200 ms is designated as blocking time. This identical calculation goes for the second and fifth tasks. But for the third and fourth tasks, they don’t have any blocking time because they finish in less than 50 ms. So, when we add up all these blocking times, it sums up to <strong>345 ms</strong> which is <strong>Total Blocking Time (TBT)</strong>.</p><h4>Weightage</h4><p><strong>30%</strong> weightage of overall performance score.​</p><h4>Good TBT Score</h4><figure><img alt="good tbt score" src="https://cdn-images-1.medium.com/max/923/1*ksNeF8PKkuppjFcJGq9bjg.png" /><figcaption>Good TBT</figcaption></figure><p>To provide a good user experience, sites should have the Total Blocking Time of <strong>200 miliseconds</strong> or less.</p><blockquote><a href="https://web.dev/tbt/">tbt reference</a></blockquote><h3>Cumulative Layout Shift (CLS) 🎞️</h3><figure><img alt="cls" src="https://cdn-images-1.medium.com/max/1024/0*qH7D50og4P2zaoPf.jpg" /></figure><blockquote><a href="https://storage.googleapis.com/web-dev-assets/layout-instability-api/layout-instability2.webm">Imagine this scenario</a>: you’re just about to click the ‘Buy NOW’ button, and suddenly, the button shifts unexpectedly to the bottom. This kind of experience is not what anyone wants, as it can be quite frustrating for users.</blockquote><p>Consider the amount of content that<strong> moves or shifts unexpectedly</strong> on a webpage during its loading process. This is referred to as layout shift.</p><p>The calculation involves adding up the cumulative score of all layout shifts that happen within the visible area of the webpage. This score is influenced by both the distance that elements move and the space they take up.</p><h4>Cumulative Layout Shift Calculation 🧮</h4><blockquote><strong>Layout shift score = impact fraction * distance fraction</strong></blockquote><ul><li><strong><em>Impacted fraction — </em></strong><em>The union of the visible areas of all unstable elements for the previous frame + current frame.</em></li><li><strong><em>Distance fraction —</em></strong><em> The greatest distance any unstable element has moved in the frame (either horizontally or vertically) divided by the viewport’s largest dimension (width or height, whichever is greater).</em></li></ul><figure><img alt="layout shift in mobile" src="https://cdn-images-1.medium.com/max/740/1*uQ4caXacSZzDTv1iS0Joyw.png" /><figcaption>layout shift in mobile</figcaption></figure><p>In the picture above, the impacted fraction is <strong>0.75</strong>. This means that the <em>text part</em> moved by 25%, causing 75% of the viewport area unstable between the frames. The distance fraction is <strong>0.25</strong>, showing that the text moved 25% down. To get the <strong>Layout Shift Score</strong>, we multiply <strong>0.75 by 0.25</strong>, which equals <strong>0.1875</strong>. As this value increases, it directly corresponds to a decrease in user experience quality.</p><h4>Weightage</h4><p><strong>25%</strong> weightage of overall performance score.​</p><h4>Good CLS Score</h4><figure><img alt="Good CLS score and color code" src="https://cdn-images-1.medium.com/max/993/1*5d2V_wt9GtJPYYbcgGlN_Q.png" /><figcaption>Good CLS</figcaption></figure><p>To provide a good user experience, sites should have the Cumulative Layout Shift of <strong>0.1</strong> or less.</p><blockquote><a href="https://web.dev/cls/">cls reference</a></blockquote><h3>Speed Index (SI) 🕓</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hwncgGCqlYLDCofT" /><figcaption>Photo by <a href="https://unsplash.com/@chrisliverani?utm_source=medium&amp;utm_medium=referral">Chris Liverani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Imagine having a coloring book filled with various pictures. As you color a picture, it takes time to fill in all the colors and bring it to life. In a similar way, the Speed Index measures how quickly a webpage becomes fully loaded, considering both speed and smoothness.</blockquote><p><strong>Technical Explanation:</strong> The Speed Index is a combined metric that reflects both the “<strong><em>visual loading speed</em></strong>” and the “<strong><em>perceived smoothness</em></strong>” of the whole webpage.</p><h4>Here’s how it works:</h4><figure><img alt="vc with timing" src="https://cdn-images-1.medium.com/max/872/0*0dFFfvdhcnh4Zwwr.png" /><figcaption>visual completion with timing</figcaption></figure><ul><li>The browser takes pictures of the page as it loads, like a snapshot.</li><li>It pays attention to the order and timing of when different parts appear.</li><li>This gives us an idea of how fast and smooth the whole page loading experience is.</li><li>Then, Lighthouse uses <em>Speedline Node.js module</em> to figure out the Speed Index score.</li></ul><h4>Weightage</h4><p><strong>10%</strong> weightage of overall performance score.​</p><h4>Good SI Score</h4><figure><img alt="Good Speed Index (SI)" src="https://cdn-images-1.medium.com/max/991/1*0HrRyBbWKdiu-zZY3_9nUg.png" /><figcaption>Good Speed Index (SI)</figcaption></figure><p>To provide a good user experience, sites should have the Speed Index of <strong>3.4</strong> or less.</p><blockquote><a href="https://developer.chrome.com/en/docs/lighthouse/performance/speed-index/">SI reference</a></blockquote><p>In Conclusion, These metrics collectively provide insights into different aspects of web page performance, ranging from initial loading speed to responsiveness to user interactions. By understanding and optimizing these metrics, developers can significantly enhance the user experience of their websites.</p><h4>Frontend Performance Optimization List</h4><p><a href="https://aquibafzal.medium.com/list/08caa7c990f9">Frontend Performance optimization</a></p><h3>Some Quick Links</h3><p><a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a> | <a href="https://aquibafzal.medium.com/mastering-frontend-performance-optimization-test-website-performance-part-1-cad551c1861">Test website performance</a></p><h3>In Plain English</h3><p><em>Thank you for being a part of our community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer! 👏</em></li><li><em>You can find even more content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><strong><em> 🚀</em></strong></li><li><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. 🗞️</em></li><li><em>Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a>, and <a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc648166633c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/mastering-frontend-performance-optimization-a-deep-dive-into-lighthouse-metrics-part-2-bc648166633c">Mastering Frontend Performance Optimization: A Deep Dive into Lighthouse Metrics (Part 2)</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[Mastering Node.js with ChatGPT: Your Ultimate Learning Companion for Exploring New Technologies]]></title>
            <link>https://ai.plainenglish.io/mastering-node-js-with-chatgpt-your-ultimate-learning-companion-for-exploring-new-technologies-44518a89040?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/44518a89040</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 12:16:16 GMT</pubDate>
            <atom:updated>2023-08-15T15:00:46.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="learning nodejs with chatGPT" src="https://cdn-images-1.medium.com/max/1024/0*DDoM2GmILSJ8xmIe" /><figcaption>Photo by <a href="https://unsplash.com/@jupp?utm_source=medium&amp;utm_medium=referral">Jonathan Kemper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Are you new to Node.js and looking to learn this popular JavaScript runtime? You’re in luck! With ChatGPT as your ultimate learning companion, mastering Node.js has never been easier.</p><h3><strong>Research and Gather Information with ChatGPT</strong></h3><figure><img alt="research" src="https://cdn-images-1.medium.com/max/1024/0*VM5DF946SEMk2-oh" /><figcaption>Photo by <a href="https://unsplash.com/@glenncarstenspeters?utm_source=medium&amp;utm_medium=referral">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As a beginner, you may have questions about the basics of Node.js. With ChatGPT, you can ask questions like “What is Node.js?” or “How does Node.js work?” and get comprehensive answers to build a solid foundation of understanding. ChatGPT can provide you with information about Node.js features, use cases, and concepts such as event-driven, non-blocking I/O, and the Node.js event loop in easy-to-understand language.</p><h3><strong>Follow Tutorials and Step-by-Step Guides</strong></h3><figure><img alt="step by step guide" src="https://cdn-images-1.medium.com/max/1024/0*F5Fs46__wXJxbNwS" /><figcaption>Photo by <a href="https://unsplash.com/@jakehills?utm_source=medium&amp;utm_medium=referral">Jake Hills</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Learning through tutorials is an effective way to understand Node.js concepts and build practical skills. With ChatGPT, you can ask for tutorials and step-by-step guides on various topics related to Node.js, such as setting up a simple Node.js server, building a RESTful API, or working with popular Node.js frameworks like Express.js. ChatGPT can provide you with instructions, explanations, and code snippets to help you follow along and learn by doing.</p><h3><strong>Troubleshooting and Problem-Solving</strong></h3><figure><img alt="bug and troubleshooting" src="https://cdn-images-1.medium.com/max/1024/0*m_vT5pyMVEK9ICFG" /><figcaption>Photo by <a href="https://unsplash.com/@justinlauria?utm_source=medium&amp;utm_medium=referral">Justin Lauria</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As a beginner, you may encounter issues or errors while working with Node.js. With ChatGPT, you can ask for help in troubleshooting and problem-solving. Describe the problem you’re facing, and ChatGPT can provide you with possible solutions and tips to resolve the issue. From debugging techniques to common error fixes, ChatGPT can assist you in overcoming obstacles in your Node.js learning journey.</p><h3><strong>Personalized Learning Experience</strong></h3><figure><img alt="learning experience" src="https://cdn-images-1.medium.com/max/1024/0*V5GvGm9Gjt3guHpa" /><figcaption>Photo by <a href="https://unsplash.com/@johnschno?utm_source=medium&amp;utm_medium=referral">John Schnobrich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the unique advantages of using ChatGPT is the ability to customize your interactions to suit your learning style and preferences. You can ask ChatGPT to explain concepts in different ways, provide feedback on its responses, or request specific types of information. ChatGPT can adapt to your learning style, providing you with a personalized learning experience tailored to your needs and helping you learn Node.js at your own pace.</p><h3><strong>Stay Updated with Latest Trends</strong></h3><figure><img alt="up to date" src="https://cdn-images-1.medium.com/max/1024/0*sjQrugiC8Ngdwi79" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Technology is constantly evolving, and it’s essential to stay updated with the latest trends and updates in Node.js. With ChatGPT, you can ask for the latest news and updates related to Node.js, such as the latest features in the newest version or performance improvements. Stay current with the latest advancements in Node.js and ensure that your learning is up-to-date with ChatGPT as your information source.</p><h3>Collaborative Learning and Discussions</h3><figure><img alt="collaborative leaning" src="https://cdn-images-1.medium.com/max/1024/0*gt5vzg846CDjizyR" /><figcaption>Photo by <a href="https://unsplash.com/@disruptxn?utm_source=medium&amp;utm_medium=referral">Desola Lanre-Ologun</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Engaging in discussions and collaborative learning can further enhance your understanding of Node.js. You can ask ChatGPT for opinions or insights on different aspects of Node.js, such as comparing Node.js with other server-side JavaScript frameworks or understanding the advantages of using Express.js. Asking ChatGPT to answer the question with different examples. ChatGPT can also provide you with valuable insights and opinions, fostering collaborative learning and discussions.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><strong><em>, </em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><strong><em>, and</em></strong><em> </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong><em> Interested in Growth Hacking? Check out </em><a href="https://circuit.ooo/"><strong><em>Circuit</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44518a89040" width="1" height="1" alt=""><hr><p><a href="https://ai.plainenglish.io/mastering-node-js-with-chatgpt-your-ultimate-learning-companion-for-exploring-new-technologies-44518a89040">Mastering Node.js with ChatGPT: Your Ultimate Learning Companion for Exploring New Technologies</a> was originally published in <a href="https://ai.plainenglish.io/">Artificial Intelligence 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[Mastering Frontend Performance Optimization: Test website performance (Part 1)]]></title>
            <link>https://javascript.plainenglish.io/mastering-frontend-performance-optimization-test-website-performance-part-1-cad551c1861?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cad551c1861</guid>
            <category><![CDATA[lighthouse]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 06:16:51 GMT</pubDate>
            <atom:updated>2023-08-24T12:46:41.640Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Frontend Performance Optimization: Test Website Performance</h3><h4>Part 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6hqt60Bkr041dhj4.png" /></figure><p>In today’s fast-paced digital landscape, a slow and sluggish website can spell disaster for your online presence and business success. Imagine waiting 10 seconds for your favorite Netflix show to load or being hungry and having the Swiggy menu take ages to appear. Nobody wants that kind of experience. The speed at which your application functions can either make or break your business, and that’s why frontend performance optimization is an absolute necessity.</p><h3>Why Website Performance Matters for Your Business:</h3><ol><li><strong>Better website performance leads to increased conversion rates.<br></strong>Research from Aberdeen reveals that a mere 7% drop in conversions can lead to substantial lost sales for e-commerce websites. For instance, a site making $10,000 per day could lose over $2.5 million annually due to a 7% drop. Swift loading times, such as a page loading in two seconds instead of three, can make a significant difference in conversions.</li><li><strong>Better website performance improves SEO.<br></strong>Search engines, led by Google, prioritize faster-loading pages in their search rankings. If your website is slow, it could lose visibility in search results, resulting in decreased organic traffic and missed opportunities.</li><li><strong>Poor website performance destroys brand perception.<br></strong>Your website’s speed has a direct impact on how users perceive your brand. Slow websites can tarnish your brand’s reputation and make users question the overall quality of your offerings.</li><li><strong>Faster performing websites gain a competitive edge.<br></strong>Websites that load quickly gain a competitive advantage. In a crowded digital landscape, the ability to provide a seamless and swift user experience sets you apart from competitors.</li></ol><h3>Calculating and Analyzing Website Performance:</h3><figure><img alt="Calculating and Analyzing Website Performance" src="https://cdn-images-1.medium.com/max/1024/0*06ygggtwwPOkv1QQ" /><figcaption>Photo by <a href="https://unsplash.com/@kmuza?utm_source=medium&amp;utm_medium=referral">Carlos Muza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are many tools available which can be used for testing performance.</p><ul><li>Google Lighthouse</li><li>GTmetrix</li><li>PageSpeed Insights</li></ul><p>In this blog, we will focus on <strong>Google Lighthouse</strong></p><h3>Unleash the Power of Google Lighthouse:</h3><figure><img alt="lighthouse" src="https://cdn-images-1.medium.com/max/1024/1*GNGcM0X-ji0Je5QWE-Pwuw@2x.jpeg" /><figcaption>Photo by Randy Laybourne on Unsplash</figcaption></figure><p>Lighthouse is a great tool to audit and measure your website performance. It covers a wide spectrum of performance parameters, including:</p><ul><li>Performance</li><li>Progressive web application</li><li>Search Engine Optimization</li><li>Accessibility</li><li>Best Practices for both mobile and desktop</li></ul><h4>How to use lighthouse?</h4><p>There are multiple ways to use lighthouse -</p><ol><li><strong>In Chrome DevTools</strong></li><li>From command line</li><li>As a node modules</li><li>As a chrome extension</li></ol><p>In the blog, we will discuss how to use lighthouse through Chrome DevTools.</p><h4>Steps to use Lighthouse through Chrome DevTools</h4><ul><li><strong>Download Google Chrome:</strong> Ensure you have <a href="https://www.google.com/chrome/?brand=CHBD&amp;brand=CHBD&amp;gclid=Cj0KCQjwz8emBhDrARIsANNJjS4N78eJ7OEObgNy5ftTwYfF5ZooaASpfXEgWqyfvCnT__8Bn6vC1nAaAusdEALw_wcB&amp;gclsrc=aw.ds">Google Chrome</a> installed on your desktop.</li><li><strong>Open DevTools:</strong> Go to the URL you want to audit, right-click, and select “Inspect” (or use the shortcut key Ctrl+Shift+I) to open Chrome DevTools.</li><li><strong>Access Lighthouse:</strong> In DevTools, navigate to the “Lighthouse” tab.</li><li><strong>Setting Viewport: </strong>Change the viewport size on which you want to test. If you want to test with full view port then open devTools in seperate window.</li><li><strong>Configuring the Test:</strong> Check Navigation in Mode, Performance in Category and mobile or desktop in Device options.</li></ul><figure><img alt="Audit website" src="https://cdn-images-1.medium.com/max/1024/1*lLvibGw_CjWEfZfO9gY1Fw.png" /><figcaption>Website to audit with lighthouse</figcaption></figure><ul><li><strong>Initiating the Test:</strong> Click the “Analyze page load” button to start the performance testing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJPc_a7NYn-nbmC5Urf2GQ.png" /><figcaption>Analysis generated by lighthouse</figcaption></figure><p>After the test completes, you’ll receive a performance score and various metrics, such as First Contentful Paint (FCP), Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and more.</p><blockquote>Note: To provide a good user experience, sites should have a <strong>good score (90–100)</strong>.</blockquote><h4>Overcoming Performance Challenges:</h4><p>Address common warnings that can affect your performance score:</p><ul><li><strong>Stored Data Issues:</strong> Clear stored data in IndexedDB, localStorage, etc., from the Application tab in DevTools.</li><li><strong>Chrome Extensions:</strong> Disable all extensions that might impact performance.</li></ul><figure><img alt="error and solution in lighthouse" src="https://cdn-images-1.medium.com/max/1024/1*iHkv-kR36aXLMtDMR50twA.png" /><figcaption>common errors and its solution</figcaption></figure><h4>What is good Performance?</h4><p>90–100 score is considered as good score.</p><ul><li>0 to 49 (red): Poor</li><li>50 to 89 (orange): Needs Improvement</li><li>90 to 100 (green): Good</li></ul><figure><img alt="Performance score color code" src="https://cdn-images-1.medium.com/max/954/0*wCV4mt0KBJpvFJW-.png" /><figcaption>performance score color code</figcaption></figure><p><em>Thank you for reading the blog! 🙏</em><br><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer! 👏</em></p><blockquote>Stay tuned for our next chapter, where we’ll dive deeper into the realm of performance metrics, unlocking even more secrets to website success.</blockquote><ul><li><a href="https://blog.bitsrc.io/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">Clean Code in JavaScript: Best Practices for Readable and Maintainable Code</a></li><li><a href="https://blog.bitsrc.io/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Boosting the Performance of Node.js Applications with the Cluster Module</a></li><li><a href="https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Legendary methods of Array in JavaScript | Part 1 : forEach, find, filter and map</a></li><li><a href="https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-2-reduce-some-and-every-7f3321876565">Legendary methods of Array in JavaScript | Part 2 : reduce, some and every</a></li></ul><h3>Some Quick Links</h3><p><a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>In Plain English</h3><p><em>Thank you for being a part of our community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer! 👏</em></li><li><em>You can find even more content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><strong><em> 🚀</em></strong></li><li><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. 🗞️</em></li><li><em>Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a>, and <a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cad551c1861" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/mastering-frontend-performance-optimization-test-website-performance-part-1-cad551c1861">Mastering Frontend Performance Optimization: Test website performance (Part 1)</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[Choosing the Best JavaScript Frontend Framework for Beginners: A Comparative Analysis]]></title>
            <link>https://javascript.plainenglish.io/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7860e6bb729e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Sat, 20 May 2023 10:53:48 GMT</pubDate>
            <atom:updated>2023-05-22T21:29:36.182Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="comparison" src="https://cdn-images-1.medium.com/max/1024/1*kNWa9Bqx4Qkd5mn-6Kb2Cg@2x.jpeg" /><figcaption>Photo by Glenn Carstens-Peters on Unsplash</figcaption></figure><p>As a beginner, selecting the right JavaScript frontend framework can greatly impact your learning experience and future career opportunities. In this guide, we’ll delve into popular JavaScript frameworks, evaluating their ease of learning, job availability, use cases, and the benefits they offer. By understanding these aspects, you can make an informed decision on which framework to choose as a beginner.</p><h3>Ease of Learning:</h3><figure><img alt="ease of learning" src="https://cdn-images-1.medium.com/max/1024/1*_QQQSFIQv6Leti14dxme5g@2x.jpeg" /><figcaption>Photo by Tim Mossholder on Unsplash</figcaption></figure><ol><li><strong>React</strong>: React has a relatively gentle learning curve, especially for developers already familiar with JavaScript. Its component-based approach and well-structured documentation make it easier to grasp. Additionally, the vast React community provides abundant learning resources, tutorials, and supportive forums.</li><li><strong>Vue.js</strong>: Vue.js is renowned for its simplicity, making it an excellent choice for beginners. Its gentle learning curve, intuitive syntax, and clear documentation contribute to its ease of learning. With Vue.js, you can quickly build small to medium-sized projects while gradually expanding your skillset.</li><li><strong>Angular</strong>: Angular has a steeper learning curve due to its comprehensive feature set and more complex concepts. However, Angular’s strong documentation, official tutorials, and a large community make learning more accessible. Angular’s focus on architecture and robustness makes it a solid choice for enterprise-level projects.</li><li><strong>Svelte</strong>: Svelte offers a smooth learning curve, particularly for beginners. Its simplicity and clear syntax enable rapid comprehension. Svelte’s compiler-based approach eliminates the need for additional libraries or complex tooling, making it easier to grasp the framework’s core concepts.</li></ol><h3>Job Availability:</h3><figure><img alt="job availability" src="https://cdn-images-1.medium.com/max/1024/1*Hxs4OS3AOl1a70act7VgMw@2x.jpeg" /><figcaption>Photo by Eric Prouzet on Unsplash</figcaption></figure><ol><li><strong>React</strong>: React boasts a high demand in the job market, with numerous opportunities available. Its popularity and extensive adoption by tech giants and startups alike ensure a steady stream of React-related job openings.</li><li><strong>Vue.js</strong>: Although not as widely adopted as React or Angular, Vue.js has been steadily gaining popularity. While the job market for Vue.js may not be as vast as React, it presents ample opportunities, particularly in smaller companies and startups.</li><li><strong>Angular</strong>: Angular has a strong presence in the enterprise world, making it a popular choice for larger organizations. Consequently, there is a significant demand for Angular developers, especially for complex enterprise projects.</li><li><strong>Svelte</strong>: Svelte, though relatively newer, has been garnering attention and gaining traction. While the job market for Svelte may not be as extensive as React or Angular, it offers opportunities for those seeking performance-focused projects and forward-looking companies.</li></ol><h3>Use Cases:</h3><figure><img alt="use cases" src="https://cdn-images-1.medium.com/max/1024/1*Q7yoOY-ZrPEoP5ZGFguUrQ@2x.jpeg" /><figcaption>Photo by Marvin Meyer on Unsplash</figcaption></figure><p><strong>React</strong>: React is suitable for a wide range of applications, from single-page applications (SPAs) and complex web interfaces to cross-platform mobile app development with React Native.</p><p><strong>Vue.js</strong>: Vue.js shines in building smaller to medium-sized projects, prototypes, or Minimum Viable Products (MVPs). It is also a great choice for interactive user interfaces and real-time updates.</p><p><strong>Angular</strong>: Angular excels in building large-scale enterprise applications with complex business logic, extensive form handling, and rich interactive features.</p><p><strong>Svelte</strong>: Svelte’s focus on performance and elegance makes it an excellent choice for applications where bundle size and performance are critical, such as mobile applications and components for existing projects.</p><h3>Benefits:</h3><figure><img alt="benefits" src="https://cdn-images-1.medium.com/max/1024/1*Y6MEOBWEPa5cU2s1bfq7GA@2x.jpeg" /><figcaption>Photo by Razvan Chisu on Unsplash</figcaption></figure><ol><li><strong>React</strong>: React’s virtual DOM, component reusability, and extensive ecosystem contribute to excellent performance and code maintainability. Its active community and rich ecosystem ensure continuous support and a wide range of libraries and tools.</li><li><strong>Vue.js</strong>: Vue.js offers flexibility, simplicity, and ease of integration with existing projects. Its lightweight nature and intuitive API contribute to faster development and enhanced productivity. Vue.js also provides excellent documentation and a growing ecosystem.</li><li><strong>Angular</strong>: Angular’s robustness, extensive features, and strong architecture make it suitable for large scale enterprise applications. Its two-way data binding, dependency injection, and comprehensive tooling enhance development efficiency and maintainability. Angular’s TypeScript integration also promotes code quality and developer productivity.</li><li><strong>Svelte</strong>: Svelte’s compilation-based approach results in highly performant applications with small bundle sizes. Its simplicity and automatic reactivity streamline development and make it easier to create efficient and elegant code. Svelte’s lightweight nature and seamless integration allow for rapid prototyping and development.</li></ol><p>In conclusion, consider your learning preferences, project requirements, and long-term goals when making your decision. Remember that while job availability is an important factor, selecting a framework that aligns with your interests and learning goals will provide the most fulfilling and rewarding experience. Regardless of the framework you choose, continuous learning, practice, and staying updated with industry trends will pave the way for your success as a JavaScript developer. Happy coding!</p><h3>Some Quick Links</h3><p><a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><p><a href="https://github.com/aquibzahidi/Advance-NodeJs">GitHub - aquibzahidi/Advance-NodeJs: This repository contains Advance NodeJs concepts and Interview questions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7860e6bb729e" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">Choosing the Best JavaScript Frontend Framework for Beginners: A Comparative Analysis</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[Clean Code in JavaScript: Best Practices for Readable and Maintainable Code]]></title>
            <link>https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/375b9792cde0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 11:15:24 GMT</pubDate>
            <atom:updated>2023-05-20T11:21:52.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XaQU72i5vBWiwOdZ" /><figcaption>Photo by <a href="https://unsplash.com/@tushar_oatsstudio?utm_source=medium&amp;utm_medium=referral">Tushar Gidwani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Clean code refers to code that is easy to comprehend, read, and maintain. It follows a set of principles and best practices that simplify the process of modifying and working with the code over time. Writing clean code is crucial as it promotes better software development practices, reduces the likelihood of bugs, and enhances the code’s ease of maintenance.</p><p><strong>To create clean code in JavaScript, the following 10 things should be prioritized:</strong></p><h3>1. Use meaningful names</h3><p>In order to write clean code, it’s crucial to use meaningful and descriptive names for variables and functions. This helps to convey the purpose and usage of these elements and makes the code more understandable and maintainable.</p><p>For example, consider the following code:</p><pre>// Bad<br>let a = 10;<br>function f(x) {<br>  return x + a;<br>}<br><br>// Good<br>let initialCount = 10;<br>function calculateFinalCount(currentCount) {<br>  return currentCount + initialCount;<br>}</pre><p>In the &quot;bad&quot; example, the variable a and the function f do not provide any clear indication of their purpose. On the other hand, the &quot;good&quot; example uses more descriptive names like initialCount and calculateFinalCount, which makes it easier to understand what they are used for.</p><p>When naming variables that store arrays, it&#39;s a good practice to use plural names to indicate that the variable stores multiple values. For instance, the following code is a good example:</p><pre>// bad<br><br>let name = [&quot;John&quot;, &quot;Doe&quot;, &quot;Peterson&quot;]<br><br>// good<br><br>let names = [&quot;John&quot;, &quot;Doe&quot;, &quot;Peterson&quot;]</pre><p>In the above example, names is a more descriptive name than name as it indicates that the variable stores multiple names.</p><p>When storing a Boolean value, it’s a good practice to use a prefix is in the variable name. For example, consider the following code:</p><pre>// Bad<br><br>let loading = true<br><br>// Good<br><br>let isLoading = true</pre><p>In the above example, using the prefix is in the variable name makes it easier to understand that it stores a Boolean value, and also makes it more descriptive.</p><h3>2. Use naming conventions using camelCase</h3><p>Using camelCase notation for naming variables, functions, objects, etc. is an important convention to make your code more readable and consistent. In camelCase notation, the first word is lowercase, and subsequent words are capitalized.</p><p>Here is an example:</p><pre>//bad code<br><br>const personname = &quot;John Doe&quot;<br><br>//good code<br><br>const personName = &quot;John Doe&quot;</pre><p>In the “bad” example, the variable personname is written in all lowercase, which makes it harder to read and understand. On the other hand, in the &quot;good&quot; example, the variable personName uses camel-case notation, which makes it easier to read and understand.</p><h3>3. Indent code</h3><p>Use code indentation tools like Prettier to keep the code clean and easy to read. This ensures that your code is consistently formatted and follows best practices, especially when dealing with complex nested structures. for code indentation, VS code extension (prettier) can be used.</p><pre>// Before formatting with Prettier<br>function calculateArea(radius){<br>let area=3.14*radius*radius;<br>return area;<br>}<br><br>// After formatting with Prettier<br>function calculateArea(radius) {<br>  let area = 3.14 * radius * radius;<br>  return area;<br>}</pre><h3>4. Use Template Literals</h3><p>Template literals are a more flexible and convenient way to work with strings in JavaScript. They allow you to embed variables and expressions directly inside a string, using special syntax with backticks (` `) instead of quotes (&#39; &#39; or &quot; &quot;).</p><p>For example:</p><pre>// Without using template literals<br>const name = &quot;John&quot;;<br>const age = 30;<br><br>const message = &quot;My name is &quot; + name + &quot; and I am &quot; + age + &quot; years old.&quot;;<br><br>console.log(message);<br>// Output: My name is John and I am 30 years old.<br><br><br>// Using template literals<br>const name = &quot;John&quot;;<br>const age = 30;<br><br>const message = `My name is ${name} and I am ${age} years old.`;<br><br>console.log(message);<br>// Output: My name is John and I am 30 years old.</pre><p>In this code, the string is constructed using concatenation with the + operator to combine the string and variables. While this approach works, it can be more cumbersome and harder to read, especially when dealing with longer strings and multiple variables.</p><p>However, the string is created using a template literal, which starts and ends with backticks (``). variables name and age are then embedded inside the string using the syntax ${variable}. This makes it much easier to read and write, especially when dealing with longer strings or multiple variables.</p><h3>5. Use Functions for Splitting Code</h3><p>Write functions for every specific task. Functions can help to split your code into smaller, more manageable chunks. This can improve readability, maintainability, and reusability. Functions should be focused on a specific task and should be named accordingly.</p><p>For example:</p><pre>// Without using functions<br>let numbers = [1, 2, 3, 4, 5];<br>let sum = 0;<br>for (let i = 0; i &lt; numbers.length; i++) {<br>  sum += numbers[i];<br>}<br>console.log(sum);<br><br>// Using functions<br>function calculateSum(numbers) {<br>  let sum = 0;<br>  for (let i = 0; i &lt; numbers.length; i++) {<br>    sum += numbers[i];<br>  }<br>  return sum;<br>}<br>let numbers = [1, 2, 3, 4, 5];<br>console.log(calculateSum(numbers));</pre><p>In the above example, the “calculateSum” function can be used many times when sum of numbers are needed. It makes the code more readable and reusable.</p><h3>6. Send Arguments as Object</h3><p>If you have to send multiple arguments then sending arguments as object can make your code more readable and flexible. Objects can contain multiple properties that represent different values, making it easier to understand the purpose and functionality of your code.</p><p>For example:</p><pre>// Without using objects<br>function createUser(name, email, age) {<br>// ...<br>}<br><br>createUser(&quot;John Doe&quot;, &quot;johndoe@example.com&quot;, 30);<br><br>// Using objects<br>function createUser(user) {<br>// ...<br>}<br><br>createUser({<br>name: &quot;John Doe&quot;,<br>email: &quot;johndoe@example.com&quot;,<br>age: 30,<br>});</pre><h3>8. Use Arrow Functions</h3><p>Arrow functions are a concise way of writing functions in JavaScript. They can make your code more readable and reduce the amount of boilerplate code. Arrow functions have a simplified syntax and an implicit return statement.</p><p>For example:</p><pre>// Without using arrow functions<br>let numbers = [1, 2, 3, 4, 5];<br>let evenNumbers = numbers.filter(function (number) {<br>return number % 2 === 0;<br>});<br>console.log(evenNumbers);<br><br>// Using arrow functions<br>let numbers = [1, 2, 3, 4, 5];<br>let evenNumbers = numbers.filter((number) =&gt; number % 2 === 0);<br>console.log(evenNumbers);</pre><h3>9. Conditional Execution with &amp;&amp; Operator</h3><p>In JavaScript, the &amp;&amp; operator can be used to perform a conditional check and execute a second command only if the first value is truthy. ‘</p><p>For example:</p><pre>// Example 1<br>let x = 5;<br>let y = &quot;&quot;;<br><br>// Check if x is truthy, then execute the second command<br>x &amp;&amp; console.log(&quot;x is truthy&quot;); // Output: &quot;x is truthy&quot;<br><br>// Check if y is truthy, then execute the second command<br>y &amp;&amp; console.log(&quot;y is truthy&quot;); // No Output </pre><p>In the example above, we have two variables x and y. The x &amp;&amp; console.log(&quot;x is truthy&quot;) statement checks if x is truthy (i.e., not null, undefined, false, 0, NaN, or an empty string), and if it is, it executes the second command console.log(&quot;x is truthy&quot;). Since x is not null, undefined, or 0, the second command is executed and the output &quot;x is truthy&quot; is printed.</p><p>On the other hand, the statement y &amp;&amp; console.log(&quot;y is truthy&quot;) checks if y is truthy. Since y is “” (a falsy value), the second command is not executed and that’swhy there is not output.</p><h3>10. Conditional Execution with || Operator</h3><p>The || operator can be used to perform a conditional check and execute a second command only if the first value is falsy.</p><p>For Example:</p><pre>let x = null;<br>let y = &quot;Hello&quot;;<br><br>// Check if x is falsy, then execute the second command<br>x || console.log(&quot;x is falsy&quot;); // Output: &quot;x is falsy&quot;<br><br>// Check if y is falsy, then execute the second command<br>y || console.log(&quot;y is falsy&quot;); // No output</pre><p>In the example above, we have two variables x and y. The x || console.log(&quot;x is falsy&quot;) statement checks if x is falsy (i.e., null, undefined, false, 0, NaN, or an empty string), and if it is, it executes the second command console.log(&quot;x is falsy&quot;). Since x is null, which is a falsy value, the second command is executed and the output &quot;x is falsy&quot; is printed.</p><p>On the other hand, the statement y || console.log(&quot;y is falsy&quot;) checks if y is falsy. Since y is a non-empty string, which is a truthy value, the condition is falsy, and the second command is not executed, resulting in no output.</p><p>Here’s another example with a slightly different scenario:</p><pre>let isLoggedIn = false;<br>let defaultUsername = &quot;Guest&quot;;<br><br>// Check if isLoggedIn is falsy, then assign defaultUsername as the username<br>let username = isLoggedIn || defaultUsername;<br><br>console.log(username); // Output: &quot;Guest&quot;</pre><p>In this example, we have a isLoggedIn and a defaultUsername variable. The isLoggedIn || defaultUsername expression checks if isLoggedIn is falsy. Since isLoggedIn is false, which is a falsy value, the expression evaluates to defaultUsername, and the value &quot;Guest&quot; is assigned to the username variable.</p><p>Using || in this way can provide a concise and efficient way to conditionally assign a default value or execute a second command based on the falsiness of a value. It&#39;s important to understand that the second command or default value will only be executed or assigned if the first value is falsy.</p><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a> | <a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a></p><p><a href="https://github.com/aquibzahidi/Advance-NodeJs">GitHub - aquibzahidi/Advance-NodeJs: This repository contains Advance NodeJs concepts and Interview questions</a></p><h3>Build Apps with reusable components, just like Lego</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Rtj6DqD3IXvU8hyk.png" /></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><strong>→ </strong><a href="https://bit.dev/"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h4>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h4><h4>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h4><h4>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h4><h4>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h4><h4>Learn more:</h4><ul><li><a href="https://blog.bitsrc.io/creating-a-developer-website-with-bit-components-3f4083a7f050">Creating a Developer Website with Bit components</a></li><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.dev/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4/">How to reuse React components across your projects</a></li><li><a href="https://blog.bitsrc.io/5-ways-to-build-a-react-monorepo-a294b6c5b0ac">5 Ways to Build a React Monorepo</a></li><li><a href="https://bit.dev/blog/how-to-create-a-composable-react-app-with-bit-l7ejpfhc/">How to Create a Composable React App with Bit</a></li><li><a href="https://itnext.io/how-to-reuse-and-share-react-components-in-2023-a-step-by-step-guide-85642e543afa">How to Reuse and Share React Components in 2023: A Step-by-Step Guide</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=375b9792cde0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">Clean Code in JavaScript: Best Practices for Readable and Maintainable Code</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async/Await in JavaScript: Simplifying Asynchronous Code]]></title>
            <link>https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/39075ea4cd03</guid>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Sun, 26 Feb 2023 07:23:20 GMT</pubDate>
            <atom:updated>2023-05-20T11:23:33.525Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Waiting" src="https://cdn-images-1.medium.com/max/1024/0*tmGP11e1cVHYjMUx" /><figcaption>Photo by <a href="https://unsplash.com/@matthewhenry?utm_source=medium&amp;utm_medium=referral">Matthew Henry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Async/await is a feature of JavaScript that simplifies asynchronous programming. We will define async/await, describe how it functions, and give some practical examples in this blog article.</p><h3>Understand Asynchronous Programming</h3><p>Asynchronous programming is a programming pattern where tasks are completed simultaneously and the results are returned as soon as they are ready. Traditional synchronous programming executes tasks sequentially, which might cause the user to wait a very long time.<br>Javascript offers asynchronous programming in primarily three different ways: <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">callbacks</a>, <a href="https://blog.bitsrc.io/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">promises</a>, and async/await.<br>Callbacks are functions that are executed after a task is completed and are passed as arguments in other functions. Promises are objects that stand in for values that might not be available right away but will be fulfilled eventually. Async/await is a modern method for managing asynchronous programming that makes the code syntax simpler and more readable.</p><p>I recommend to read JavaScript Promise before delving into Async/await for a better understanding of the underlying concepts.</p><p><a href="https://blog.bitsrc.io/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">JavaScript Promise: A Beginner’s Guide to Asynchronous Operations</a></p><h3>What is Async/Await?</h3><p>Programmers can write asynchronous code more synchronously using JavaScript’s async/await syntax feature. It is based on <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> and offers a cleaner, more legible approach to construct asynchronous programmes.</p><p>When a function is marked with the “async” prefix, it means that it will always return a <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a>. The “await” keyword is used to halt the execution of the programme inside an async function until the Promise is fulfilled.</p><h3>How to use Async/Await?</h3><figure><img alt="How to use Async/Await" src="https://cdn-images-1.medium.com/max/1024/0*uhmAV70HgmjMkhwA" /><figcaption>Photo by <a href="https://unsplash.com/@levimeirclancy?utm_source=medium&amp;utm_medium=referral">Levi Meir Clancy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>let’s look at an example to understand working of async/await. Consider the case where a function returns a Promise that resolves after some time:</p><pre>function wait(ms) {<br>  return new Promise(resolve =&gt; setTimeout(resolve, ms));<br>}</pre><p>We can use this function to create a delay in our code. For instance, We can delay the execution of the function by one second by using the code below:</p><pre>async function delayedFunction() {<br>  await wait(1000);<br>  console.log(&quot;Delayed function executed&quot;);<br>}</pre><p>In this code, we have marked the “delayedFunction” as asynchronous using the “async” keyword. We have also used the “await” keyword to pause the execution of the code until the <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> returned by “wait” function is resolved. Once the Promise is resolved, the console will log the message “Delayed function executed”.</p><h3>Handling Errors with Async/Await</h3><figure><img alt="Error Handling in JavaScript (Async/Await)" src="https://cdn-images-1.medium.com/max/1024/0*VmuapTA4meZF2gw8" /><figcaption>Photo by <a href="https://unsplash.com/@rojekilian?utm_source=medium&amp;utm_medium=referral">Sarah Kilian</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Error handling is simplified when async/await is used, which is one of its advantages. We can use the “try/catch” to handle the error in a more synchronous way. For instance, that we have a function that returns a Promise which expires after some time:</p><pre>function waitAndReject(ms) {<br>  return new Promise((resolve, reject) =&gt; setTimeout(() =&gt; reject(&quot;Error&quot;), ms));<br>}</pre><p>We can use this function to simulate an error in our code. For example, we can handle the error in the following way:</p><pre>async function errorFunction() {<br>  try {<br>    await waitAndReject(1000);<br>  } catch (e) {<br>    console.log(e);<br>  }<br>}</pre><p>In this code, we have used the “try/catch” statement to handle the error thrown by the Promise returned by “waitAndReject”. If the <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> is rejected, the error message “Error” will be logged to the console.</p><h3>Real-world Examples of Async/Await</h3><figure><img alt="Real-world Examples of Async/Await" src="https://cdn-images-1.medium.com/max/1024/0*rX5XW2uoXdoPdN3N" /><figcaption>Photo by <a href="https://unsplash.com/@polarmermaid?utm_source=medium&amp;utm_medium=referral">Anne Nygård</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s take a look at how to use async/await with the Fetch API to retrieve data from a third-party API:</p><pre>async function getJokes(category) {<br>  try {<br>    const response = await fetch(`https://api.chucknorris.io/jokes/random?category=${category}`);<br>    const data = await response.json();<br>    const joke = data.value;<br>    console.log(`Here&#39;s a joke about ${category}: ${joke}`);<br>  } catch (e) {<br>    console.log(`Error: ${e}`);<br>  }<br>}</pre><p>In this code, we have used async/await with the Fetch API to make an HTTP request to the Chuck Norris Jokes API and retrieve a random joke for a given category. We have also used try/catch to handle any errors that may occur during the request.</p><p>The Chuck Norris Jokes API is a public API that provides random jokes about Chuck Norris in different categories such as “dev”, “science”, “movie”, etc. This example demonstrates how to use async/await to retrieve data from a third-party API and use it in your application.</p><h3>Benefits of Using Async/Await</h3><figure><img alt="why?" src="https://cdn-images-1.medium.com/max/1024/0*IjuBATHo_TNlc8O3" /><figcaption>Photo by <a href="https://unsplash.com/@emilymorter?utm_source=medium&amp;utm_medium=referral">Emily Morter</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Using async/await has several benefits over traditional asynchronous programming methods. First, it simplifies the syntax and makes the code more readable by avoiding callback nesting and chaining. Second, it allows for better error handling by using try/catch blocks to handle exceptions. Finally, it improves the performance of web applications by allowing tasks to execute concurrently and reducing the wait time for the user.</p><h3>Best Practices for Using Async/Await</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hcuZhxVPEZRTlGZr" /><figcaption>Photo by <a href="https://unsplash.com/@austinchan?utm_source=medium&amp;utm_medium=referral">Austin Chan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>While async/await provides a simpler and more concise way to write asynchronous code, there are still some best practices to keep in mind. Here are a few tips to help you write efficient and maintainable async/await code:</p><ol><li>Always use try/catch blocks to handle exceptions and errors.</li><li>Use Promise.all() method to execute multiple asynchronous tasks concurrently.</li><li>Use Promise.race() method to execute multiple asynchronous tasks and return the result of the first task that resolves or rejects.</li><li>Avoid using await inside loops, as it can block the execution of other tasks.</li><li>Use third-party libraries such as async or bluebird to handle complex asynchronous tasks.</li></ol><p>In conclusion, JavaScript’s async/await functionality is a potent tool that lets programmers write asynchronous code in a more synchronous manner. It makes handling <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> easier and makes handling errors simpler. It could take some time to become used to the syntax and comprehend how async/await functions if you are a beginner. But once you get the hang of it, you’ll discover that writing asynchronous JavaScript code gets much simpler and more pleasurable.</p><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>Contact Me</h3><p><a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a> | <a href="https://github.com/aquibzahidi">Github</a></p><h4>Build Apps with reusable components, just like Lego</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*60wFHFzy454JxbGf.png" /></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><strong>→ </strong><a href="https://bit.dev/"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h4>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h4><h4>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h4><h4>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h4><h4>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h4><h4>Learn more:</h4><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.dev/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4/">How to reuse React components across your projects</a></li><li><a href="https://blog.bitsrc.io/5-ways-to-build-a-react-monorepo-a294b6c5b0ac">5 Ways to Build a React Monorepo</a></li><li><a href="https://bit.dev/blog/how-to-create-a-composable-react-app-with-bit-l7ejpfhc/">How to Create a Composable React App with Bit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39075ea4cd03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await in JavaScript: Simplifying Asynchronous Code</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Promise: A Beginner’s Guide to Asynchronous Operations]]></title>
            <link>https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b6676d3016a</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[callback]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 07:41:07 GMT</pubDate>
            <atom:updated>2023-05-20T11:24:16.880Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="promise" src="https://cdn-images-1.medium.com/max/1024/0*VzgQWZDVEUaXWg_p" /><figcaption>Photo by <a href="https://unsplash.com/@alisestorsul?utm_source=medium&amp;utm_medium=referral">alise storsul</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>JavaScript Promise is a powerful tool for handling asynchronous operations in web applications. It’s widely used in modern JavaScript development, and it’s important to understand how it works and how to use it in your code. In this article, we’ll explain what Promises are, how to create and use them, and provide a summary of the Promise API.</p><p><a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6"><strong>Callback</strong></a> is used to handle asynchronous operations before Promise.</p><p><a href="https://blog.bitsrc.io/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Functions in JavaScript: A Comprehensive Guide</a></p><h3>Promise in JavaScript?</h3><p>JavaScript Promise is an object that represents the eventual completion or failure of an asynchronous operation. Promises are used to handle asynchronous operations, such as fetching data from an API.</p><blockquote>Consider a Promise is like a contract between your code and the asynchronous operation. When you make a Promise, you’re saying “I promise to do something once this operation is complete.” That something can be to display the data on a web page, to process the data further, or to handle any errors that might occur.</blockquote><figure><img alt="promise working" src="https://cdn-images-1.medium.com/max/801/1*0xv_E34lF_dvwL_nbuTvaQ.png" /></figure><p>Promise has three states: pending, resolved, and rejected.</p><ul><li>Pending: The initial state of a Promise. The Promise is neither fulfilled nor rejected.</li><li>Resolved: The state of a Promise when the asynchronous operation is successfully completed.</li><li>Rejected: The state of a Promise when the asynchronous operation fails.</li></ul><h3>Benefits of using Promise:</h3><figure><img alt="benefits of promise" src="https://cdn-images-1.medium.com/max/1024/0*5qK9-Q1IPpPcqKOg" /><figcaption>Photo by <a href="https://unsplash.com/@bradencollum?utm_source=medium&amp;utm_medium=referral">Braden Collum</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ol><li><strong>Cleaner code:</strong> Promises can simplify code that involves multiple asynchronous operations, such as fetching data from multiple APIs.</li><li><strong>Improved error handling:</strong> Promises make it easier to handle errors that occur during asynchronous operations. Instead of using nested callbacks to handle errors, you can use the catch method to handle errors in a more concise and readable way.</li><li><strong>Better performance:</strong> Promises can improve the performance of your code by allowing asynchronous operations to be executed in parallel, instead of blocking the execution of the rest of your code.</li><li><strong>Easy debugging:</strong> Promises make it easier to debug asynchronous code by providing more predictable and consistent error handling. Promises also make it easier to trace the flow of data through your application.</li></ol><h3>Creating a Promise:</h3><figure><img alt="creating a promise" src="https://cdn-images-1.medium.com/max/1024/0*NZoj3_KW_6tWpKVo" /><figcaption>Photo by <a href="https://unsplash.com/@momentance?utm_source=medium&amp;utm_medium=referral">SwapnIl Dwivedi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To create a Promise, we use the Promise constructor function, which takes a single argument, a function that defines the asynchronous operation. The function takes two parameters, resolve and reject, which are functions that can be called to either resolve or reject the Promise.</p><pre>const myPromise = new Promise((resolve, reject) =&gt; {<br>  // Define your asynchronous operation here<br>  // Call resolve() when the operation is successful<br>  // Call reject() when the operation fails<br>});</pre><h3>Using Promise:</h3><p>Once we’ve created a Promise, we can use it to handle asynchronous operations. We do this using the then method, which is called when the Promise is resolved.</p><pre>myPromise.then(result =&gt; {<br>  // Handle the resolved Promise here<br>}).catch(error =&gt; {<br>  // Handle the rejected Promise here<br>});</pre><h3>Example of creating and using a Promise:</h3><figure><img alt="example code" src="https://cdn-images-1.medium.com/max/1024/0*6FWEEDwmxzl7BsOR" /><figcaption>Photo by <a href="https://unsplash.com/@ryland_dean?utm_source=medium&amp;utm_medium=referral">Ryland Dean</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><pre>const myPromiseNumber = new Promise((resolve, reject) =&gt; {<br>   setTimeout(() =&gt; {<br>    const randomNumber = Math.floor(Math.random() * 10);<br>     if (randomNumber &lt; 5) {<br>       resolve(randomNumber);<br>     } else {<br>      reject(new Error(&#39;Number too high&#39;));<br>     }<br>    }, 1000);<br> });<br><br>// Usage<br>myPromiseNumber<br>  .then((result) =&gt; {<br>    console.log(&#39;Task completed successfully:&#39;, result);<br>  })<br>  .catch((error) =&gt; {<br>    console.log(&#39;Task failed with error:&#39;, error.message);<br>  });<br></pre><p>In this example, the myPromiseNumber is a new Promise that performs an asynchronous task of generating a random number between 0 and 9 after a one-second delay. If the generated number is less than 5, the Promise resolves with the number, and if it&#39;s greater than or equal to 5, the Promise rejects with an error message.</p><p>The Promise is used by chaining the then and catch methods to it. If the Promise resolves successfully, the then method is called with the generated number, and if the Promise rejects with an error, the catch method is called with the error message. This allows you to handle the result of the Promise in a readable and expressive way, and to handle any errors that might occur during the asynchronous task.</p><h3>The Promise API:</h3><figure><img alt="methods" src="https://cdn-images-1.medium.com/max/1024/0*b7w6LCG0WX098LUt" /><figcaption>Photo by <a href="https://unsplash.com/@weareambitious?utm_source=medium&amp;utm_medium=referral">Ambitious Creative Co. - Rick Barrett</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Promise API provides several methods that you can use to interact with Promises:</p><ol><li>Promise.all(iterable): This method takes an iterable of Promises as an input and returns a new Promise that resolves to an array of the results of all the input Promises, in the same order as the input Promises. If any of the input Promises reject, the entire Promise.all() will reject immediately.</li><li>Promise.allSettled(iterable): This method takes an iterable of Promises as an input and returns a new Promise that resolves to an array of objects that describe the outcome of each input Promise. The objects in the array have a status property that is either &quot;fulfilled&quot; or &quot;rejected&quot;, and a value or reason property that contains the result or error of each Promise, respectively.</li><li>Promise.any(iterable): This method takes an iterable of Promises as an input and returns a new Promise that resolves as soon as any of the input Promises resolves, with the value of the first resolved Promise. If all of the input Promises reject, then the returned Promise rejects with an AggregateError containing all of the rejection reasons.</li><li>Promise.race(iterable): This method takes an iterable of Promises as an input and returns a new Promise that resolves or rejects as soon as any of the input Promises resolve or reject.</li><li>Promise.resolve(value): This method returns a new Promise that is resolved with the given value.</li><li>Promise.reject(reason): This method returns a new Promise that is rejected with the given reason.</li></ol><p>In Conclusion, JavaScript Promise is a powerful tool for handling asynchronous operations in web applications. By understanding how Promises work and using them in your code, you can create more efficient and reliable applications.</p><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>Contact Me</h3><p><a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a> | <a href="https://github.com/aquibzahidi">Github</a></p><h3>Build Node.js Apps with reusable components</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*KST-OQLOqbnXFWKr.png" /></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><strong>→ </strong><a href="https://bit.dev/"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h4>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h4><h4>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h4><h4>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h4><h4>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h4><h3>Learn more</h3><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.dev/blog/how-to-reuse-react-components-across-your-projects-l3bhezsg">Bit - Component driven development</a></li><li><a href="https://blog.bitsrc.io/5-ways-to-build-a-react-monorepo-a294b6c5b0ac">5 Ways to Build a React Monorepo</a></li><li><a href="https://bit.dev/blog/how-to-create-a-composable-react-app-with-bit-l7ejpfhc/">How to Create a Composable React App with Bit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b6676d3016a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">JavaScript Promise: A Beginner’s Guide to Asynchronous Operations</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Callback Functions in JavaScript: A Comprehensive Guide]]></title>
            <link>https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a61cdcc3d6</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[callback-function]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 09:39:33 GMT</pubDate>
            <atom:updated>2023-08-11T03:20:25.864Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="callback function" src="https://cdn-images-1.medium.com/max/1024/0*3sqs_wycZUGeJqpT" /></figure><p>In JavaScript, a callback function is a function that is passed as an argument to another function and is executed after some operation has been completed.</p><p>Callbacks allow us to write asynchronous code, where we can continue to execute other code while waiting for a particular event to occur.</p><h3>How Do Callback Functions Work?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ed1ayW60-4yYHki7RaIcyw@2x.jpeg" /></figure><p>Callback functions are used to handle events that may occur at any point in time. By passing a callback function as an argument, we allow the function to call it when necessary.</p><p>For example, we have to execute doSomethingElse function just after logging “Doing something…” which is in function doSomething.</p><pre>function doSomething(callback) {<br>  console.log(&#39;Doing something...&#39;);<br>  callback();<br>}<br><br>function doSomethingElse() {<br>  console.log(&#39;Doing something else...&#39;);<br>}<br><br>doSomething(doSomethingElse);</pre><p>In this example, we define two functions, doSomething and doSomethingElse. The doSomething function takes a callback function as an argument and logs a message to the console. It then calls the callback function. The doSomethingElse function logs a different message to the console.</p><p>Finally, we call the doSomething function and pass in the doSomethingElse function as the callback. When doSomething is called, it logs &quot;Doing something...&quot; to the console and then calls the doSomethingElse function, which logs &quot;Doing something else...&quot; to the console.</p><h3>Real-World Example</h3><p>Another real-world example of using a callback function is when fetching data from a server. In this case, we use a callback function to handle the data once it has been received.</p><pre>function fetchData(url, callback) {<br>  fetch(url)<br>    .then(response =&gt; response.json())<br>    .then(data =&gt; callback(data))<br>    .catch(error =&gt; console.log(error));<br>}<br><br>fetchData(&#39;https://jsonplaceholder.typicode.com/todos/1&#39;, function(data) {<br>  console.log(data);<br>});</pre><p>In this example, we define a function fetchData that takes a URL and a callback function as arguments. The function uses the fetch function to make a network request to the specified URL. Once the data is received, it is converted to JSON and the callback function is called with the data as an argument.</p><p>Finally, we call the fetchData function and pass in a callback function that logs the data to the console. When the data is received from the server, the callback function is called with the data, and the data is logged to the console.</p><h3>Issues with Callback Functions and Solutions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUsQaho6HyVKKMppcK5p3Q@2x.jpeg" /></figure><p>One issue that can arise when using callback functions is the problem of “<strong>callback hell</strong>” or “<strong>pyramid of doom</strong>.” This occurs when you have multiple nested callbacks, making the code difficult to read and understand.</p><p>One solution to this problem is to use <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">promises</a> or <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">async/await</a>, which allow for more structured and readable code.</p><h3>Conclusion</h3><p>Callbacks are a powerful tool in programming, allowing for asynchronous code execution and enabling developers to write more efficient and flexible code.</p><p>However, they can also make code difficult to read and understand, especially when there are multiple nested callbacks.</p><p><a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promises</a> and <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">async/await</a> are two alternatives to using callbacks that can make code more readable and maintainable.</p><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>Contact Me</h3><p><a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a> | <a href="https://github.com/aquibzahidi">Github</a></p><h3>Build Apps with reusable components, just like Lego</h3><figure><a href="https://bit.cloud/"><img alt="" src="https://cdn-images-1.medium.com/max/700/1*mutURvkHDCCgCzhHe-lC5Q.png" /></a></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><strong>→ </strong><a href="https://bit.dev/"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h4>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h4><h4>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h4><h4>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h4><h4>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h4><h3>Learn more</h3><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l3bhezsg">How to reuse React components across your projects</a></li><li><a href="https://blog.bitsrc.io/5-ways-to-build-a-react-monorepo-a294b6c5b0ac">5 Ways to Build a React Monorepo</a></li><li><a href="https://bit.cloud/blog/how-to-create-a-composable-react-app-with-bit-l7ejpfhc">How to Create a Composable React App with Bit</a></li><li><a href="https://bit.dev/blog/sharing-javascript-utility-functions-across-projects-l557lr9k">Sharing JavaScript Utility Functions Across Projects</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a61cdcc3d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Functions in JavaScript: A Comprehensive Guide</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Legendary methods of Array in JavaScript | Part 1 : forEach, find, filter and map]]></title>
            <link>https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a43d1f86522</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Mon, 13 Feb 2023 16:03:45 GMT</pubDate>
            <atom:updated>2023-05-20T11:25:32.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUKIIC1sbrIeP2NmBXynmA@2x.jpeg" /></figure><p>ForEach, Filter, Find, Map, Reduce, Some and Every are all JavaScript array methods that are used to manipulate arrays and perform various operations on them. In this blog, we will take a look at what each of these methods does, how they can be used and why they are useful for web developers.</p><p>In this blog I will discuss forEach, find, filter and map.</p><pre>&lt;style&gt;.libutton { display: flex; flex-direction: column; justify-content: center; padding: 7px; text-align: center; outline: none; text-decoration: none !important; color: #ffffff !important; width: 200px; height: 32px; border-radius: 16px; background-color: #0A66C2; font-family: &quot;SF Pro Text&quot;, Helvetica, sans-serif; } &lt;/style&gt;<br>&lt;a class=&quot;libutton&quot; href=&quot;http://www.linkedin.com/comm/mynetwork/discovery-see-all?usecase=PEOPLE_FOLLOWS&amp;followMember=aquib-afzal&quot; target=&quot;_black&quot;&gt;Follow on LinkedIn&lt;/a&gt;</pre><h3>.forEach 🔁</h3><p>The forEach method allows you to iterate over an array and perform a specific operation on each element in the array. It is similar to the for loop, but it is more concise and easier to use.</p><p>Here’s the syntax for using the forEach method:</p><pre>array.forEach(function(currentValue, index, arr) {<br>  // Your code here<br>});</pre><p>The forEach method takes a callback function as its argument. This callback function will be called once for each element in the array. The callback function takes three arguments:</p><ul><li>currentValue: the current element being processed in the array</li><li>index: the index of the current element</li><li>arr: the array that forEach was called upon</li></ul><p>Here’s an example of using the forEach method to log the name of each product in the products array:</p><pre>let products = [<br>  { name: &#39;🍎&#39;, inStock: true },<br>  { name: &#39;🍌&#39;, inStock: false },<br>  { name: &#39;🥕&#39;, inStock: true },<br>  { name: &#39;🍩&#39;, inStock: true },<br>  { name: &#39;🍆&#39;, inStock: false }<br>];<br><br>products.forEach(function(product) {<br>  console.log(product.name);<br>});<br><br>/*<br>🍎<br>🍌<br>🥕<br>🍩<br>🍆<br>*/</pre><p>In this example, the forEach method is used to iterate over the products array. For each product in the array, the callback function logs the name of the product.</p><h3>.find 🔎</h3><p>The find method is used to find the first element in an array that satisfies a given condition. It takes a callback function as an argument and returns the first element that passes the condition specified in the callback function.</p><p>For example, if you have a 🧑🏻‍💼 list of customers and you want to find the first customer who spent more than $100, you can use the find method.</p><pre>let customers = [<br>  { name: &#39;John Doe&#39;, orderAmount: 50 },<br>  { name: &#39;Jane Doe&#39;, orderAmount: 75 },<br>  { name: &#39;Jim Smith&#39;, orderAmount: 120 },<br>  { name: &#39;Jill Smith&#39;, orderAmount: 95 },<br>  { name: &#39;Jack Johnson&#39;, orderAmount: 75 }<br>];<br><br>let highOrderCustomer = customers.find(customer =&gt; customer.orderAmount &gt; 100);<br>console.log(highOrderCustomer);<br><br>/*<br>{ name: &#39;Jim Smith&#39;, orderAmount: 120 }<br>*/ja</pre><h3>.filter 🔍</h3><p>The filter method is used to create a new array from an existing array, but with only elements that pass a certain test. This test is defined in a callback function that you provide as an argument.</p><p>Let’s say you have a list of 🎥 movies and you want to create a new list that only includes movies that are rated G. You can use the filter method to achieve this:</p><pre>let movies = [<br>  { title: &#39;🐭 The Lion King&#39;, rating: &#39;G&#39; },<br>  { title: &#39;🦖 Jurassic Park&#39;, rating: &#39;PG-13&#39; },<br>  { title: &#39;🚀 Space Jam&#39;, rating: &#39;PG&#39; },<br>  { title: &#39;🏰 Beauty and the Beast&#39;, rating: &#39;G&#39; },<br>  { title: &#39;🦸‍♂️ Shazam!&#39;, rating: &#39;PG-13&#39; }<br>];<br><br>let kidsMovies = movies.filter(movie =&gt; movie.rating === &#39;G&#39;);<br>console.log(kidsMovies);<br><br>/*<br>[<br>  { title: &#39;🐭 The Lion King&#39;, rating: &#39;G&#39; },<br>  { title: &#39;🏰 Beauty and the Beast&#39;, rating: &#39;G&#39; }<br>]<br>*/</pre><p>In this example, the filter method iterates through the movies array and checks each movie&#39;s rating. If a movie is rated G, it gets included in the kidsMovies array.</p><p>.map 🔄</p><p>The map method is used to create a new array from an existing array, by transforming each element in the original array into a new value. The transformation is defined in a callback function that you provide as an argument.</p><p>Example 1: if you have a list of 🔢 numbers and you want to create a new list that contains the square of each number, you can use the map method.</p><pre>let numbers = [1, 2, 3, 4, 5];<br>let squares = numbers.map(number =&gt; number * number);<br>console.log(squares);<br><br>/*<br>[1, 4, 9, 16, 25]<br>*/</pre><p>Example 2: let’s say you have a list of 🍎 apples and you want to create a new list that shows the weight of each apple in grams. You can use the map method to achieve this:</p><pre>let apples = [<br>  { type: &#39;Granny Smith&#39;, weight: 150 },<br>  { type: &#39;Red Delicious&#39;, weight: 120 },<br>  { type: &#39;Golden Delicious&#39;, weight: 130 },<br>  { type: &#39;Fuji&#39;, weight: 140 },<br>  { type: &#39;Gala&#39;, weight: 110 }<br>];<br><br>let appleWeights = apples.map(apple =&gt; apple.weight + &#39;g&#39;);<br>console.log(appleWeights);<br><br>/*<br>[ &#39;150g&#39;, &#39;120g&#39;, &#39;130g&#39;, &#39;140g&#39;, &#39;110g&#39; ]<br>*/</pre><p>In this example, the map method iterates through the apples array and transforms each apple&#39;s weight into a string with the units g. The result is a new array called appleWeights that contains the weights of each apple in grams.</p><ul><li><a href="https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-2-reduce-some-and-every-7f3321876565">Legendary methods of Array in JavaScript | Part 2 : reduce, some and every</a></li><li><a href="https://github.com/aquibzahidi/Advance-NodeJs">GitHub - aquibzahidi/Advance-NodeJs: This repository contains Advance NodeJs concepts and Interview questions</a></li></ul><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>Contact Me</h3><p><a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a> | <a href="https://github.com/aquibzahidi">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a43d1f86522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Legendary methods of Array in JavaScript | Part 2 : reduce, some and every]]></title>
            <link>https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-2-reduce-some-and-every-7f3321876565?source=rss-b34241cd11a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f3321876565</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Aquib Afzal]]></dc:creator>
            <pubDate>Mon, 13 Feb 2023 16:00:37 GMT</pubDate>
            <atom:updated>2023-05-20T11:26:08.770Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_vQPzRQpxaWTUKNlK2cZDg@2x.jpeg" /></figure><p>ForEach, Filter, Find, Map, Reduce, Some and Every are all JavaScript array methods that are used to manipulate arrays and perform various operations on them. In this blog, we will take a look at what each of these methods does, how they can be used and why they are useful for web developers.</p><p>In this blog I will discuss reduce, some, and every.</p><h3>.reduce 🔼</h3><p>The reduce method is used to reduce an array to a single value. This single value can be of any data type, such as a number, string, object, or even another array. The reduce method works by iterating over an array and updating a &quot;running total&quot; with each iteration.</p><p>For example, let’s say you have a list of 💰 expenses and you want to find the total amount spent. You can use the reduce method to achieve this:</p><pre>let expenses = [<br>  { category: &#39;groceries&#39;, amount: 50 },<br>  { category: &#39;entertainment&#39;, amount: 30 },<br>  { category: &#39;transportation&#39;, amount: 20 },<br>  { category: &#39;utilities&#39;, amount: 40 },<br>  { category: &#39;rent&#39;, amount: 1000 }<br>];<br><br>let totalExpense = expenses.reduce((sum, expense) =&gt; sum + expense.amount, 0);<br>console.log(totalExpense);<br>/*<br>1140<br>*/</pre><p>In this example, the reduce method iterates over the expenses array and updates the sum variable with each iteration. The sum variable starts at 0, and with each iteration, the amount of the current expense is added to the sum. The final result is the total amount spent, which is 1140.</p><h3>.some🤔</h3><p>The some method is used to check if at least one element in an array satisfies a certain condition. The condition is defined in a callback function that you provide as an argument. The some method returns true if at least one element in the array satisfies the condition, and false otherwise.</p><p>For example, let’s say you have a list of 📚 books and you want to check if at least one book is rated 5 stars. You can use the some method to achieve this:</p><pre>let books = [<br>  { title: &#39;The Great Gatsby&#39;, stars: 4 },<br>  { title: &#39;To Kill a Mockingbird&#39;, stars: 5 },<br>  { title: &#39;Pride and Prejudice&#39;, stars: 4 },<br>  { title: &#39;The Lord of the Rings&#39;, stars: 5 },<br>  { title: &#39;The Hobbit&#39;, stars: 4 }<br>];<br><br>let hasFiveStarBook = books.some(book =&gt; book.stars === 5);<br>console.log(hasFiveStarBook);<br>/*<br>true<br>*/</pre><p>In this example, the some method iterates over the books array and checks if at least one book has 5 stars. If at least one book has 5 stars, the some method returns true, and if not, it returns false. In this case, the result is true because there is at least one book rated 5 stars.</p><h3>.every 💯</h3><p>The every method is used to check if all elements in an array satisfy a certain condition. The condition is defined in a callback function that you provide as an argument. The every method returns true if all elements in the array satisfy the condition, and false otherwise.</p><p>For example, if you have a list of 🛍️ products and you want to check if all of them are in stock, you can use the every method:</p><pre>let products = [<br>  { name: &#39;🍎&#39;, inStock: true },<br>  { name: &#39;🍌&#39;, inStock: false },<br>  { name: &#39;🥕&#39;, inStock: true },<br>  { name: &#39;🍩&#39;, inStock: true },<br>  { name: &#39;🍆&#39;, inStock: false }<br>];<br><br>let areAllProductsInStock = products.every(product =&gt; product.inStock === true);<br>console.log(areAllProductsInStock);<br>/*<br>false<br>*/</pre><p>The every method iterates over the products array and checks if all products have an inStock value of true. If all products have an inStock value of true, the every method returns true. If at least one product has an inStock value of false, the every method returns false. In this case, the result is false because not all products are in stock.</p><p><a href="https://aquibafzal.medium.com/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Legendary methods of Array in JavaScript | Part 1 : forEach, find, filter and map</a></p><h3>Some Quick Links</h3><p><a href="https://medium.com/@aquibafzal/choosing-the-best-javascript-frontend-framework-for-beginners-a-comparative-analysis-7860e6bb729e">JsFramework</a> | <a href="https://medium.com/bitsrc/clean-code-in-javascript-best-practices-for-readable-and-maintainable-code-375b9792cde0">CleanCode</a> | <a href="https://medium.com/@aquibafzal/browser-local-storage-ce1514cf87fd">LocalStorage</a> | <a href="https://medium.com/bitsrc/optimizing-node-js-performance-with-redis-caching-f509edf33e04">Redis Caching</a> | <a href="https://medium.com/bitsrc/boosting-the-performance-of-node-js-applications-with-the-cluster-module-e55def010186">Node.js Cluster</a> | <a href="https://medium.com/@aquibafzal/legendary-methods-of-array-in-javascript-part-1-foreach-find-filter-and-map-1a43d1f86522">Array Methods</a> | <a href="https://medium.com/bitsrc/understanding-callback-functions-in-javascript-a-comprehensive-guide-30a61cdcc3d6">Callback Function</a> | <a href="https://medium.com/bitsrc/what-is-javascript-promise-and-why-it-is-important-4b6676d3016a">Promise</a> | <a href="https://medium.com/bitsrc/async-await-in-javascript-simplifying-asynchronous-code-39075ea4cd03">Async/Await</a></p><h3>Contact Me</h3><p><a href="https://www.linkedin.com/in/aquib-afzal/">LinkedIn</a> | <a href="https://github.com/aquibzahidi">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f3321876565" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>