<?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: Daniel Joo</title>
    <description>The latest articles on DEV Community by Daniel Joo (@danhjoo7).</description>
    <link>https://dev.to/danhjoo7</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%2F241605%2F49e9500b-3ae1-4271-9c82-97de962d0ec1.jpg</url>
      <title>DEV Community: Daniel Joo</title>
      <link>https://dev.to/danhjoo7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danhjoo7"/>
    <language>en</language>
    <item>
      <title>A quick explanation/example of closure in JS </title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Sat, 11 Apr 2020 19:15:39 +0000</pubDate>
      <link>https://dev.to/danhjoo7/a-quick-explanation-example-of-closure-in-js-2kke</link>
      <guid>https://dev.to/danhjoo7/a-quick-explanation-example-of-closure-in-js-2kke</guid>
      <description>&lt;p&gt;Hope everyone is staying safe and healthy during these crazy times! Just wanted to briefly explain the main concepts of closure, along with providing an example that highlights these concepts. So let's dive right in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is closure?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Simply put, closure occurs when a function accesses a variable that is outside its scope. This function is also invoked in a different scope from that of the variable. We can say that a function 'closes' over that variable. In easier terms, a function has access to a variable that is outside the function. Closure can only happen through an invoked function that references a variable(s) that is outside the function and outside the function's scope.&lt;/p&gt;

&lt;p&gt;Enough words and abstract ideas, let's see this in a concrete example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Friday&lt;/span&gt;&lt;span class="dl"&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;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;dayOfTheWeek&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// we are closing over `day`,&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;`Today is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt; &lt;span class="nx"&gt;day&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="nx"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Saturday&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Today is Saturday.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this example, the function &lt;code&gt;dayOfTheWeek&lt;/code&gt; is called and closes over the variable &lt;code&gt;day&lt;/code&gt;. &lt;code&gt;day&lt;/code&gt; is declared and is assigned the value 'Friday,' but is later reassigned the value of 'Saturday'. This concept might seem very similar to scope, but the key difference is this: closure applies specifically to functions. Each time a function like &lt;code&gt;dayOfTheWeek&lt;/code&gt; is called, there is a new closure. In Javascript, closure ensures that outside variables, which may be in an outer, enclosing function, are not garbage-collected (or GC'ed) once that outer function is done running. Closure allows the inner-scope function to have live access to those variables.&lt;/p&gt;

&lt;p&gt;Here is another example, which might be very confusing at first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;keeps&lt;/span&gt; &lt;span class="o"&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="mi"&gt;3&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="nx"&gt;keeps&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="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;keepI&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;// closure over `i`&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;i&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;keeps&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt;   &lt;span class="c1"&gt;// 3 &lt;/span&gt;
&lt;span class="nx"&gt;keeps&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="c1"&gt;// 3&lt;/span&gt;
&lt;span class="nx"&gt;keeps&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="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You might expect the function calls at the end to produce the outputs &lt;code&gt;0&lt;/code&gt;,&lt;code&gt;1&lt;/code&gt;, and &lt;code&gt;2&lt;/code&gt;. However, &lt;code&gt;3&lt;/code&gt; is returned for all three. Why? It's because of closure. The function &lt;code&gt;keepI&lt;/code&gt; is called inside the for loop, and closes over the global &lt;code&gt;var i&lt;/code&gt; during each instance of the loop. Although each function instance has its own closure, it closes over the same variable &lt;code&gt;i&lt;/code&gt;, which takes on the value of 3 at the end of the loop.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Function-level Scoping in pre-ES6 </title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Sat, 04 Apr 2020 22:07:07 +0000</pubDate>
      <link>https://dev.to/danhjoo7/function-level-scoping-in-pre-es6-211k</link>
      <guid>https://dev.to/danhjoo7/function-level-scoping-in-pre-es6-211k</guid>
      <description>&lt;p&gt;Before the introduction of &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; in ES6,&lt;code&gt;var&lt;/code&gt; reigned supreme and was used for all declarations/identifiers. The use of &lt;code&gt;var&lt;/code&gt; is still quite common today, either through legacy code or in new code. Although there is a lot of debate over where and when &lt;code&gt;var&lt;/code&gt; declarations should be used, I want to show some of the pre-ES6 function scoping.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&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="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;y&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;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&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;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&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;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x&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;In this example here, we have a function where we want the difference between the two numbers to be positive. If &lt;code&gt;x&lt;/code&gt; is greater than &lt;code&gt;y&lt;/code&gt;, then we assign the value of &lt;code&gt;x&lt;/code&gt; to &lt;code&gt;z&lt;/code&gt;, which is declared in this function scope. Then, we take steps to essentially switch the values of &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;. In the end, we return &lt;code&gt;y-x&lt;/code&gt;, which should be a positive number.&lt;/p&gt;

