<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ben Matt, Jr.</title>
    <description>The latest articles on DEV Community by Ben Matt, Jr. (@jrmatanda).</description>
    <link>https://dev.to/jrmatanda</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F477510%2Ff804e7cc-ff97-41d3-b28f-7534f1569973.jpg</url>
      <title>DEV Community: Ben Matt, Jr.</title>
      <link>https://dev.to/jrmatanda</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jrmatanda"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Wed, 16 Jul 2025 15:16:15 +0000</pubDate>
      <link>https://dev.to/jrmatanda/-109l</link>
      <guid>https://dev.to/jrmatanda/-109l</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k" class="crayons-story__hidden-navigation-link"&gt;What are AI parameters?&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/jrmatanda" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F477510%2Ff804e7cc-ff97-41d3-b28f-7534f1569973.jpg" alt="jrmatanda profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/jrmatanda" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Ben Matt, Jr.
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Ben Matt, Jr.
                
              
              &lt;div id="story-author-preview-content-2694669" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/jrmatanda" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F477510%2Ff804e7cc-ff97-41d3-b28f-7534f1569973.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Ben Matt, Jr.&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 16 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k" id="article-link-2694669"&gt;
          What are AI parameters?
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/chatgpt"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;chatgpt&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/llm"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;llm&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/deeplearning"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;deeplearning&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>llm</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>What are AI parameters?</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Wed, 16 Jul 2025 15:00:20 +0000</pubDate>
      <link>https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k</link>
      <guid>https://dev.to/jrmatanda/understand-ai-parameters-behind-all-modern-llms-h8k</guid>
      <description>&lt;p&gt;We hear a lot about parameters in modern AI models. Every time a highly performant model is released, the next thing everyone wants to know is how many parameters it has. 600 billion? 700 billion? 😋&lt;/p&gt;

&lt;p&gt;It's almost as if the more parameters there are, the better the A.I. model performs (and to some extent, it does).&lt;/p&gt;

&lt;h2&gt;
  
  
  Parametric and Nonparametric learning 🥶
&lt;/h2&gt;

&lt;p&gt;To understand what parameters are and their use within modern LLMs like ChatGPT and Claude, we first need to know how machines learn, because A.I parameters are closely tied to two of the major ways we train A.I model today, which includes parametric and nonparametric techniques. Understanding these two techniques will mark our first step into our understanding of A.I model's parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parametric learning 🧪
&lt;/h2&gt;

&lt;p&gt;When an A.I model resort to parametric learning during training what it does is that it tries to predict an outcome base on a dataset (that constructs its base knowledge), and if the dataset is very large, that first prediction will likely be incorrect, that were the parameters come in; parameters are settings that influence the predictions of AI models, if a prediction is incorrect the parameters are adjusted and the next prediction will be done based on new parameter settings up until we get to a correct prediction, note that this happens during training not in production.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx591g3nsylj0x2jzcys6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx591g3nsylj0x2jzcys6.png" alt="Illustration" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, during training, the LLM takes an input that asks if the next movie starring a female actress will win an Oscar, the LLM then refers to its base knowledge, and makes a prediction based on its parameter settings.&lt;/p&gt;

&lt;p&gt;If the LLM responds with “Yes, the next movie starring a female actress will win an Oscar”, and the movie ended up not making it to the Oscars, next time the prediction will be done with different parameter settings until we start to get more accurate predictions.&lt;/p&gt;

&lt;p&gt;It's like telling the model when it’s wrong and then giving it another try with different parameter settings over and over.&lt;/p&gt;

&lt;p&gt;Keep in mind that the number of parameters is fixed and does not depend on the amount of training data. By the way, ChatGPT and Claude use a parametric approach. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55lctywkgrpf7pmt0qbx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55lctywkgrpf7pmt0qbx.png" alt="Illustration" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a high-level overview that aims to help you understand the inner workings of LLMs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Nonparametric learning 😮
&lt;/h2&gt;

&lt;p&gt;The funny thing about nonparametric learning is that it doesn’t mean that there are no parameters involved! We still resort to parameters, but they aren’t a fixed number of parameters that do not depend on the amount of training data.&lt;/p&gt;

&lt;p&gt;Nonparametric learning refers to a class of machine learning methods where the model structure is not fixed in advance. That is, the model does not assume a predetermined number of parameters. Instead, it learns patterns directly from the data, and its complexity can grow as more data becomes available.&lt;/p&gt;

&lt;p&gt;So what does that mean? How do we make sure our predictions are correct?&lt;/p&gt;

&lt;p&gt;This time, as it relies more on the data it’s provided with, the model will have a more analytical approach, it will be more observing, and it adapts to the structure and size of the training data.&lt;/p&gt;

&lt;p&gt;Example: Having all successful movies (Oscar winning included) starring female actresses as it dataset, the LLM will rely on the shape of the data, the structure on which the data has been form could present properties like the popularity of the actress, how much revenue she generates on average in the movies she was casted in and so on.&lt;/p&gt;

&lt;p&gt;This way, the LLM can assume that in every Oscar-winning movie starring a female actress, the actress had above 70% in popularity and, on average, generated more than $100 million of revenue for the movies she had previously starred in.&lt;/p&gt;

&lt;p&gt;It will then evaluate and filter movies based on those features and try to make more accurate predictions.&lt;/p&gt;

&lt;h1&gt;
  
  
  2 What are parameters?
&lt;/h1&gt;

&lt;p&gt;They are settings that influence an AI model's predictions during training; The better those settings are, the better the predictions.&lt;br&gt;
More parameters don't mean a better AI model; What if those settings do not lead to better predictions? So the quality of the settings determines the quality of the training of the model and the quality of the model itself, and even in that case, we still need a great number of parameters! So finding the right balance is key here! &lt;/p&gt;

&lt;p&gt;That it! You made it this far! Follow me if you want more content like this in your feed! 😋&lt;/p&gt;

&lt;p&gt;Here’s my &lt;a href="https://x.com/JrMatanda" rel="noopener noreferrer"&gt;Twitter/X&lt;/a&gt;  😉&lt;/p&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>llm</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>How I built the most beautiful flutter app</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Fri, 02 Jun 2023 14:21:50 +0000</pubDate>
      <link>https://dev.to/jrmatanda/how-i-built-the-most-beautiful-flutter-app-3o8a</link>
      <guid>https://dev.to/jrmatanda/how-i-built-the-most-beautiful-flutter-app-3o8a</guid>
      <description>&lt;p&gt;Before telling you how I built this app, let me tell you the back story and what it is about!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I built this app?
&lt;/h2&gt;

&lt;p&gt;Since the year 2020, I started feeling more and more unproductive, and as a result? I started feeling more and more anxious. Then I tried countless of habit tracking/productivity apps, seeing the of result I started building an app that really help me reach my goals and build the perfect daily routine! &lt;/p&gt;

