<?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 &lt;Andrew Rymaruk /&gt; on Medium]]></title>
        <description><![CDATA[Stories by &lt;Andrew Rymaruk /&gt; on Medium]]></description>
        <link>https://medium.com/@andrewrymaruk?source=rss-ae4424d09906------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*smhRX4v3Wr-DeJAKKSRNVw.png</url>
            <title>Stories by &amp;lt;Andrew Rymaruk /&amp;gt; on Medium</title>
            <link>https://medium.com/@andrewrymaruk?source=rss-ae4424d09906------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:10:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andrewrymaruk/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[TypeScript 6 Beta: Cleaner Code with getOrInsert]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@andrewrymaruk/typescript-6-beta-cleaner-code-with-getorinsert-4ac22f098071?source=rss-ae4424d09906------2"><img src="https://cdn-images-1.medium.com/max/1536/1*Q8ti_iWww1hGvNOlRs5ZBw.png" width="1536"></a></p><p class="medium-feed-snippet">The Microsoft team has announced the beta release of TypeScript 6.0. This version is important because it is the last one based on the&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@andrewrymaruk/typescript-6-beta-cleaner-code-with-getorinsert-4ac22f098071?source=rss-ae4424d09906------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@andrewrymaruk/typescript-6-beta-cleaner-code-with-getorinsert-4ac22f098071?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ac22f098071</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 12:57:09 GMT</pubDate>
            <atom:updated>2026-02-12T12:57:09.317Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Efficient JS Memoization Using map()]]></title>
            <link>https://javascript.plainenglish.io/efficient-js-memoization-using-map-86f1f4735cc?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/86f1f4735cc</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[memo]]></category>
            <category><![CDATA[memoization]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 19:48:32 GMT</pubDate>
            <atom:updated>2023-08-28T00:57:57.657Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Memoization</strong> is a powerful technique in computer science and programming that involves caching the results of expensive function calls and reusing them when the same inputs occur again.</p><p>This technique can significantly improve the performance of programs, particularly in scenarios where functions are called repeatedly with the same arguments.</p><p>In this article, I will show the simple concept of memoization in JavaScript and demonstrate its implementation using the Map() data structure.</p><p>Let’s create a memo function that accepts a function fn as an argument and returns a new function that has memoization capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBveZEtwlFdOAxNaGDNrtw.png" /></figure><p>The join method is used to concatenate the values and types with a separator (|). This minimizes the overhead and provides a more optimized key generation process while still achieving the desired result of treating <strong>different types as distinct inputs</strong>.</p><h3>Understanding Memoization</h3><p><strong>Memoization</strong> is about trading space complexity for time complexity.</p><p>Instead of recalculating the result for a specific set of inputs every time a function is called, we store the result in a cache and return it directly if the same inputs are encountered again.</p><p>This can be especially beneficial for functions that involve heavy computations, recursive calculations, or database queries.</p><h3><strong>Conclusion</strong></h3><p>Memoization can be a game-changer when it comes to optimizing the performance of functions that involve repetitive computations. By utilizing the Map() data structure to store cached results, we can effectively trade memory for faster execution times.</p><p>The memo function presented in this article provides an elegant and reusable way to implement memoization in your JavaScript projects, helping you create more efficient and responsive applications.</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=86f1f4735cc" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/efficient-js-memoization-using-map-86f1f4735cc">Efficient JS Memoization Using map()</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check if two strings are an anagram. JavaScript]]></title>
            <link>https://medium.com/@andrewrymaruk/how-to-check-if-two-strings-are-an-anagram-javascript-6890b871ca25?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/6890b871ca25</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Thu, 15 Sep 2022 08:29:07 GMT</pubDate>
            <atom:updated>2022-09-15T13:02:39.041Z</atom:updated>
            <content:encoded><![CDATA[<p>The definition of an anagram is very simple. A word, phrase, or name formed by rearranging letters.</p><p>Examples of anagram words:</p><ul><li><strong>cinema -&gt; iceman</strong></li><li><strong>listen -&gt; silent</strong></li></ul><p>Let’s write a method to check whether two given strings are <a href="http://en.wikipedia.org/wiki/Anagram">anagram </a>of each other or not.</p><p>Regarding to the examples above we know that an anagram of a string is another string that contains<strong> the same characters. Only one exception is a different order of symbols.</strong></p><p>Out of here, one really easy way to compare just the letters is to sort the strings.</p><p>So let’s begin by making them both lowercase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIkDOG5spak5R6k5-P0fLg.png" /></figure><p>Then we <strong>need to sort the characters</strong> in each string and concatenate the result to form another string for easy comparison.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyPpXM9bI5iuAhw78uajDA.png" /></figure><p>Below is the implementation of the idea:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3bvdY8rR-sPEAcOpqQDSw.png" /></figure><p>You can try edit it by the link below 👇</p><p><a href="https://codesandbox.io/embed/is-anagram-84fqwm?fontsize=14&amp;hidenavigation=1&amp;theme=dark">https://codesandbox.io/embed/is-anagram-84fqwm?fontsize=14&amp;hidenavigation=1&amp;theme=dark</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6890b871ca25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ JS Must-Read. Which JavaScript Books you should read]]></title>
            <link>https://medium.com/front-end-weekly/js-must-read-which-javascript-books-you-should-read-b217bd532c82?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/b217bd532c82</guid>
            <category><![CDATA[rymaruk]]></category>
            <category><![CDATA[book-recommendations]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Sat, 02 May 2020 12:56:07 GMT</pubDate>
            <atom:updated>2020-05-05T05:44:53.822Z</atom:updated>
            <content:encoded><![CDATA[<h3>📖 JS Must-Read. Wich JavaScript Books you should read</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VB_OGEHitV12dyc7" /></figure><p>When I start studying programming I spend a lot of time reading or watching content from various ways to make sure, I have relevant content and practical exercises.</p><p>I try looking to see how well the content meets a few criteria below:</p><ol><li><strong>Popular Technology</strong></li></ol><p>One of the main things for me. If you’ve been following the news on exciting tech trends like <a href="https://medium.com/javascript-in-plain-english/face-detection-just-using-faceapijs-d03d737e87be"><strong>artificial intelligence</strong></a>, then you’re probably aware that emerging technologies are changing the way we work and interact with others.</p><p>2. <strong>Advanced Topics</strong></p><p>This is the coverage of extended topics such as design patterns, data structures &amp; algorithms, immutability, functional programming, etc.</p><p>3. <strong>Explanations</strong></p><p>The terms/concepts well explained.</p><p>4. <strong>Practice</strong></p><p>I like the books which explaining step by step code exercises.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>📖 Eloquent JavaScript, 3rd Edition: A Modern Introduction to Programming by Marijn Haverbeke</h3><p>In my personal opinion, this book is honestly one of the best-structured books.</p><p>The contents of this book can be divided into three parts:<br>1. JavaScript Language<br>2. Browser<br>3. Node</p><blockquote>Like human languages, computer languages allow words and phrases to be combined in new ways, making it possible to express ever new concepts.</blockquote><p><strong>This book will try to make you familiar enough with this language to do useful and amusing things with it.</strong></p><p><a href="https://eloquentjavascript.net/">Eloquent JavaScript</a></p><h3>📖 You Don’t Know Js: this &amp; Object Prototypes by Kyle Simpson.</h3><p>This concise, in-depth guide takes you inside JavaScript’s this structure and object prototypes.</p><p>You’ll learn how they work and why they’re integral to behavior delegation — a design pattern in which objects are linked, rather than cloned.</p><blockquote>No matter how much experience you have with JavaScript, odds are you don’t fully understand the language.</blockquote><p><a href="https://www.oreilly.com/library/view/you-dont-know/9781491905142/">You Don&#39;t Know JS: this &amp; Object Prototypes</a></p><h3>📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings</h3><p>I consider that algorithms it’s fundamental in any language.</p><p><a href="https://github.com/trekhleb/javascript-algorithms">This repository</a> contains JavaScript based examples of many popular algorithms and data structures.</p><p>Each algorithm and data structure has its own separate README with related explanations and links for further reading (including ones to YouTube videos).</p><p><a href="https://github.com/trekhleb/javascript-algorithms">GitHub - trekhleb/javascript-algorithms: 📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings</a></p><h3>📖 Node.js Complete Reference Guide</h3><p>Discover a more sustainable way of writing software with high levels of reusability and collaboration using Node.js.</p><p>Node.js Complete Reference Guide takes you through basic knowledge of JavaScript and server-side development to create, maintain, deploy, and test your Node.js applications.</p><p><a href="https://www.oreilly.com/library/view/nodejs-complete-reference/9781789952117/">Node.js Complete Reference Guide</a></p><h4>Key Features</h4><ul><li>Explore the latest JavaScript features and EcmaScript modules</li><li>Walkthrough different stages of developing robust applications using Node.js 10</li><li>Create rich and scalable RESTful API solutions</li></ul><h3>So, What’s Next?</h3><p>Never stop running!!! Technologies are emerging and evolving all around us. Always look for something new, learn something new, and<a href="https://medium.com/@andrewrymaruk"> be sure to share your experience…</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b217bd532c82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/js-must-read-which-javascript-books-you-should-read-b217bd532c82">📖 JS Must-Read. Which JavaScript Books you should read</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Modules in JavaScript?]]></title>
            <link>https://javascript.plainenglish.io/what-is-javascript-module-90d58a8290b0?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/90d58a8290b0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Wed, 08 Apr 2020 06:48:41 GMT</pubDate>
            <atom:updated>2020-04-12T13:46:34.034Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What</strong> is a <strong>Module </strong>in JavaScript?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ljnWAuUhEYej-FQ2.jpeg" /></figure><p>JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules.</p><h3>What is a module?</h3><p><strong>A module is just a file. One script is one module.</strong></p><p>Modules can load each other and use special directives export and import to interchange functionality</p><ul><li>export keyword labels variables and functions that should be accessible from outside the current module.</li><li>import allows the import of functionality from other modules.</li></ul><p>You may have used a userland JavaScript module system in the past. Maybe you used <a href="https://nodejs.org/docs/latest-v10.x/api/modules.html">CommonJS like in Node.js</a>, or maybe <a href="https://github.com/amdjs/amdjs-api/blob/master/AMD.md">AMD</a>, or maybe something else. All of these module systems have one thing in common: they allow you to <strong>import</strong> and <strong>export</strong> stuff.</p><h3><strong>CommonJS Modules</strong></h3><p>CommonJS is a module pattern proposed to help bring a more familiar syntax to dependency management. The most popular software package that implements the CommonJS Module style code is NodeJS. The following should be very familiar to you if you’ve worked with Node before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34suKiOgIAMWmTM2ovhtIQ.png" /><figcaption>math.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fyGmjUm0LFo1lF2ybn8x3w.png" /><figcaption>calc.js</figcaption></figure><h3>ES6/ES2015 Modules</h3><p>ES6 modules are available through transpilers like <a href="https://babeljs.io/">Babel</a>. It’s a simpler, easier to understand the way of importing/exporting your code. There are a few alerts you need to understand before you can fully utilize the power of ES6 modules.</p><ul><li><strong>Default Export</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGaURM7y_wpvn_ouCbIJaw.png" /></figure><p>This will export the function <strong>foo</strong>, so you can use it like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eo_AuJgza186KVhAV4u-MA.png" /></figure><p>As you can see, you can name it<strong> whatever you want</strong> because the compiler will know to pick the default function from <strong>foo.js</strong></p><ul><li><strong>Named Export</strong></li></ul><p>Named export comes in handy when you have multiple modules you want to export from a single module.</p><p>You can chain named imports like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Mc-JAo64pOMlYGgMpn0eg.png" /></figure><ul><li><strong>Aliased Import</strong></li></ul><p>Sometimes you want to import a module with a different name than what was exported, in that case, you can use the <strong>as</strong> keyword:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBUAvmgQlex7Q0dsPRowuw.png" /></figure><p>Clean and powerful. ES6 modules are used all over modern frontend/backend javascript projects, it is the unofficial standard way of loading javascript.</p><blockquote>I hope you enjoy this article and learned something new about how to use Javascript modules.</blockquote><h3>Must read</h3><ul><li><a href="https://blog.tableflip.io/the-difference-between-module-exports-and-exports/">The difference between module.exports and exports</a></li><li><a href="https://www.penta-code.com/how-javascript-modules-work-from-past-to-present/">How javascript modules work - from past to present</a></li><li><a href="https://www.tutorialsteacher.com/nodejs/nodejs-module-exports">Node.js Export Module</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90d58a8290b0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/what-is-javascript-module-90d58a8290b0">What are Modules in JavaScript?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Face Detection with FaceApiJS  ]]></title>
            <link>https://javascript.plainenglish.io/face-detection-just-using-faceapijs-d03d737e87be?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/d03d737e87be</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javscript]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Fri, 28 Feb 2020 23:42:01 GMT</pubDate>
            <atom:updated>2020-03-05T22:04:15.750Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/816/0*YtsSfrhiF0rCGqEY.png" /><figcaption><a href="https://github.com/rymaruk/app-face-detection">https://github.com/rymaruk/app-face-detection</a></figcaption></figure><p>In this article, we will be setting up real-time <strong>face detection</strong> through a webcam using AI. We will look into a simple code example, that will get you started immediately with the package in just a few lines of code.</p><p><strong>Goals:</strong></p><ul><li>Streaming a webcam through HTML</li><li>Using Face API to detect faces in real-time</li><li>Drawing facial landmarks in real-time</li></ul><p>We will use the <a href="https://github.com/justadudewhohacks/face-api.js/">face-api.js</a> library built on TensorFlow, which implements several <strong>CNN</strong>s <strong>(</strong>Convolutional Neural Networks) to solve face detection, face recognition and face landmark detection, optimized for the web and for mobile devices.</p><p>You can use this library to track and detect a face in real-time.</p><p>Now let’s dive into it 💻…</p><h3>Customize your project</h3><p>Before we start, we need to set up a local development server. It will be enough to use a WebPack dev server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0063e1bc0d2d1a1fc2c2cd8497e750fb/href">https://medium.com/media/0063e1bc0d2d1a1fc2c2cd8497e750fb/href</a></iframe><p>After that, you should add a models in to your project and download the file present at — <a href="https://github.com/WebDevSimplified/Face-Detection-JavaScript/tree/master/models">https://github.com/WebDevSimplified/Face-Detection-JavaScript/tree/master/models</a></p><p>The models will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*JdRuv-T5dCY0AcKNYLdZvg.png" /></figure><p>Create a file index.js inside src folder, that will have all our logic.</p><p><strong>Index.js</strong> will contain only one import statement as <strong>face-api.js </strong>(JavaScript face recognition API for the browser and NodeJS implemented on top of tensorflow.js core).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*GjDS84IbgyCngLKqgeAeRQ.png" /></figure><p>Next, we will define our face-API model URL. Just load models that you are going to use for face detection.</p><blockquote>I use ASYNC function for getting models. This will allow the camera to start immediately after the models have been loaded.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9hEp464-y82PC7PzXE91Fg.png" /></figure><p><strong>MediaDevices.getUserMedia()</strong></p><p>Method prompts the user for permission to use a media input which produces a <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream">MediaStream</a>. That stream can include a video track.</p><blockquote>It returns a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> that resolves to a <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream">MediaStream</a> object. If the user denies permission, or matching media is not available, then the promise is rejected with NotAllowedError or NotFoundError respectively.</blockquote><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia">MediaDevices.getUserMedia()</a></p><h3><strong>Implement camera capture ability to &lt;canvas&gt;</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*Ilau_ksKwNQJ0AeRV5Sqpw.png" /></figure><p>First of all, need to create a Canvas Element from Video Element and initializing display values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*w7glvoPPUNGkLIWRvQDFYA.png" /></figure><h4>MatchDimensions</h4><p>faceapi.matchDimensions — helper function to resize media elements.</p><p>Just pass your “video-canvas” and “displayValues” as arguments</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*XAnB6CnL9cnAvR3QDiAdMQ.png" /></figure><h4>Receive a Full Face Description</h4><p>The neural nets accept HTML image, canvas or video elements or tensors as inputs. To detect all face’s bounding boxes of an input image we simply say:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*yyUP-8XbQwavNLTIQ0BG-g.png" /></figure><p>The returned bounding boxes and landmark positions are relative to the original media size. In case the displayed image size does not correspond to the original image size you can simply resize them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*2o68FWArWu988HPQBAUhHQ.png" /></figure><p>We can visualize the detection results by drawing the bounding boxes into a canvas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*2Lj88ryvp54L6C75CVVv0g.png" /></figure><h3>Source code</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de107da9eeef7cb914dd25c95520d887/href">https://medium.com/media/de107da9eeef7cb914dd25c95520d887/href</a></iframe><h3><strong>Recommendations</strong></h3><ul><li><a href="https://github.com/WebDevSimplified/Face-Detection-JavaScript">WebDevSimplified/Face-Detection-JavaScript</a></li><li><a href="https://itnext.io/face-api-js-javascript-api-for-face-recognition-in-the-browser-with-tensorflow-js-bcc2a6c4cf07">face-api.js — JavaScript API for Face Recognition in the Browser with tensorflow.js</a></li><li><a href="https://github.com/justadudewhohacks/face-api.js">GitHub - justadudewhohacks/face-api.js: JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js</a></li><li><a href="https://justadudewhohacks.github.io/face-api.js/docs/index.html">face-api.js</a></li><li><a href="https://developers.google.com/web/updates/2015/10/media-devices">Choose Cameras, Microphones and Speakers from Your Web App</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d03d737e87be" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/face-detection-just-using-faceapijs-d03d737e87be">Face Detection with FaceApiJS 📣 😳</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[You need to try NextJS for your next web app.]]></title>
            <link>https://javascript.plainenglish.io/next-javascript-app-just-try-it-8e74bf35e4a7?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e74bf35e4a7</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Sat, 23 Nov 2019 22:55:02 GMT</pubDate>
            <atom:updated>2019-11-24T09:43:23.765Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>👉 You need to try NextJS for your next web app</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rvz24ZkIt-BxU1ep.jpg" /></figure><p><strong>NextJS</strong> is an awesome framework built by <a href="https://zeit.co/">Zeit</a> to create Web Applications. It has many great features and advantages, which can make NextJS your first choice for building your next web application.</p><h3>The main features of NextJS. Look at that 👇</h3><ul><li><strong>Server-Side Rendering</strong></li></ul><p>You can render React components on the server-side, before sending the HTML to the client.</p><ul><li><strong>Automatic Routing (Create Dynamic Pages)</strong></li></ul><p>Any URL is mapped to the filesystem, to files put in the pages folder, and you don&#39;t need any configuration (you have customization options of course).</p><ul><li><strong>Single File Components</strong></li></ul><p>Using styled-jsx, completely integrated as built by the same team, it&#39;s trivial to add styles scoped to the component.</p><ul><li><strong>Ecosystem Compatibility</strong></li></ul><p>Next.js plays well with the rest of the JavaScript, Node, and React ecosystem.</p><ul><li><strong>Automatic Code Splitting</strong></li></ul><p>Pages are rendered with just the libraries and JavaScript that they need, no more. Instead of generating one single JavaScript file containing all the app code, the app is broken up automatically by Next.js in several different resources.</p><p>Next.js does that by analyzing the resources imported.</p><ul><li><strong>Prefetching</strong></li></ul><p>The Link component, used to link together different pages, supports a prefetch prop which <strong>automatically prefetches page resources</strong> (including code missing due to code splitting) <strong>in the background.</strong></p><ul><li><strong>Static Exports</strong></li></ul><p>Static exports: with the next export you can export a fully static site from your application.</p><ul><li><strong>TypeScript Support</strong></li></ul><p>Next.js is written in TypeScript and as such comes with excellent <strong>TypeScript</strong> support :)</p><ul><li><strong>AMP pages</strong></li></ul><p>Yes! Next.js supports hybrid and <a href="https://amp.dev/">AMP</a> only pages (make sure you are using Next.js 8.1 or newer)</p><h3>NextJS vs React</h3><p>NextJS is the React framework. React is a library for building user interfaces. NextJS uses React, a framework for server-rendered React applications.</p><p>What NextJS does is it renders React apps on the server (SSR).</p><p><strong>Two can’t really be compared, because NextJS wraps React, and they basically work together.</strong></p><p>It provides a common structure that allows you to easily build a frontend React application and transparently handles server-side rendering for you.</p><h3>How to install Next.js?</h3><p>We can choose 2 routes now: using create-next-app or the classic approach which involves <a href="https://nextjs.org/docs#quick-start">installing and setting up the NextJS app manually</a>.</p><p>If you’re familiar with <a href="https://flaviocopes.com/react-create-react-app/">create-react-app</a>, create-next-app is the same thing - except it creates a Next app instead of a React app.</p><pre><strong>npx create-next-app</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IrmLCiHKWbBJzWyd6QC3rA.png" /><figcaption>NextJS CLI</figcaption></figure><p>The command asks for the app name, then <strong>creates a new folder for you</strong>, then downloads <strong>all the packages it needs</strong> (react, react-dom, next), as usual installs package.json.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qzn16_M2uAgz6YvdFZK11Q.png" /></figure><p>and you can immediately run the sample app by running npm run dev</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQGHcRyzqYAU-7fmxsbuTQ.png" /></figure><p><strong>This is the recommended way to start a Next.js application, as it gives you structure and sample code to play with.</strong></p><p>There’s more than just that default sample application.</p><p>Also, you can use any of the examples stored at <a href="https://github.com/zeit/next.js/tree/canary/examples">https://github.com/zeit/next.js/tree/canary/examples</a> using the --example option</p><h3><strong>The SSR really works</strong></h3><p>If we create a site using Next.js, the site pages are rendered on the server, which delivers HTML to the browser.</p><p>Let’s make sure.</p><p>Just view the source of the app. Using <strong>Chrome</strong> you can <strong>right-click anywhere</strong> on the page, and press<strong> View Page Source</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyzuWIHxe5h33_D89uz3tQ.png" /></figure><p>We don’t need to set up anything, server-side rendering is already working for us. No configuration unless it’s needed. Automatic hot-code reloading, error reporting, source maps, transpilation for older browsers.</p><h3>Only JavaScript. Everything is a function</h3><p>Every route within Next.js is simply an ES6 module that exports a function or class that extends from React.Component.</p><p>The advantage of this approach over similar models is that your entire system remains highly composable and testable.</p><blockquote>For example, a component can be rendered directly, or be imported and rendered by another top-level component.</blockquote><p>We’ve also made the decision to embrace CSS-in-JS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7drqKql6S0uXW4VBPv2ldg.png" /></figure><h3>Automatic server rendering and code splitting</h3><p>Two tasks are most desirable:</p><ul><li>Server-Side Rendering</li><li>Splitting your app’s build into smaller bundles</li></ul><p>With Next.js, every component inside pages/ gets server-rendered automatically and their scripts inlined.</p><p>When a component is loaded dynamically through &lt;Link prefetch /&gt; or <a href="https://github.com/zeit/next.js/blob/master/readme.md#routing">the router</a>, we fetch a JSON based representation of the page which likewise contains its scripts.</p><p>This means that a certain page could have an extensive list of imports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hz-4ilWCeREbR-eoAskcxA.png" /></figure><h3>Data fetching is up to the developer</h3><p>Server-rendering of static JSX is an important achievement, but real-world applications deal with dynamic data coming from different API calls and network requests.</p><p>Next.js makes a very important extension to the React’s Component contract: getInitialProps.</p><p>A page that fetches some data would look as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hUL0kyCF1u3pX8cYYDE1Iw.png" /></figure><p>As you can see, the contract is very simple and unopinionated: getInitialProps must return a Promise that resolves to a `JavaScript` object, which then populates the component&#39;s props.</p><blockquote>This makes Next.js play well with REST APIs, GraphQL and even global-state management libraries Redux.</blockquote><h3>Simple deployment</h3><p>All it takes to deploy a Next.js app is to run next build followed by next start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0e-vJeh36V4KS5t_IuHbA.png" /></figure><blockquote>In my opinion, it strikes a good balance between flexibility and smart defaults, but it’s certainly not a solution to every problem.</blockquote><h3>Recommendations</h3><ul><li><a href="https://zeit.co/blog/next">Next.js</a></li><li><a href="https://flaviocopes.com/react-create-react-app/">Introduction to create-react-app</a></li><li><a href="https://www.freecodecamp.org/news/the-next-js-handbook/">The Next.js Handbook - Learn Next.js for Beginners</a></li><li><a href="https://blog.logrocket.com/next-js-vs-create-react-app/">Next.js vs. Create React App: Whose apps are more performant? - LogRocket Blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e74bf35e4a7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/next-javascript-app-just-try-it-8e74bf35e4a7">You need to try NextJS for your next web app.</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[What are Blobs used for in JavaScript?]]></title>
            <link>https://javascript.plainenglish.io/javascript-blob-why-is-it-useful-20c372dfca00?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/20c372dfca00</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Wed, 30 Oct 2019 23:02:08 GMT</pubDate>
            <atom:updated>2019-11-13T21:06:13.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Naqy8xyQ09LWFLe-DLziBw.png" /></figure><blockquote>Blobs are a fundamental data type to understand.</blockquote><p><strong>Blob</strong> means “Binary Large Object” and it’s an opaque representation of a chunk of bytes. Web Browsers implement a Blob object, which is responsible for holding data.</p><p>Blobs are used for many things.</p><ul><li>They can be created from content from the network.</li><li>They can be saved to disk or read from a disk.</li><li>They are the underlying data structure for <a href="https://flaviocopes.com/file/">File</a> used in the FileReader API, for example.</li></ul><p>A Blob has its size and <a href="https://en.wikipedia.org/wiki/Media_type#Common_examples"><strong>MIME type</strong></a> just like a file has. Blob data is stored in the memory or filesystem depending on the browser and blob size. A Blob can be used like a file wherever we use files.</p><blockquote>Most APIs for working with blobs are asynchronous.</blockquote><blockquote>But synchronous versions of APIs are also available so that they can be used in WebWorkers.</blockquote><p>Content of a blob can be read as <strong>ArrayBuffer</strong> and therefore it makes blobs very handy to store binary data. Basically <strong>ArrayBuffer</strong> is used to keep binary data. It can be the binary data of an image for example. In other languages, buffers are proved very useful. 🙂 Yes, of course, it is a little difficult to understand or use than other data types.</p><h3>Creating a Blob</h3><p>A blob can be created using:</p><ul><li>the Blob() constructor</li><li>another blob, using the Blob.slice() instance method</li></ul><p>The constructor takes an array of values. Even if you have just one string to put in the blob, you must wrap it in an array.</p><p>When you call slice() you can retrieve a part of the blob.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-custom-blob%3Fembed%3D1%26file%3Dindex.js&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-custom-blob%3Fembed%3D1%26file%3Dindex.js&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/090ee9354a840ec6e4a96c48e3b540c0/href">https://medium.com/media/090ee9354a840ec6e4a96c48e3b540c0/href</a></iframe><p><strong>Once you have a Blob object, you can access its 2 properties:</strong></p><ul><li>size returns the length in bytes of the content of the blob</li><li>type the MIME type associated with it</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vThBNhflwR-y-O6AjGqkQ.png" /></figure><h3>Blob URLs</h3><p>As we have file:// URLs, referencing to a real file in a local filesystem. Similarly, we have blob:// URLs referencing to a blob. blob:// URLs can be used almost wherever we use regular URLs.</p><p>A blob:// URL to a blob can be obtained using the <strong>createObjectURL</strong> object.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-blob-urls%3Fembed%3D1%26file%3Dindex.js&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-blob-urls%3Fembed%3D1%26file%3Dindex.js&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5fd340bed1bab90c688c259277dca1c/href">https://medium.com/media/f5fd340bed1bab90c688c259277dca1c/href</a></iframe><p>The <strong>URL.createObjectURL()</strong> the static method creates a <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString">DOMString</a> containing a URL representing the object given in the parameter.</p><p>A <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString">DOMString</a> containing an object URL that can be used to reference the contents of the specified source object.</p><blockquote>Each time you call createObjectURL(), a new object URL is created, even if you&#39;ve already created one for the same object.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-blob-link%3Fembed%3D1%26file%3Dindex.js&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-blob-link%3Fembed%3D1%26file%3Dindex.js&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f166215b74b46042672a7cd99b04766/href">https://medium.com/media/2f166215b74b46042672a7cd99b04766/href</a></iframe><h3>File Interface</h3><p>A <a href="https://developer.mozilla.org/en-US/docs/Web/API/File"><strong>File</strong></a> object in JavaScript references an actual file in the local filesystem. This File object inherits all properties and methods from the Blob class. Although the File objects and Blob objects are different, they expose the same methods and properties.</p><p>There is no way to create a File object, some JavaScript API return references File objects.</p><p>File objects can be retrieved from a <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileList">FileList</a> object returned as a result of a user selecting files using the &lt;input&gt; element or from a drag and drop operation’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer">DataTransfer</a> object.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-file-interface%3Fembed%3D1%26file%3Dindex.js&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fjs-file-interface%3Fembed%3D1%26file%3Dindex.js&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6970bcdac1ecb9f788b812b7504dd69/href">https://medium.com/media/c6970bcdac1ecb9f788b812b7504dd69/href</a></iframe><p><strong>Conclusion</strong></p><p><strong>Blobs</strong> are very useful while working with binary remote files.</p><p>A blob can be very large i.e., can contain audio and video data too. They can be created dynamically and using blob URLs can be used as files. You can use them in many different ways to make them more useful.</p><p>🙂 <strong>Thanks for reading.</strong></p><h3>Recommendations</h3><ul><li><a href="https://flaviocopes.com/blob/">The Blob Object</a></li><li><a href="http://qnimate.com/an-introduction-to-javascript-blobs-and-file-interface/">An Introduction To JavaScript Blobs and File Interface</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader">FileReader</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob">Blob()</a></li><li><a href="https://www.javascripture.com/Blob">Blob JavaScript API</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20c372dfca00" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/javascript-blob-why-is-it-useful-20c372dfca00">What are Blobs used for in JavaScript?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to edit any web page by activating Design Mode]]></title>
            <link>https://javascript.plainenglish.io/you-can-edit-any-web-page-design-mode-bafdbf2d10e5?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/bafdbf2d10e5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 14:46:12 GMT</pubDate>
            <atom:updated>2019-10-19T11:35:02.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z1rgbCVK6AAUy-81.jpg" /></figure><h4>You can edit any website directly in your browser.</h4><p>If the design mode is enabled, the user can edit the entire contents of the document like in a <strong>WYSIWYG</strong> (What You See Is What You Get) editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NpBRqwNGbwONZm8rMxUUwg.png" /></figure><p>The <strong>designMode</strong> property is not supported by HTML elements, only the editable state of the entire document can be modified with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*UUGOGj5i1GDuBvWl.gif" /></figure><p><strong>If you’ve ever wanted to quickly:</strong></p><ul><li>Show a client how their site should look</li><li>Edit a website so your designer knows what you want</li><li>Make your bank account look like it has $100m in it</li></ul><p>…then the following trick is for you.</p><p>No tech knowledge is needed. No HTML tags appear in the text.</p><h4>Recommendation</h4><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//twitter.com/sulco/status/1177559150563344384&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fpbs.twimg.com%252Fext_tw_video_thumb%252F1177558925463425024%252Fpu%252Fimg%252Fk8hd9W45tAgvkl7P.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/55f3fc8829b1bcf18e70ccb06a270f06/href">https://medium.com/media/55f3fc8829b1bcf18e70ccb06a270f06/href</a></iframe><p><a href="https://hackernoon.com/easily-create-an-html-editor-with-designmode-and-contenteditable-7ed1c465d39b">Easily create an HTML editor with DesignMode and ContentEditable</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bafdbf2d10e5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/you-can-edit-any-web-page-design-mode-bafdbf2d10e5">How to edit any web page by activating Design Mode</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[ Memory leaks and Garbage Collection ️ in JavaScript. You need to know this]]></title>
            <link>https://javascript.plainenglish.io/memory-leaks-and-garbage-collection-%EF%B8%8F-in-javascript-you-need-to-know-this-3fa8173e8b3c?source=rss-ae4424d09906------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fa8173e8b3c</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[<Andrew Rymaruk />]]></dc:creator>
            <pubDate>Sat, 12 Oct 2019 17:46:46 GMT</pubDate>
            <atom:updated>2019-10-13T21:20:07.641Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 Memory leaks and Garbage Collection 🗑️ in JavaScript.</h3><h4>You should know this</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0SgfNK2cbkF9ysDNSehKg.png" /></figure><p>Memory leaks are a problem every developer has to face eventually.</p><h3>What are memory leaks?</h3><p>In essence, memory leaks can be defined as memory that is <strong>not required</strong> by an application anymore that for some reason is not returned to the operating system or the pool of free memory.</p><blockquote>Of course, you can favor different ways of managing memory, and these ways may reduce the chance of leaking memory.</blockquote><blockquote>However, whether a certain piece of memory is unused or not is actually an undecidable problem.</blockquote><h3>Memory Management &amp;&amp; Memory Life Cycle In Javascript 👇</h3><p>We define various primitives, objects, functions, etc. in our program. When we do, the JavaScript engine assigns them a space in the main memory of the device. Different browsers have different techniques to manage their data.</p><p><strong>Memory Life Cycle</strong> In the <strong><em>high-level language</em></strong>, We will just read and write to the memory explicitly (Use Memory). In the <strong><em>low-level language</em></strong>, all three steps the developer needs to take care of explicitly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dv8mEIH-u0NCaMfOj0mAUA.png" /></figure><p>✅ <strong>Allocate memory to the variables.</strong></p><p>✅ <strong>Use the defined variables.</strong></p><p>✅ <strong>Remove them from the memory.</strong></p><blockquote>The reason why we need to understand the concept of memory management while learning any programming language is to prevent memory leaks.</blockquote><blockquote>In any program, memory leaks may lead to several problems, <strong><em>including slow execution, program crashing, high latency</em></strong> (large delays in processing the data), etc.</blockquote><blockquote>💡 The most important task in managing memory is to detect the unused variables in a program and remove them from memory.</blockquote><p>When declaring the variable, Javascript will automatically allocate the memory for the variables</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSjMDOs4hhJ3rrShMlpQ1w.png" /><figcaption>define various primitives</figcaption></figure><p>When the memory is no longer needed anymore, then the allocated memory will be released. Memory leak and most of the memory-related issues come while releasing the memory. The hardest part is finding the memory which is no longer needed and it is tracked down by the <strong>garbage collector</strong>.</p><h3>Garbage Collector 👇</h3><blockquote>The main cause for leaks in garbage collected languages are unwanted references.” via <a href="http://twitter.com/auth0">@auth0</a> <a href="http://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/">http://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/</a></blockquote><p>JavaScript uses Garbage Collector to decide whether a piece of code requires memory or not. Most garbage collectors use an algorithm known as <strong><em>mark-and-sweep</em></strong>.</p><p>In simple terms, the algorithm “<strong><em>mark-and-sweep</em></strong>” consists of the following steps:</p><p>1️⃣ <strong>The garbage collector builds a list of “roots”.</strong></p><p>Roots usually are global variables to which a reference is kept in code. The <strong>window</strong> object is always present, so the garbage collector can consider it and all of its children to be always present (i.e. <strong><em>not garbage</em></strong>).</p><p>2️⃣ <strong>All roots are inspected and marked as active.</strong></p><p>All children are inspected recursively as well. Everything that can be reached from a root <strong><em>is not considered garbage</em></strong>.</p><p>3️⃣<strong> All pieces of memory not marked as active can now be considered garbage.</strong></p><p>The collector can now free that memory and return it to the OS.</p><blockquote>Modern garbage collectors improve on this algorithm in different ways, but the essence is the same: reachable pieces of memory are marked as such and the rest is considered garbage.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAeUCN2lPqL8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAeUCN2lPqL8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAeUCN2lPqL8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd8e9c975ac705b9fb3ab643c30f8b61/href">https://medium.com/media/cd8e9c975ac705b9fb3ab643c30f8b61/href</a></iframe><h3>The Three Types of Common JavaScript Leaks</h3><p>👉 <strong>Accidental global variables</strong></p><p>One of the ways in which JavaScript is permissive is in the way <strong>it handles undeclared variables</strong>: a reference to an undeclared variable creates a new variable inside the global object.</p><p>In the case of browsers, the global object is a “<strong>window</strong>”. For instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*GXfWwppE-CM8w6hDs4Hcdg.png" /></figure><p>but, is in fact</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*Ecg_NpFobehZpbRb7Lu0fw.png" /></figure><p>If <strong>bar</strong> was supposed to hold a reference to a variable only inside the scope of the <strong>someFn</strong> function and you forget to use var to declare it, an unexpected global variable is created.</p><p>To prevent these mistakes from happening, add &#39;<strong>use strict</strong>&#39;; at the beginning of your JavaScript files. This enables a stricter mode of parsing JavaScript that prevents accidental globals.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">Strict mode - JavaScript | MDN</a></p><p>👉 <strong>Forgotten callbacks or timers</strong></p><p>The use of setInterval is quite common in JavaScript. Most of libraries provide observers and other facilities that take callbacks.</p><p>The example below illustrates what can happen with dangling timers: <strong><em>timers that make reference to nodes or data that is no longer required.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*LsSVmmEDvoOwXqzqAI-RWQ.png" /></figure><p>The object represented by node maybe removed in the future, making the whole block inside the interval handler unnecessary. However, the handler, as the interval is still active, cannot be collected (<strong>the interval needs to be stopped for that to happen</strong>).</p><p>If the interval handler cannot be collected, its dependencies cannot be collected either. That means that, someResource which presumably stores sizable data, cannot be collected either.</p><p><strong>For the case of observers</strong>, it is important to make explicit calls to remove them once they are not needed anymore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*czktiYoiaJ7iuBP3Dzhk7g.png" /></figure><p>Frameworks and libraries such as <em>jQuery e.t.c </em>do remove listeners before disposing of a node.</p><p>This is handled internally by the libraries and makes sure that no leaks are produced, even when running under problematic browsers such as 🎃 the old Internet Explorer.</p><p>👉 <strong>Out of DOM references</strong></p><p>Sometimes it may be useful to store DOM nodes inside data structures.</p><p>Suppose you want to rapidly update the contents of several rows in a table. It may make sense to store a reference to each DOM row in a dictionary or array.</p><p>When this happens, two references to the same DOM element are kept: one in the DOM tree and the other in the dictionary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBuxjTKN0n0lrWA2DPuyrA.png" /></figure><p><strong>If at some point in the future you decide to remove these rows, you need to make both references unreachable.</strong></p><p>If you enjoyed this article, please share it with your developer friends and in social media.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*SzlUGhZrzsVCdGYr.gif" /></figure><h3>Recommendation for reading</h3><ul><li><a href="https://medium.com/front-end-weekly/understanding-javascript-memory-management-using-garbage-collection-35ed4954a67f">Understanding JavaScript Memory Management using Garbage Collection</a></li><li><a href="https://data-flair.training/blogs/javascript-garbage-collection/">JavaScript Garbage Collection - Unravel it with Diagrams &amp; Examples - DataFlair</a></li><li><a href="https://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/">4 Types of Memory Leaks in JavaScript and How to Get Rid Of Them</a></li><li><a href="https://www.geeksforgeeks.org/mark-and-sweep-garbage-collection-algorithm/">Mark-and-Sweep: Garbage Collection Algorithm - GeeksforGeeks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fa8173e8b3c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/memory-leaks-and-garbage-collection-%EF%B8%8F-in-javascript-you-need-to-know-this-3fa8173e8b3c">🧠 Memory leaks and Garbage Collection 🗑️ in JavaScript. You need to know this</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>