&lt;p&gt;I want to bring attention to &lt;code&gt;z&lt;/code&gt; declaration in this function. &lt;code&gt;var&lt;/code&gt; identifiers within functions are accessible across the whole function. They attach themselves to the nearest enclosing function, no matter where they may be within that function. So in this case, although &lt;code&gt;z&lt;/code&gt; may have been declared in the if block, it still belongs to the function scope. Unlike &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;, &lt;code&gt;var&lt;/code&gt; declarations cannot create their own block scope. So although &lt;code&gt;z&lt;/code&gt; has been declared inside a block, it does not create a block scope. Also, to be completely clear, not all blocks create their own scopes as well. &lt;/p&gt;

&lt;p&gt;Theoretically then, for the function above, we could change it so that it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&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;z&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="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&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;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&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;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x&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 version of the function would exhibit the exact same behavior  since &lt;code&gt;z&lt;/code&gt; belongs to the function scope. One possible argument I could have against this version, however, is that putting &lt;code&gt;z&lt;/code&gt; outside the if block would signal that it's available and ready to be used within the whole function. While this is true, it's only technically needed for the set of statements within the if block. So putting the declaration of &lt;code&gt;z&lt;/code&gt; inside the if block would semantically show that &lt;code&gt;z&lt;/code&gt; is only needed for the part of the function inside the if block, although functionally, nothing changes. In other words, it semantically shows that &lt;code&gt;z&lt;/code&gt; is block scoped.&lt;/p&gt;

&lt;p&gt;In ES6+, we could incorporate &lt;code&gt;let&lt;/code&gt; and simply swap out &lt;code&gt;var&lt;/code&gt; for &lt;code&gt;let&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&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="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;y&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;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&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;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&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;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;x&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;In this ES6+ version, this &lt;code&gt;let&lt;/code&gt; declaration also creates its own block scope within the if statement. &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Difference between == and === in JS</title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Sun, 22 Mar 2020 04:36:58 +0000</pubDate>
      <link>https://dev.to/danhjoo7/difference-between-and-in-js-58la</link>
      <guid>https://dev.to/danhjoo7/difference-between-and-in-js-58la</guid>
      <description>&lt;p&gt;Anyone new to Javascript can at one point find themselves asking this very question when dealing with these comparison operators. This short answer is this: &lt;code&gt;==&lt;/code&gt; requires that the variables on either side are of the same value, while &lt;code&gt;===&lt;/code&gt; requires both variables to be of the same value AND the same variable type. &lt;/p&gt;

&lt;p&gt;For &lt;code&gt;==&lt;/code&gt;, type coercion is performed. Type coercion is when the variable types for both variables are set to the same type before the values are compared. Here is an example of all this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;variable&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;variable2&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;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;variable&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this code, the first console log statement returns &lt;code&gt;true&lt;/code&gt;. This is because type coercion makes both variables to have the same type. The second console log statement returns false because although both variables have the same value, &lt;code&gt;variable&lt;/code&gt; is a string, while &lt;code&gt;variable2&lt;/code&gt; is a number.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding the Key Concepts of Compilation in JavaScript </title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Sun, 15 Mar 2020 05:17:32 +0000</pubDate>
      <link>https://dev.to/danhjoo7/understanding-the-key-concepts-of-compilation-in-javascript-540o</link>
      <guid>https://dev.to/danhjoo7/understanding-the-key-concepts-of-compilation-in-javascript-540o</guid>
      <description>&lt;p&gt;JavaScript can be best described as a compiled language. One may ask, "What is a compiled language?" Simply put, compilation is when code is transformed, through a series of steps, into instructions that your computer can then execute. During compilation, the entirety of the code is changed all at once. JS programs are run through two phases: compilation and execution. The programs are compiled before they are executed.&lt;/p&gt;

&lt;p&gt;Compilation is important to consider and learn because it is during compilation that scope is determined. The scope, in turn, affects how the program is executed. Compilation broadly consists of three stages: Tokenizing/lexing, parsing, and code generation. &lt;/p&gt;