&lt;h2&gt;
  
  
  What the app is really about
&lt;/h2&gt;

&lt;p&gt;The first thing I noticed when it comes to building a daily routine is that I was doing it wrong, it was too unrealistic.&lt;/p&gt;

&lt;p&gt;So I started studying famous people's daily routines, people like Elon Musk, Bill Gates or Oprah, because when we think of it they are the ones that inspired countless of books about productivity and habits in general.&lt;/p&gt;

&lt;p&gt;So I created an app that would let you use successful people's daily routines! But not just that you can share your personal daily routine with other users or even use theirs and many more.&lt;/p&gt;

&lt;p&gt;If you're interested in building the most accurate daily routine to improve the quality of your life consider checking this amazing app: &lt;a href="https://play.google.com/store/apps/details?id=com.softwareTools.habitMaster"&gt;https://play.google.com/store/apps/details?id=com.softwareTools.habitMaster&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>productivity</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How NodeJS Interacts with the C/C++ language</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Tue, 07 Mar 2023 20:51:56 +0000</pubDate>
      <link>https://dev.to/jrmatanda/how-nodejs-interacts-with-the-cc-language-11n0</link>
      <guid>https://dev.to/jrmatanda/how-nodejs-interacts-with-the-cc-language-11n0</guid>
      <description>&lt;h2&gt;
  
  
  Why node.js in the first place?
&lt;/h2&gt;

&lt;p&gt;In the era of fast-growing technologies, &lt;code&gt;Node.js&lt;/code&gt; plays a massive role in making enterprises more effective and productive. Here is an example:&lt;/p&gt;

&lt;p&gt;In moving from a monolithic JAVA server architecture to Node.js, NETFLIX improved performance and reduced infrastructure costs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;They reduced the start-up time from 40 minutes to 1 minute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They reduced the number of EC2 instances of &lt;code&gt;Node&lt;/code&gt; compared with the legacy JAVA stack by 75% while serving the same number of subscribers at lower latencies.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Node.js is great at building fast network applications that scale. Using node.js, you'll be able to handle a vast number of connections simultaneously with high throughput, which equates to high scalability. Understanding how &lt;code&gt;Node.js&lt;/code&gt; works under the hood will help you enhance the quality of your following &lt;code&gt;Node.js&lt;/code&gt; applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do nodeJS take its superpower from?
&lt;/h2&gt;

&lt;p&gt;Well, Node.js takes the best out of C and C++ languages as they are part of the fastest and most used low-level languages out there, but how are such interactions made possible?&lt;br&gt;
For that, we need to examine both the V8 &lt;/p&gt;

&lt;h3&gt;
  
  
  The v8 project:
&lt;/h3&gt;

&lt;p&gt;The V8 project is a JAVASCRIPT engine created by Google to enable JAVASCRIPT code to run outside the browser, primarily built to run inside the Chrome browser. The cool thing is that the V8 engine is independent of the browser that runs it. This key feature enabled the rise of Node.js. The V8 engine was the technology built to be the engine that powered Node.js back in 2009. As the popularity of Node.js exploded, V8 became the engine that now powers an incredible amount of server-side code written in JAVASCRIPT.&lt;/p&gt;

&lt;p&gt;The Node.js ecosystem is enormous thanks to the V8 engine that also powers desktop applications with projects like Electron.&lt;/p&gt;

&lt;h3&gt;
  
  
  The libuv project:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Libuv&lt;/strong&gt; is the C library that implements the Node.js event loop, the asynchronous behaviors, and worker threads. It also gives Node access to the operating system, and as a result, actions like interacting with the file system and accessing device information are now possible.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;V8&lt;/strong&gt; engine and the &lt;strong&gt;Libuv&lt;/strong&gt; library are with &lt;strong&gt;C&lt;/strong&gt; and &lt;strong&gt;C++&lt;/strong&gt; programs. So the purpose of Node is to provide you with an API for accessing functionalities implemented inside &lt;strong&gt;V8&lt;/strong&gt; and &lt;strong&gt;Libuv&lt;/strong&gt;. See the diagram below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hOQt98VX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kinausc6xmm63zv7mf1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hOQt98VX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kinausc6xmm63zv7mf1.png" alt="diagram" width="572" height="662"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A closer look at this relation would look a bit different. The following diagram introduces a new concept called native extensions, more on that later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--asppr71W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdprjyr63n51c8td8p53.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--asppr71W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdprjyr63n51c8td8p53.png" alt="diagram" width="680" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node.js interaction with other languages such as C and C++ is made possible by the &lt;strong&gt;AddOn&lt;/strong&gt; and &lt;strong&gt;FFI&lt;/strong&gt;(foreign function interface) technologies. Let have a look at them!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are addOns?
&lt;/h2&gt;

&lt;p&gt;in &lt;strong&gt;C++&lt;/strong&gt; that give Node.js access to specific functionalities. We can load them using the &lt;code&gt;require()&lt;/code&gt; function just like any Node.js module out there! &lt;strong&gt;AddOns&lt;/strong&gt; are a bridge between &lt;strong&gt;Javascript&lt;/strong&gt; and C++ libraries.&lt;/p&gt;

&lt;p&gt;Some of the common ways of implementing addons are Node-API, direct use of internal V8.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When not using Node-API, implementing addons is complicated, involving knowledge of several components and APIs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is a foreign functions interface (FFI)?
&lt;/h2&gt;

&lt;p&gt;Foreign Function Interfaces are ways to call into native code from a higher-level language. Among all the reasons for resorting to native code, performance is the most important.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎉🎉🎉 Thank you for reading the third part of this article! 🎉🎉🎉
&lt;/h2&gt;

&lt;p&gt;And if you want more in depth knowledge about your favorite programming languages find me on &lt;a href="https://twitter.com/JrMatanda"&gt;Twitter&lt;/a&gt; as well😃.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Do you really understand JS functions? (part 1)</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Mon, 01 Aug 2022 14:40:00 +0000</pubDate>
      <link>https://dev.to/jrmatanda/do-you-really-understand-js-functions-part-1-4g0k</link>
      <guid>https://dev.to/jrmatanda/do-you-really-understand-js-functions-part-1-4g0k</guid>
      <description>&lt;p&gt;As the book Effective JavaScript put it, “functions are JavaScript’s workhorse”, and one of the reasons I think that’s true is that while other languages resort to different techniques to manipulate data, JS functions alone plays the role of: procedures, methods, constructors, and even classes and modules. So having a deep understanding of JS functions and knowing how to use them effectively in different context will help you master a significant portion of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the difference between Function, Method, and constructor calls in JS?
&lt;/h2&gt;

&lt;p&gt;In other languages that uses OOP we know that functions, methods, and class constructor or three different things, but in JavaScript they are just different patterns of one single construct: &lt;strong&gt;functions&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;serverListen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`The server is listening at &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;```