&lt;p&gt;First, tokenizing/lexing is when the code is split up into meaningful chunks. For example, &lt;code&gt;var c = 0&lt;/code&gt; can be split up into the tokens &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Parsing is when these tokens are collected and formed into the Abstract Syntax Tree (AST). The AST can be describes as the grammatical structure of the program. According to Wikipedia, it is "a tree representation of the abstract syntactic structure of source code written in a programming language." To simply put, it represents the structure of the code. Lastly, during code generation, the AST is transformed into executable code. &lt;/p&gt;

&lt;p&gt;So what exactly is the significance of compilation on how code is executed? Is there actual proof of compilation? Consider the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;month&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;It is March, 2020.&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;month&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;month&lt;/span&gt; &lt;span class="o"&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;It is March 14, 2020.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// SyntaxError: unexpected token .&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When this program is run, the console.log statement is in fact, not executed. This is because of the syntax error, which comes from the period, in the redeclaration of &lt;code&gt;var month&lt;/code&gt;. This shows how the code is first compiled and then executed. Otherwise, the console.log statement would have been executed and then the error would have appeared.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Class vs Pure vs Functional Components in React </title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Fri, 03 Jan 2020 16:30:15 +0000</pubDate>
      <link>https://dev.to/danhjoo7/class-vs-pure-vs-functional-components-in-react-4p0n</link>
      <guid>https://dev.to/danhjoo7/class-vs-pure-vs-functional-components-in-react-4p0n</guid>
      <description>&lt;p&gt;When first learning React and looking through source code on the Internet, I found myself slightly confused by the different types of components. Although one could go about only using class components throughout his or her application, pure and functional components can come in handy and allow for more clarity/organization within an application. Let's get into the differences between the three components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Class components are the go-to components in React. They can be used exclusively throughout an entire application, and are the components that are most frequently used. Here is an example of a very simple class component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;

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



&lt;p&gt;&lt;strong&gt;Pure components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So what exactly are pure components? As the name suggests, the concept of a pure component is very similar to that of a pure function. In a pure function, if you put in the same input "x" number of times, you will get the same output "x" number of times. Putting in the same input will always lead to the same output in a pure function. Similarily, if a pure component is given the same state and props, it will always behave in the same way. A pure component does not have access to &lt;code&gt;shouldComponentUpdate&lt;/code&gt;. What this means is that there is an automatic, shallow comparison of old and new props and state. Pure components are written pretty much the same way as class components with a minor tweak.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PureComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;PureComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Functional components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Functional components come in handy when you know that you don't need to include state or lifecycle methods in your component. Class components automatically check for lifecycle methods, and if you don't need to utilize them, you can simply use functional components. Because there are no lifecycle methods, &lt;code&gt;render&lt;/code&gt; is not used. Functional components are a good option when all you want do is display something in your component and not include logic. They can take in props from parent components and re-render based on changes in props in the parent components. Functional components can also re-render if their parent components re-render. A functional component returns JSX and can be written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>codenewbie</category>
      <category>react</category>
    </item>
    <item>
      <title>Using a Switch Component in React Router</title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Tue, 10 Dec 2019 19:15:34 +0000</pubDate>
      <link>https://dev.to/danhjoo7/using-a-switch-component-in-react-router-d2k</link>
      <guid>https://dev.to/danhjoo7/using-a-switch-component-in-react-router-d2k</guid>
      <description>&lt;p&gt;Routing in React can be a little difficult for those who are new to React. It is pretty different from the routing system used in Ruby on Rails because it is now done completely on the client. The client is responsible for all routing in React. &lt;/p&gt;

&lt;p&gt;When working with routing in React, I came upon the &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt; component and noticed how people were using that in place of &lt;code&gt;&amp;lt;Router /&amp;gt;&lt;/code&gt;. This made me delve a little further into the differences between the two and why using &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt; can be very helpful and the preferred component between the two. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Router /&amp;gt;&lt;/code&gt; can include many nested routes that render inclusively. And what does "render inclusively" mean? It just means that whenever a route's path matches the url path, the router will render the route's component. Let's take a look at the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/login"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/explore"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Explore&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;),&lt;/span&gt;
       &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;In this example, when a user goes the url path &lt;code&gt;/&lt;/code&gt;, the &lt;code&gt;Home&lt;/code&gt;,&lt;code&gt;Login&lt;/code&gt;, and &lt;code&gt;Explore&lt;/code&gt; components will all render. This is because all three routes include &lt;code&gt;/&lt;/code&gt; in their paths. The &lt;code&gt;&amp;lt;Route /&amp;gt;&lt;/code&gt; component is handy in this way in that it can render certain components all the time, such as the header, nav bar, and other components that should appear on every page of a website. &lt;/p&gt;

&lt;p&gt;One way to ensure that routes don't render inclusively is by adding "exact paths" to routes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/login"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/explore"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Explore&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;),&lt;/span&gt;
       &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;Above, I added an exact path to the &lt;code&gt;login&lt;/code&gt; route. So when we visit &lt;code&gt;/login&lt;/code&gt;, only the &lt;code&gt;Login&lt;/code&gt; component will now render on the page.&lt;/p&gt;

&lt;p&gt;So what exactly is the advantage of using &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt;? The &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt; component will only render the first route that matches/includes the path. Once it finds the first route that matches the path, it will not look for any other matches. Not only that, it allows for nested routes to work properly, which is something that &lt;code&gt;&amp;lt;Router /&amp;gt;&lt;/code&gt; will not be able to handle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/login"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/explore"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Explore&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;),&lt;/span&gt;
       &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;In the example above, when the user goes to &lt;code&gt;/login&lt;/code&gt;, only the &lt;code&gt;Login&lt;/code&gt; component will now be rendered. It is also important to note that an exact path can and should still be utilized for routes that are inside a &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt;. An exact path for a route that is inside a &lt;code&gt;&amp;lt;Switch /&amp;gt;&lt;/code&gt; makes sure that the route matches exactly the path that is specified. For example, without the exact path for &lt;code&gt;/&lt;/code&gt; above, a user who goes to &lt;code&gt;/login&lt;/code&gt; would find the &lt;code&gt;Home&lt;/code&gt; component rendered on the web page. &lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>The differences between typeof and instanceof in OO JS</title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Fri, 15 Nov 2019 18:10:04 +0000</pubDate>
      <link>https://dev.to/danhjoo7/the-differences-between-typeof-and-instanceof-in-oo-js-317f</link>
      <guid>https://dev.to/danhjoo7/the-differences-between-typeof-and-instanceof-in-oo-js-317f</guid>
      <description>&lt;p&gt;I want to explain the differences between the &lt;code&gt;typeof&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt; operators in object-oriented JavaScript. Both of these operators can be used to find out more information about a certain piece of data. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;typeof&lt;/code&gt; is an operator that can be used to verify what datatype a certain "operand" is. An "operand," as mentioned in the MDN documentation, is just a piece of data that is being manipulated or worked on. This operand can be pretty much anything, from a variable that contains a value to a function. When using &lt;code&gt;typeof&lt;/code&gt; on an operand, all you need to is simply state &lt;code&gt;typeof&lt;/code&gt; right before the operand. &lt;/p&gt;

&lt;p&gt;Here are two examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//"number"&lt;/span&gt;


&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;hello&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`hello, &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="s2"&gt;`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt;
&lt;span class="c1"&gt;//"function"&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//"string"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the first example, we are using &lt;code&gt;typeof&lt;/code&gt; on the variable &lt;code&gt;a&lt;/code&gt;, which contains the value of integer 6. Therefore, the return value is "number," because 6 is a number/integer. &lt;/p&gt;

&lt;p&gt;The second example is a little more tricky. Here, we have the &lt;code&gt;hello&lt;/code&gt; function. When using &lt;code&gt;typeof&lt;/code&gt; on &lt;code&gt;hello&lt;/code&gt;, we get the return value of &lt;code&gt;function.&lt;/code&gt; This is because &lt;code&gt;hello&lt;/code&gt; refers to the function body, or the code that is between the brackets, also known as the code block. If we call &lt;code&gt;typeof&lt;/code&gt; on &lt;code&gt;hello()&lt;/code&gt;, however, we get the value of &lt;code&gt;string&lt;/code&gt;. This is because the function is now being invoked, and therefore returns the string within the code block.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;instanceof&lt;/code&gt; operator tests to see whether the operand is an instance, or object, of a certain class. In JavaScript, just like &lt;code&gt;initialize&lt;/code&gt; method in Ruby, instances of a class can be created/initialized with certain attributes using the &lt;code&gt;constructor&lt;/code&gt; method. This makes each instance of a class unique. Let's take a look at this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;constructor&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;age&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&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;person&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;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;David&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;22&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;david&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;Person&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;person&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;//"David"&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;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//22&lt;/span&gt;

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