## Methods

Meanwhile, methods in JavaScript are just functions that happen to be object properties.



```&lt;/span&gt;&lt;span class="nx"&gt;javascript&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;startServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;serverConnexion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;databaseName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serverPort&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`The server has started listening on port: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;serverPort&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;

    &lt;span class="na"&gt;databaseName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auth_db&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;serverPort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4937&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startServer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// The server has started listening on port: 4937&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
javascript&lt;br&gt;
But using the this keyword on a nonmethod function is mostly unnecessary as it it would refer to the global object(or window object):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function runServer(){
    return `The server is listening on port: ${this.serverPort}`
 }

console.log(runServer()); // The server is listening on port: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since there is no &lt;code&gt;serverPort&lt;/code&gt; property on the global object it will be set to &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A good practice in order to quickly catch this kind of mistakes is the use of &lt;strong&gt;ES15&lt;/strong&gt;’s strict mode that sets the default binding of &lt;code&gt;this&lt;/code&gt; to &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
 &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;runServer&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 👈&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`The server is listening at port: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serverPort&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;runServer&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// error: cannot read property "serverPort" of undefined&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Constructors
&lt;/h2&gt;

&lt;p&gt;Unlike functions a constructor passes a brand-new object as the value of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;UserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;UserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@#*&amp;amp;*87*#IOI*&amp;amp;^&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;will@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// will@gmail.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The primary goal of a constructor call is to initialize an object, using the new keyword we are able to return a new Object.&lt;/p&gt;

&lt;h1&gt;
  
  
  Thank you if you've read this far! 🎉🎉🎉
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Don't forget to follow me if you want to read the upcoming episodes 😉
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://twitter.com/JrMatanda"&gt;Follow me on tweeter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>The truth about Event Loop 🍦 (Part 1)</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Thu, 09 Sep 2021 21:51:23 +0000</pubDate>
      <link>https://dev.to/jrmatanda/the-truth-about-event-loop-part-1-2l31</link>
      <guid>https://dev.to/jrmatanda/the-truth-about-event-loop-part-1-2l31</guid>
      <description>&lt;p&gt;JavaScript  was  designed  as  an  embedded  scripting  language.  JavaScript  programs  do  not  run  as  stand-alone applications,  but  as scripts  in  the  context  of  a  larger  application.  The  flagship  example is,  of  course,  the  web  browser.  A  browser  can  have  many  windows and  tabs  running  multiple  web  applications,  each  responding  to  various  inputs  and  stimuli:  user  actions  via  keyboard,  mouse,  or touch, the arrival of data from the network, or timed alarms. These &lt;br&gt;
events  can  occur  at  any  point—even  simultaneously—during  the lifetime of a web application. And for each kind of event, the application may wish to be notified of information and respond with custom &lt;br&gt;
behavior.&lt;br&gt;
JavaScript’s  approach  to  writing  programs  that  respond  to  multiple concurrent events is remarkably user-friendly and powerful, using a &lt;br&gt;
combination of a simple execution model, sometimes known as event-&lt;br&gt;
queue  or  event-loop  concurrency,  with  what  are  known  as  asynchronous APIs. Thanks to the effectiveness of this approach, as well as the &lt;br&gt;
fact  that  JavaScript  is  standardized  independently  of  web  browsers, JavaScript is used as the programming language for a variety of other &lt;br&gt;
applications,  from  desktop  applications  to  server-side  frameworks such as Node.js.&lt;br&gt;
Curiously, the ECMAScript standard has, to date, never said a word &lt;br&gt;
about  concurrency.  Consequently,  this  chapter  deals  with  “de  facto” characteristics of JavaScript rather than the official standard. Nevertheless,  most  JavaScript  environments  share  the  same  approach  to concurrency, and future versions of the standard may standardize on &lt;br&gt;
this widely implemented execution model. Regardless of the standard, &lt;br&gt;
working with events and asynchronous APIs is a fundamental part of &lt;br&gt;
programming in JavaScript.&lt;/p&gt;
&lt;h2&gt;
  
  
  Don't block the Event queue on I/O 🥞
&lt;/h2&gt;

&lt;p&gt;JavaScript programs are structured around events: inputs that may &lt;br&gt;
come  in  simultaneously  from  a  variety  of  external  sources,  such  as interactions from a user (clicking a mouse button, pressing a key, or touching a screen), incoming network data, or scheduled alarms. In &lt;br&gt;
some languages, it’s customary to write code that waits for a particular input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;downloadSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://example.com/file.txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The console.log API is a common utility in JavaScript platforms for &lt;br&gt;
printing  out  debugging  information  to  a  developer  console.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Functions  such  as  &lt;code&gt;downloadSync&lt;/code&gt;  are  known  as  synchronous,  or  blocking:&lt;br&gt;
The program stops doing any work while it waits for its input in this case, the result of downloading a file over the internet. Since the computer could be doing other useful work while it waits for the download to  complete,  such  languages  typically  provide  the  programmer  with a way to create multiple threads: subcomputations that are executed &lt;br&gt;
concurrently,  allowing  one  portion  of  the  program  to  stop  and  wait for (“block on”) a slow input while another portion of the program can carry on usefully doing independent work.&lt;/p&gt;

&lt;p&gt;In  JavaScript,  most  I/O  operations  are  provided  through  asynchronous,  or  nonblocking  APIs.  Instead  of  blocking  a  thread  on  a  result, the  programmer  provides  a  callback  (see  Item  19)  for  the  system  to invoke once the input arrives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;downloadAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://example.com/file.txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rather than blocking on the network, this API initiates the download process and then immediately returns after storing the callback in an internal  registry.  At  some  point  later,  when  the  download  ha s  completed, the system calls the registered callback, passing it the text of the downloaded file as its argument.&lt;br&gt;
Now, the system does not just jump right in and call the callback the instant  the  download  completes.  JavaScript  is  sometimes  described as providing a run-to-completion guarantee: Any user code that is currently  running  in  a  shared  context,  such  as  a  single  web  page  in  a browser,  or  a  single  running  instance  of  a  web  server,  is  allowed  to finish  executing  before  the  next  event  handler  is  invoked.  In  effect, the system maintains an internal queue of events as they occur, and invokes any registered callbacks one at a time.&lt;/p&gt;

&lt;p&gt;The image below shows an illustration of example event queues in client-side and  server-side  applications.  As  events  occur,  they  are  added  to  the end  of  the  application’s  event  queue  (at  the  top  of  the  diagram).  The JavaScript  system  executes  the  application  with  an  internal  event loop, which plucks events off of the bottom of the queue—that is, in the order in which they were received—and calls any registered Java Script event handlers (callbacks like the one passed to &lt;code&gt;downloadAsync&lt;/code&gt; above) one at a time, passing the event data as arguments to the handlers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://firebasestorage.googleapis.com/v0/b/code-rainbow.appspot.com/o/blog-posts%2Feventloop%2Feventloop.png?alt=media&amp;amp;token=fda025de-f154-4d66-a062-cdd92cc8949c" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fcode-rainbow.appspot.com%2Fo%2Fblog-posts%252Feventloop%252Feventloop.png%3Falt%3Dmedia%26token%3Dfda025de-f154-4d66-a062-cdd92cc8949c" alt="event loop diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example event queues in a) a web client application and &lt;br&gt;
b) a web server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The benefit of the run-to-completion guarantee is that when your code runs,  you  know  that  you  have  complete  control  over  the  application state: You never have to worry that some variable or object property will change out from under you due to concurrently executing code. This  has  the  pleasant  result  that  concurrent  programming  in  Java-Script tends to be much easier than working with threads and locks in languages such as C++, Java, or C#.&lt;/p&gt;

&lt;p&gt;Conversely,  the  drawback  of  run-to-completion  is  that  any  and  all code  you  write  effectively  holds  up  the  rest  of  the  application  from proceeding.  In  interactive  applications  like  the  browser,  a  blocked event handler prevents any other user input from being handled and can even prevent the rendering of a page, leading to an unresponsive user  experience.  In  a  server  setting,  a  blocked  handler  can  prevent other network requests from being handled, leading to an unresponsive server.&lt;/p&gt;

&lt;p&gt;The  single  most  important  rule  of  concurrent  JavaScript  is  never  to use  any  blocking  I/O  APIs  in  the  middle  of  an  application’s  event queue.  In  the  browser,  hardly  any  blocking  APIs  are  even  available, although  a  few  have  sadly  leaked  into  the  platform  over  the  years. The &lt;code&gt;XMLHttpRequest&lt;/code&gt; library, which provides network I/O similar to the &lt;code&gt;downloadAsync&lt;/code&gt; function above, has a synchronous version that is considered bad form. Synchronous I/O has disastrous consequences for the interactivity of a web application, preventing the user from interacting with a page until the I/O operation completes.&lt;/p&gt;

&lt;p&gt;By contrast, asynchronous APIs are safe for use in an event-based setting, because they force your application logic to continue processing in a separate “turn” of the event loop. In the examples above, imagine that it takes a couple of seconds to download the URL. In that time, an enormous number of other events may occur. In the synchronous implementation,  those  events  would  pile  up  in  the  event  queue,  but the event loop would be stuck waiting for the JavaScript code to finish executing, preventing the processing of any other events. But in the asynchronous version, the JavaScript code registers an event handler and  returns  immediately,  allowing  other  event  handlers  to  process intervening events before the download completes&lt;/p&gt;

&lt;p&gt;In  settings  where  the  main  application’s  event  queue  is  unaffected, blocking operations are less problematic. For example, the web platform  provides  the  Worker  API,  which  makes  it  possible  to  spawn concurrent computations. Unlike conventional threads, workers are  executed  in  a  completely  isolated  state,  with  no  access  to  the global  scope  or  web  page  contents  of  the  application’s  main  thread, so they cannot interfere with the execution of code running in from the main event queue. In a worker, using the synchronous variant of &lt;code&gt;XMLHttpRequest&lt;/code&gt; is less problematic; blocking on a download does prevent the Worker from continuing, but it does not prevent the page from rendering  or  the  event  queue  from  responding  to  events.  In  a  server setting,  blocking  APIs  are  unproblematic  during  startup,  that  is, before the server begins responding to incoming requests. But when &lt;br&gt;
servicing requests, blocking APIs are every bit as catastrophic as in the event queue of the browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things to Remember  🧠
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Asynchronous APIs take callbacks to defer processing of expensive 
operations and avoid blocking the main application.&lt;/li&gt;
&lt;li&gt;JavaScript  accepts  events  concurrently  but  processes  event  handlers sequentially using an event queue.&lt;/li&gt;
&lt;li&gt;Never use blocking I/O in an application’s event queue&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Master Objects in JS 🍨 (Part 3)</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Wed, 08 Sep 2021 09:12:01 +0000</pubDate>
      <link>https://dev.to/jrmatanda/master-objects-in-js-part-3-4m9j</link>
      <guid>https://dev.to/jrmatanda/master-objects-in-js-part-3-4m9j</guid>
      <description>&lt;h2&gt;
  
  
  Make your Constructors new-Agnostic 🏗️
&lt;/h2&gt;

&lt;p&gt;When you create a constructor such as the User function, you rely on callers to remember to call it with the new operator. Notice how the function assumes that the receiver is a brand-new object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a caller forgets the new keyword, then the function’s receiver&lt;br&gt;&lt;br&gt;
becomes the global object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baravelli&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;d8b74df393528d51cd19980ae0aa028e&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;u&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "baravelli"&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "d8b74df393528d51cd19980ae0aa028e"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Not only does the function uselessly return undefined, it also disas-&lt;br&gt;
trously creates (or modifies, if they happen to exist already) the global&lt;br&gt;
variables name and passwordHash.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the User function is defined as ES5 strict code, then the receiver&lt;br&gt;&lt;br&gt;
defaults to undefined:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baravelli&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;d8b74df393528d51cd19980ae0aa028e&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// error: this is undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this case, the faulty call leads to an immediate error: The first line&lt;br&gt;
of User attempts to assign to this.name, which throws a TypeError. So,&lt;br&gt;
at least with a strict constructor function, the caller can quickly dis-&lt;br&gt;
cover the bug and fix it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Still, in either case, the User function is fragile. When used with new&lt;br&gt;
it works as expected, but when used as a normal function it fails. A&lt;br&gt;
more robust approach is to provide a function that works as a con-&lt;br&gt;
structor no matter how it’s called. An easy way to implement this is to&lt;br&gt;
check that the receiver value is a proper instance of User:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, the result of calling User is an object that inherits from &lt;code&gt;User.prototype&lt;/code&gt;, regardless of whether it’s called as a function or as a constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baravelli&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;d8b74df393528d51cd19980ae0aa028e&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baravelli&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;d8b74df393528d51cd19980ae0aa028e&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One downside to this pattern is that it requires an extra function call, so it is a bit more expensive. It’s also hard to use for variadi c functions, since there is no straightforward analog to the apply method for calling variadic functions as constructors. A somewhat more exotic approach makes use of &lt;strong&gt;ES5&lt;/strong&gt;’s &lt;code&gt;Object.create&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Object.create&lt;/code&gt; takes a prototype object and returns a new object that inherits from it. So when this version of User is called as a function, the result is a new &lt;strong&gt;object&lt;/strong&gt; inheriting from &lt;code&gt;User.prototype&lt;/code&gt;, with the name and passwordHash properties initialized.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While Object.create is only available in ES5, it can be approximated&lt;br&gt;
in older environments by creating a local constructor and instantiat-&lt;br&gt;
ing it with new:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that this only implements the &lt;strong&gt;single-argument&lt;/strong&gt; version of &lt;code&gt;Object.create&lt;/code&gt;. The real version also accepts an optional second &lt;strong&gt;argument&lt;/strong&gt; that describes a set of &lt;strong&gt;property&lt;/strong&gt; descriptors to define on the new &lt;strong&gt;object&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What happens if someone calls this new version of User with new?&lt;br&gt;
Thanks to the constructor override pattern, it behaves just like it does with a function call. This works because JavaScript allows the result of a new expression to be overridden by an explicit return from a constructor function. When User returns self, the result of the new expression becomes self, which may be a different object from the one bound to this.&lt;/p&gt;

&lt;p&gt;Protecting a constructor against misuse may not always be worth the trouble, especially when you are only using a constructor locally.&lt;br&gt;
Still, it’s important to understand how badly things can go wrong if a constructor is called in the wrong way. At the very least, it’s important to document when a constructor function expects to be called with new, especially when sharing it across a large codebase or from a shared library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things to Remember 🧠
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Make a &lt;strong&gt;constructor&lt;/strong&gt; &lt;strong&gt;agnostic&lt;/strong&gt; to its caller’s syntax by reinvoking itself with new or with &lt;code&gt;Object.create&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Document clearly when a function expects to be called with new.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  🎉🎉🎉 Thank you for reading the third part of this article! 🎉🎉🎉
&lt;/h2&gt;

&lt;p&gt;And if you want more in depth knowledge about your favorite programming languages checkout my personal &lt;a href="https://code-rainbow.vercel.app/"&gt;blog&lt;/a&gt; to become an on demand developer 😉, and you can find me on &lt;a href="https://twitter.com/JrMatanda"&gt;twitter&lt;/a&gt; as well😃.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Master objects in JS 🍨 (Part 2)</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Mon, 06 Sep 2021 21:23:10 +0000</pubDate>
      <link>https://dev.to/jrmatanda/master-objects-in-js-part-2-2fnn</link>
      <guid>https://dev.to/jrmatanda/master-objects-in-js-part-2-2fnn</guid>
      <description>&lt;h2&gt;
  
  
  Objects and Prototypes
&lt;/h2&gt;

&lt;p&gt;Like many &lt;strong&gt;object-oriented&lt;/strong&gt; languages, JavaScript provides support for implementation inheritance: the reuse of code or data through a dynamic delegation mechanism. But unlike many conventional languages, &lt;strong&gt;JavaScript&lt;/strong&gt;’s inheritance mechanism is based on prototypes rather than classes. For many programmers, &lt;strong&gt;JavaScript&lt;/strong&gt; is the first object-oriented language they encounter without classes.&lt;/p&gt;

&lt;p&gt;In many languages, every object is an instance of an associated class, which provides code shared between all its instances. &lt;strong&gt;JavaScript&lt;/strong&gt;, by contrast, has no built-in notion of classes. Instead, objects inherit from other objects. Every object is associated with some other object, known as its prototype. Working with prototypes can be different from classes, although many concepts from traditional object-oriented languages still carry over.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand the difference between &lt;code&gt;prototype&lt;/code&gt;, &lt;code&gt;getPrototypeOf&lt;/code&gt; and &lt;code&gt;__proto__&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Prototypes involve three separate but related accessors, all of which are named with some variation on the word prototype. This unfortunate overlap naturally leads to quite a bit of confusion. Let’s get straight to the point.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;C.prototype&lt;/code&gt; is used to establish the &lt;strong&gt;prototype&lt;/strong&gt; of &lt;strong&gt;objects&lt;/strong&gt; created by new C().&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Object.getPrototypeOf(obj)&lt;/code&gt; is the standard &lt;strong&gt;ES5&lt;/strong&gt; mechanism for retrieving &lt;code&gt;obj&lt;/code&gt;’s prototype object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;obj.__proto__&lt;/code&gt; is a nonstandard mechanism for retrieving &lt;code&gt;obj&lt;/code&gt;’s &lt;strong&gt;prototype&lt;/strong&gt; object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To understand each of these, consider a typical definition of a JavaScript datatype. The User constructor expects to be called with the new operator and takes a name and the hash of a password string and&lt;br&gt;
stores them on its created object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;[User &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkPassword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sfalken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0ef33ae791068ec64b502d6cb0191387&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The User &lt;strong&gt;function&lt;/strong&gt; comes with a default &lt;strong&gt;prototype&lt;/strong&gt; property, containing an &lt;strong&gt;object&lt;/strong&gt; that starts out more or less empty. In this example, we add two methods to the &lt;code&gt;User.prototype&lt;/code&gt; object: &lt;code&gt;toString&lt;/code&gt; and &lt;code&gt;checkPassword.&lt;/code&gt; When we create an instance of User with the new operator, the resultant object u gets the object stored at &lt;code&gt;User.prototype&lt;/code&gt;&lt;br&gt;
automatically assigned as its &lt;strong&gt;prototype object&lt;/strong&gt;. The image below shows a diagram of these objects&lt;/p&gt;

&lt;p&gt;Notice the arrow linking the instance object u to the prototype object&lt;br&gt;
&lt;code&gt;User.prototype&lt;/code&gt;. This link describes the inheritance relationship.&lt;br&gt;
Property lookups start by searching the &lt;code&gt;object&lt;/code&gt;’s &lt;code&gt;own properties&lt;/code&gt;; for example, u.name and &lt;code&gt;u.passwordHash&lt;/code&gt; return the current values of immediate properties of u. Properties not found directly on u are looked up in u’s prototype. Accessing &lt;code&gt;u.checkPassword&lt;/code&gt;, for example, retrieves a method stored in &lt;code&gt;User.prototype&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This leads us to the next item in our list. Whereas the &lt;strong&gt;prototype&lt;/strong&gt; property of a constructor function is used to set up the &lt;strong&gt;prototype&lt;/strong&gt; relationship of new instances, the ES5 function &lt;code&gt;Object.getPrototypeOf()&lt;/code&gt; can&lt;br&gt;
be used to retrieve the prototype of an existing object. So, for example, after we create the object u in the example above, we can test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPrototypeOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://firebasestorage.googleapis.com/v0/b/code-rainbow.appspot.com/o/blog-posts%2Fjs%20objects%2FDiagram.png?alt=media&amp;amp;token=80eceac8-d133-4bdd-a776-fb0be71f5525" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fcode-rainbow.appspot.com%2Fo%2Fblog-posts%252Fjs%2520objects%252FDiagram.png%3Falt%3Dmedia%26token%3D80eceac8-d133-4bdd-a776-fb0be71f5525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This illustrates the &lt;strong&gt;prototype&lt;/strong&gt; relationships for the User &lt;strong&gt;constructor&lt;/strong&gt; and&lt;br&gt;
&lt;strong&gt;instance&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some environments produce a nonstandard mechanism for retrieving&lt;br&gt;
the &lt;strong&gt;prototype&lt;/strong&gt; of an &lt;strong&gt;object&lt;/strong&gt; via a special &lt;code&gt;__proto__&lt;/code&gt; property. This can&lt;br&gt;
be useful as a stopgap for environments that do not support &lt;strong&gt;ES5&lt;/strong&gt;’s &lt;code&gt;Object.getPrototypeOf&lt;/code&gt;. In such environments, we can similarly test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A final note about &lt;strong&gt;prototype&lt;/strong&gt; relationships: &lt;strong&gt;JavaScript&lt;/strong&gt; programmers will often describe User as a class, even though it consists of little more than a function. Classes in JavaScript are essentially the combination of a constructor function (User) and a &lt;strong&gt;prototype&lt;/strong&gt; &lt;strong&gt;object&lt;/strong&gt; used to share methods between instances of the &lt;strong&gt;class&lt;/strong&gt; (&lt;code&gt;User.prototype&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://firebasestorage.googleapis.com/v0/b/code-rainbow.appspot.com/o/blog-posts%2Fjs%20objects%2Fdiagram2.png?alt=media&amp;amp;token=1b38b56a-86c4-4583-acd3-5377f453690c" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fcode-rainbow.appspot.com%2Fo%2Fblog-posts%252Fjs%2520objects%252Fdiagram2.png%3Falt%3Dmedia%26token%3D1b38b56a-86c4-4583-acd3-5377f453690c"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a conceptual view of the User “class”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The image above provides a good way to think about the User &lt;strong&gt;class&lt;/strong&gt; conceptually. The User &lt;strong&gt;function&lt;/strong&gt; provides a &lt;strong&gt;public constructor&lt;/strong&gt; for the class, and &lt;code&gt;User.prototype&lt;/code&gt; is an internal implementation of the methods shared between instances. Ordinary uses of User and u have no need to access the &lt;strong&gt;prototype&lt;/strong&gt; &lt;strong&gt;object&lt;/strong&gt; directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things to Remember 🧠
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;C.prototype&lt;/code&gt; determines the prototype of objects created by new &lt;code&gt;C()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Object.getPrototypeOf(obj)&lt;/code&gt; is the standard ES5 function for retrieving the &lt;strong&gt;prototype&lt;/strong&gt; of an &lt;strong&gt;object&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;obj.__proto__&lt;/code&gt; is a nonstandard mechanism for retrieving the &lt;strong&gt;prototype&lt;/strong&gt; of an &lt;strong&gt;object&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A class is a &lt;strong&gt;design pattern&lt;/strong&gt; consisting of a &lt;strong&gt;constructor&lt;/strong&gt; &lt;strong&gt;function&lt;/strong&gt; and
an associated &lt;strong&gt;prototype&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prefer &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; to &lt;code&gt;__proto__&lt;/code&gt; 🦄
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ES5&lt;/strong&gt; introduced &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; as the standard &lt;strong&gt;API&lt;/strong&gt; for retrieving an object’s prototype, but only after a number of &lt;strong&gt;JavaScript&lt;/strong&gt; engines had long provided the special &lt;code&gt;__proto__&lt;/code&gt; property for the same purpose. Not all &lt;strong&gt;JavaScript&lt;/strong&gt; environments support this extension, however, and those that do are not entirely compatible. Environments differ, for example, on the treatment of objects with a null prototype. In some environments, &lt;strong&gt;proto&lt;/strong&gt; is inherited from &lt;code&gt;Object.prototype&lt;/code&gt;, so an object with a null prototype has no special &lt;strong&gt;proto&lt;/strong&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// object with no prototype&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;__proto__&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false (in some environments)&lt;/span&gt;
&lt;span class="c1"&gt;// In  others,  __proto__  is  always  handled  specially,  regardless  of  an object’s state:&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// object with no prototype&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;__proto__&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true (in some environments&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wherever &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; is available, it is the more standard and portable approach to extracting prototypes. Moreover, the &lt;code&gt;__proto__&lt;/code&gt; property leads to a number of bugs due to its pollution of&lt;br&gt;
all objects. JavaScript engines that currently support the extension may choose in the future to allow programs to disable it in order to avoid these bugs. Preferring &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; ensures that code will continue to work even if &lt;code&gt;__proto__&lt;/code&gt; is disabled.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;JavaScript&lt;/strong&gt; environments that do not provide the &lt;strong&gt;ES5&lt;/strong&gt; API, it is easy to implement in terms of &lt;code&gt;__proto__&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPrototypeOf&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPrototypeOf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;not an object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This implementation is safe to include in ES5 environments, because it avoids installing the function if &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; already exists.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Things to Remember 🧠
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Prefer the standards-compliant &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; to the non-&lt;br&gt;
standard &lt;code&gt;__proto__&lt;/code&gt; property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; in non-ES5 environments that&lt;br&gt;&lt;br&gt;
support &lt;code&gt;__proto__&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Never modify &lt;code&gt;__proto__&lt;/code&gt; 🍕
&lt;/h2&gt;

&lt;p&gt;The special &lt;strong&gt;proto&lt;/strong&gt; property provides an additional power that &lt;code&gt;Object.getPrototypeOf&lt;/code&gt; does not: the ability to modify an &lt;strong&gt;object&lt;/strong&gt;’s &lt;strong&gt;prototype&lt;/strong&gt; link. While this power may seem innocuous (after all, it’s just another property, right?), it actually has serious implications and should be avoided. The most obvious reason to avoid modifying&lt;br&gt;
&lt;code&gt;__proto__&lt;/code&gt; is portability: Since not all platforms support the ability to&lt;br&gt;
change an &lt;strong&gt;object&lt;/strong&gt;’s &lt;strong&gt;prototype&lt;/strong&gt; you simply can’t write portable code that does it.&lt;/p&gt;

&lt;p&gt;Another reason to avoid modifying &lt;code&gt;__proto__&lt;/code&gt; is performance. All modern &lt;strong&gt;JavaScript&lt;/strong&gt; engines heavily optimize the act of getting and setting &lt;strong&gt;object&lt;/strong&gt; &lt;strong&gt;properties&lt;/strong&gt;, since these are some of the most common operations that JavaScript programs perform. These optimizations are built on the engine’s knowledge of the structure of an object. When you change the object’s internal structure, say, by adding or removing properties to the object or an object in its prototype chain, some of these optimizations are invalidated. Modifying &lt;code&gt;__proto__&lt;/code&gt; actually changes the inheritance structure itself, which is the most destructive change possible. This can invalidate many more optimizations than modifications to ordinary properties.&lt;/p&gt;

&lt;p&gt;But the biggest reason to avoid modifying &lt;code&gt;__proto__&lt;/code&gt; is for maintaining predictable behavior. An object’s prototype chain defines its behavior by determining its set of properties and property values. Modifying an object’s prototype link is like giving it a brain transplant: It swaps the object’s entire inheritance hierarchy. It may be possible to imagine exceptional situations where such an operation could be helpful, but as a matter of basic sanity, an inheritance hierarchy should remain stable.&lt;/p&gt;

&lt;p&gt;For creating new objects with a custom prototype link, you can use &lt;strong&gt;ES5&lt;/strong&gt;’s &lt;code&gt;Object.create&lt;/code&gt;. For environments that do not implement ES5, Item 33 provides a portable implementation of &lt;code&gt;Object.create&lt;/code&gt; that does not rely on &lt;code&gt;__proto__&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things to Remember 🧠
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Never modify an object’s &lt;code&gt;__proto__&lt;/code&gt; property.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Object.create&lt;/code&gt; to provide a custom &lt;strong&gt;prototype&lt;/strong&gt; for new objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  🎉🎉🎉 Thank you for reading the second part this article! 🎉🎉🎉
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Don't forget to checkout the third part of this serie! 🥳 &lt;a href="https://code-rainbow.vercel.app/blog/Master%20Objects%20in%20JS%20%F0%9F%8D%A8%20(Part%203)" rel="noopener noreferrer"&gt;Make your Constructors new-Agnostic&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;And if you want more in depth knowledge about your favorite programming languages checkout my personal &lt;a href="https://code-rainbow.vercel.app/" rel="noopener noreferrer"&gt;blog&lt;/a&gt; to become an on demand developer 😉, and you can find me on &lt;a href="https://twitter.com/JrMatanda" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; as well😃.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>
 Master Objects in JS 🍨 (Part 1)</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Mon, 06 Sep 2021 15:35:48 +0000</pubDate>
      <link>https://dev.to/jrmatanda/master-objects-in-js-part-1-41hk</link>
      <guid>https://dev.to/jrmatanda/master-objects-in-js-part-1-41hk</guid>
      <description>&lt;h2&gt;
  
  
  Objects
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Objects are JavaScript’s fundamental data structure. Intuitively, an object represents a table relating strings to values. But when you dig deeper, there is a fair amount of machinery that goes into objects.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most strongly typed languages such as Java use &lt;code&gt;isEquals()&lt;/code&gt; to check whether two objects&lt;br&gt;
are the same. You may be tempted to simply use the &lt;code&gt;==&lt;/code&gt; operator to check whether two&lt;br&gt;
objects are the same in JavaScript.&lt;br&gt;
However, this will not evaluate to true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstEmptyObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secondEmptyObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="nx"&gt;firstEmptyObject&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;secondEmptyObject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;span class="nx"&gt;firstEmptyObject&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;secondEmptyObject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although these objects are equivalent (same properties and values), they are not&lt;br&gt;
equal. Namely, the variables have different addresses in memory.&lt;br&gt;
This is why most JavaScript applications use utility libraries such as &lt;code&gt;lodash&lt;/code&gt; or&lt;br&gt;
&lt;code&gt;underscore&lt;/code&gt;, which have the &lt;code&gt;isEqual(object1, object2)&lt;/code&gt; function to check two objects&lt;br&gt;
or values strictly. This occurs via implementation of some property-based equality&lt;br&gt;
checking where each property of the object is compared.&lt;br&gt;
In this example, each property is compared to achieve an accurate object equality result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;personOne&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Will&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Owen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;personTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Will&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Owen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;isEquivalent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// arrays of property names&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;aProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getOwnPropertyNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;bProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getOwnPropertyNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// If their property lengths are different, they're different objects&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aProps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;bProps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;aProps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;propName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aProps&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="c1"&gt;// If the values of the property are different, not equal&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// If everything matched, correct&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this would still work for objects that have only a string or a number as the&lt;br&gt;
property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;equivalenceCheck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because functions and arrays cannot simply use the == operator to check for&lt;br&gt;
equality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;function1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;function2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;function1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;function2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints 'false'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although the two functions perform the same operation, the functions have&lt;br&gt;&lt;br&gt;
different addresses in memory, and therefore the equality operator returns false.&lt;br&gt;
The primitive equality check operators, == and ===, can be used only for strings and&lt;br&gt;
numbers. To implement an equivalence check for objects, each property in the object&lt;br&gt;
needs to be checked.&lt;/p&gt;

&lt;p&gt;Now let dig a little bit deeper 😋.&lt;/p&gt;
&lt;h2&gt;
  
  
  Freezing an object 🥶
&lt;/h2&gt;

&lt;p&gt;The first thing you need to know about objects in JavaScript is that they are mutable (meaning they can be changed). That flexibility it one the most powerful things about JavaScript! 🤩 However in order to make your code more robust 💪&lt;/p&gt;

&lt;p&gt;you sometimes need to create objects that are immutable, for example perhaps you use an object to keep track of data that are constant and need to remain constant, in a case like that you need to freeze the object to prevent it from being changed.&lt;/p&gt;

&lt;p&gt;Another common application is in functional programming using such a of paradigm you want to avoid mutating data. let's look at an example of how to freeze an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;courseInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;possScore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;startPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./page1.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let say you want to modify the &lt;code&gt;courseInfo&lt;/code&gt; object, you would write something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;possScore&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// {question: 10, active: true, startPage: "./page1.html"};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we can't access the &lt;code&gt;possScore&lt;/code&gt; property anymore as we deleted it, But let's look at how we would prevent that from happening.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;courseInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;freeze&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;possScore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;startPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./page1.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// Our object is now freezed!🥶&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's do a step by step analysis.&lt;/p&gt;

&lt;p&gt;step 1. We changed &lt;code&gt;courseInfo&lt;/code&gt; variable from let to a constant variable because we don't want it to be reassigned either.&lt;/p&gt;

&lt;p&gt;step 2. We make use of the &lt;code&gt;Object.freeze&lt;/code&gt; static method to prevent all the properties and values of the object from being changed.&lt;/p&gt;

&lt;p&gt;But now how do we check if our &lt;code&gt;courseInfo&lt;/code&gt; is actually frozen? Well you can try to delete or add new things to it but one simple way of doing is to use the &lt;code&gt;isFrozen&lt;/code&gt; method like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isFrozen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// This returns true 😉&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a copy of an object 🧪
&lt;/h2&gt;

&lt;p&gt;One of the problems JavaScript developers usually faces when working with objects is creating a copy of them. This happens because they try to assign the variable that they want to assign a variable X to a variable Y thinking that this would help them in anyway, but the truth is by doing so, we are just using a reference to the original object, as the result when ever the original object is modified the so called "copy" will change as well.&lt;/p&gt;

&lt;p&gt;A simple and efficient way of achieving that task is making use of both the &lt;code&gt;JSON.parse()&lt;/code&gt; and &lt;code&gt;JSON.stringify()&lt;/code&gt; methods like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;courseInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;question&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;possScore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;startPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./page1.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// Create a copy of the courseInfo object&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;copyOfCourseInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Modify the original object&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;question&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// {possScore: 100, active: true, startPage: "./page1.html"};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseInfo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// {question: 10, possScore: 100, active: true, startPage: "./page1.html"};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🎉🎉🎉 Thank you for reading the first part this article! 🎉🎉🎉
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Don't forget to checkout the second part of this serie because we dig even deeper 🥳! &lt;a href="https://code-rainbow.vercel.app/blog/Master%20Objects%20in%20JS%20%F0%9F%8D%A8%20(Part%202)"&gt;JS Objects and Prototypes&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;And if you want more in depth knowledge about your favorite languages checkout my personal &lt;a href="https://code-rainbow.vercel.app/"&gt;blog&lt;/a&gt; to become an on demand developer 😉, and you can find me on &lt;a href="https://twitter.com/JrMatanda"&gt;twitter&lt;/a&gt; as well😃.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Recursion explained 🎉</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Wed, 23 Jun 2021 15:12:35 +0000</pubDate>
      <link>https://dev.to/jrmatanda/recursion-explained-1d45</link>
      <guid>https://dev.to/jrmatanda/recursion-explained-1d45</guid>
      <description>&lt;p&gt;In this article we will break down all the concept you need to know before saying that you fully understand recursion. The goal is to talk about those concepts so that you can come up with your own definition of what recursion is 😋.&lt;/p&gt;

&lt;p&gt;Definition : Recursion is mostly described as a process that calls it self.&lt;br&gt;
It can also be described by a function that calls it self.&lt;/p&gt;

&lt;p&gt;Call Stack : In case we're calling a function or more multiple times in a program, &lt;br&gt;
their is a thing called "Call Stack" that is an actual stack in witch functions are placed &lt;br&gt;
on top of each other in terms of execution,&lt;br&gt;
so the call stack can hold informations about all the functions that are placed on it.&lt;/p&gt;

&lt;p&gt;So when using a recursive function what happen is we keep pushing the same function onto the "Call Stack".&lt;/p&gt;

&lt;p&gt;What's the main structure of a recursive function ? :&lt;/p&gt;

&lt;p&gt;A recursive function has two essential parts wich are the base case and a different input (or function argument). &lt;/p&gt;

&lt;p&gt;1) The base case :&lt;br&gt;
For the base case you can, think of it as a condition that causes the function to stop calling it self, in other words it stops the recursion.&lt;/p&gt;

&lt;p&gt;2) Different input : Everytime a recursive function is being called, we need to make sure that the input aren't the same.&lt;/p&gt;

&lt;p&gt;If one of the two or both are missing the process can resolve in what called a&lt;br&gt;
"Stack overflow" forcing you to spend hours looking for answers on stackoverflow.com 😉.&lt;/p&gt;

&lt;p&gt;Now let play a game!&lt;/p&gt;

&lt;p&gt;The followings are two examples of recursive functions and your goal is to.&lt;br&gt;
1) Find the "base case".&lt;br&gt;
2) Find the the difference input.&lt;br&gt;
3) Leave your answers in the comment section 😋.&lt;/p&gt;

&lt;p&gt;Ex 1:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yDvum4OU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1ppug6yr9jhbq4c6t1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yDvum4OU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1ppug6yr9jhbq4c6t1t.png" alt="Alt Code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ex 2:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f1edB78h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk9x2lm9v356ilg615g6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f1edB78h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk9x2lm9v356ilg615g6.png" alt="Alt Code example"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>react</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>How to remove duplicates from an array in Dart</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Sun, 13 Jun 2021 22:22:15 +0000</pubDate>
      <link>https://dev.to/jrmatanda/how-to-remove-duplicates-from-an-array-in-dart-a5m</link>
      <guid>https://dev.to/jrmatanda/how-to-remove-duplicates-from-an-array-in-dart-a5m</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;removeDuplicates&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toSet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Output: [1,2,3,4]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanations: First we initialized a variable called list to an array that contains some duplicates, then we converted it to a set(as sets can not contain duplicates) and then back to a list.&lt;/p&gt;

&lt;p&gt;Don't forget to follow me if you like tips like this 😉&lt;/p&gt;

</description>
      <category>darklang</category>
      <category>dart</category>
      <category>flutter</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How To Run VS Code In Your Browser
</title>
      <dc:creator>Ben Matt, Jr.</dc:creator>
      <pubDate>Fri, 02 Oct 2020 16:29:00 +0000</pubDate>
      <link>https://dev.to/jrmatanda/how-to-run-vs-code-in-your-browser-n3n</link>
      <guid>https://dev.to/jrmatanda/how-to-run-vs-code-in-your-browser-n3n</guid>
      <description>&lt;p&gt;If you like VS Code then you'll surely like this brand feature on VS Code!&lt;br&gt;
Because yes! You can actually run VS Code on your browser!&lt;br&gt;
And here is how!&lt;/p&gt;

&lt;p&gt;First you need to check this repo : &lt;a href="https://github.com/cdr/code-server"&gt;https://github.com/cdr/code-server&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the official repo to get VS Code in your browser, once you get there you'll just need to copy &amp;amp; past those two command in your command prompt(You need to be administrator or sudo depending on what OS you're currently using).&lt;/p&gt;

&lt;p&gt;First Copy &amp;amp; past this command: curl -fsSL &lt;a href="https://code-server.dev/install.sh"&gt;https://code-server.dev/install.sh&lt;/a&gt; | sh -s -- --dry-run&lt;/p&gt;

&lt;p&gt;Now that you have code-server installed you need to copy &amp;amp; past this one: curl -fsSL &lt;a href="https://code-server.dev/install.sh"&gt;https://code-server.dev/install.sh&lt;/a&gt; | sh&lt;/p&gt;

&lt;p&gt;And after all that you're ready to go!&lt;br&gt;
You just need to tape the following : code-server.&lt;/p&gt;

&lt;p&gt;That will generate a log for you and you should search for this line right here:  HTTP server listening on &lt;a href="http://127.0.0.1:8080"&gt;http://127.0.0.1:8080&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Copy &amp;amp; past that URL in your browser and see the magic!&lt;/p&gt;

&lt;p&gt;This link will take you to a YouTube video that talks about it:&lt;br&gt;
&lt;a href="https://youtu.be/gB1Pg5ge06g"&gt;https://youtu.be/gB1Pg5ge06g&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>chrome</category>
      <category>codeserver</category>
    </item>
  </channel>
</rss>