&lt;p&gt;In this &lt;code&gt;Person&lt;/code&gt; class, each new instance of &lt;code&gt;Person&lt;/code&gt; will be created with a name and an age. &lt;code&gt;this&lt;/code&gt; refers to the object/instance that is currently being created and initialized. &lt;code&gt;this&lt;/code&gt; is similar in concept to &lt;code&gt;self&lt;/code&gt; in Ruby.&lt;/p&gt;

&lt;p&gt;With this knowledge of the constructor method in JavaScript, we can use the &lt;code&gt;instanceof&lt;/code&gt; operator to verify whether the operand is actually an instance of a certain class. &lt;code&gt;typeof&lt;/code&gt; returns a boolean value. Using the &lt;code&gt;Person&lt;/code&gt; class above, we can use &lt;code&gt;instanceof&lt;/code&gt; to verify whether &lt;code&gt;person&lt;/code&gt; is an instance of the &lt;code&gt;Person&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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="nx"&gt;person&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Person&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;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;david&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Person&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;When applying this to &lt;code&gt;person&lt;/code&gt; and &lt;code&gt;david&lt;/code&gt;, we can see that both of the expressions return the value of "true." This is because both are instances of the &lt;code&gt;Person&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;To summarize, &lt;code&gt;typeof&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt; are neat little operators that can be utilized when trying to verify the properties/characteristics of objects and data in JavaScript.  &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Strong Params with Custom Arguments </title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Fri, 25 Oct 2019 15:37:21 +0000</pubDate>
      <link>https://dev.to/danhjoo7/strong-params-with-custom-arguments-1ng5</link>
      <guid>https://dev.to/danhjoo7/strong-params-with-custom-arguments-1ng5</guid>
      <description>&lt;p&gt;Strong Params are used in Rails to make sure that users can only pass in values for permitted parameters when sending POST requests to the server. For example, when updating a blog post, a user will only be able to update the attribute parameters for the post that have been permitted by the developers for users to edit/update.&lt;/p&gt;

&lt;p&gt;Custom arguments for strong parameters are a helpful way to ensure that the user cannot update the values for certain parameters after the object has already been created (through a form_for).&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the example shown here, I have a private strong params method. It's called task_params and takes in custom arguments for what params are permitted for a user to enter values for when creating and updating a task. The method requires that there be a task, and what is being permitted is up to the developer's digression later on in the Tasks#create and Tasks#update methods.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the Tasks#create controller action, there are 5 parameters that are being permitted. There is the assigner_id, title, category, priority, and content. These are the only attributes of a task object that the user can pass in values for when that user creates a task on a form.&lt;/p&gt;

&lt;p&gt;However, because the task_params method has custom arguments, now I can permit different parameters when users want to update a preexisting task. Let's say that once a task has been assigned to someone(the assignee), the assignee for a task cannot be changed. In the Tasks#update action, you can see that the assignee_id parameter has now been taken out. As long as take out the form field for assignee_id in the corresponding form on the edit view page, users will now only be permitted to update values for the remaining 4 parameters. &lt;/p&gt;

&lt;p&gt;Passing custom arguments for strong parameters is definitely a neat and simple way to control what users can and cannot update!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>The Convenience of Faker</title>
      <dc:creator>Daniel Joo</dc:creator>
      <pubDate>Thu, 03 Oct 2019 20:10:01 +0000</pubDate>
      <link>https://dev.to/danhjoo7/the-convenience-of-faker-1m6n</link>
      <guid>https://dev.to/danhjoo7/the-convenience-of-faker-1m6n</guid>
      <description>&lt;p&gt;When working on a new project, everyone needs to populate their databases with some data. This can be a daunting task, especially for beginners to programming. In Ruby however, there is a "Faker" gem, which, upon installing, can make that task a whole lot easier. There is pretty much no need to hardcode any fake data when you need a lot of data!&lt;/p&gt;

&lt;p&gt;What Faker does is generates fake data for your database. Before you use Faker, three things need to be done. First, you have to install the gem with "gem install faker." Second, you must set up made a migration for your tables and have your schema ready. This can be done through Active Record. Lastly, you need to require Faker on your gemfile. Now, you are all set to use Faker to generate this fake data! &lt;/p&gt;

&lt;p&gt;Faker is such a convenient tool, and although I won't get into the specifics of how to actually incorporate it into the code, everyone who works with Ruby on their personal projects should utilize it.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
