<?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: Paul Thompson</title>
    <description>The latest articles on DEV Community by Paul Thompson (@paritho).</description>
    <link>https://dev.to/paritho</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%2F171460%2F77afa02d-8ec9-403a-8919-6d9e44bdda75.jpg</url>
      <title>DEV Community: Paul Thompson</title>
      <link>https://dev.to/paritho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paritho"/>
    <language>en</language>
    <item>
      <title>Don't Learn A JS Framework</title>
      <dc:creator>Paul Thompson</dc:creator>
      <pubDate>Mon, 15 Nov 2021 16:05:04 +0000</pubDate>
      <link>https://dev.to/paritho/dont-learn-a-js-framework-h3m</link>
      <guid>https://dev.to/paritho/dont-learn-a-js-framework-h3m</guid>
      <description>&lt;p&gt;...until you &lt;em&gt;master&lt;/em&gt; JavaScript.&lt;/p&gt;

&lt;p&gt;Now, you don't have to be on the same level as Brendan Eich, Eric Elliott, or &lt;a class="mentioned-user" href="https://dev.to/getify"&gt;@getify&lt;/a&gt;
, but you should endeavor to understand as much about vanilla JavaScript as you can.&lt;/p&gt;

&lt;p&gt;Fan bois, rise up! Jump to the comments to defend the glory of your framework! &lt;/p&gt;

&lt;p&gt;Now that I have your attention, let's have a discussion. Imagine you're at a &lt;a href="https://dev.to/paritho/3-reasons-to-use-var-in-javascript-1hoe"&gt;fun party&lt;/a&gt;. Macarena comes on and a group of people immediately jump up to dance. You stare on, wishing you knew the moves, but you only know how to &lt;a href="https://www.youtube.com/watch?v=T2e1tsnKkiI"&gt;dance dance&lt;/a&gt;. You spent the last year learning to put your feet -- and only your feet -- in the exact spot the game told you. And when the dancers now shift to the electric slide where you have to move your feet &lt;em&gt;and&lt;/em&gt; clap...well, this is the exact kind of situation your mother warned you about.&lt;/p&gt;

&lt;p&gt;If I've spent time learning a JavaScript framework without taking time to understand the language at a deep level, I'm more like our woeful dance-dancer than I'd like to admit. Frameworks are &lt;em&gt;built&lt;/em&gt; on and with JavaScript. So while you can code an app or website with React© or Vue©, you'll inevitably run across a situation where having a deep understanding of JS is necessary to solve a problem. Furthermore, if you &lt;a href="https://brendaneich.com/"&gt;always bet on JavaScript&lt;/a&gt; you'll be able to move from &lt;del&gt;the macarena&lt;/del&gt; React© to &lt;del&gt;the electric slide&lt;/del&gt; Vue© fairly easily. &lt;/p&gt;

&lt;p&gt;Here's a real-world example of where understanding how JS handles object references could trip you up inside a framework.&lt;/p&gt;

&lt;p&gt;Consider this Vue© &lt;a href="https://vuejs.org/v2/guide/single-file-components.html"&gt;SFC&lt;/a&gt;, Books.vue.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;(book,idx) in processedBooks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;idx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFilter&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
             &lt;span class="nx"&gt;processedBooks&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;toProcess&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;books&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;toProcess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                     &lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                     &lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasBeenProcessed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                     &lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toFilter&lt;/span&gt; &lt;span class="o"&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;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&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;return&lt;/span&gt; &lt;span class="nx"&gt;book&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="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;books&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;required&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="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we use this little guy 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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Books&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;books&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;books&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;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="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
            &lt;span class="na"&gt;books&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Eric Elliott&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Programming JavaScript Applications&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="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kyle Simpson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You don't know JS&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="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Matt Pagett&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The Best Dance Moves in the World&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="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you were to take a look at the books property inside the Books.vue component, what do you think you'd find? You might expect it to just contain the authors and titles of our book list. However, this is what you'd see:&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="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Eric Elliott&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PROGRAMMING JAVASCRIPT APPLICATIONS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;hasBeenProcessed&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;toFilter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PROGRAMMING JAVASCRIPT APPLICATIONS-Eric Elliott&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="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kyle Simpson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOU DON'T KNOW JS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;hasBeenProcessed&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;toFilter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOU DON'T KNOW JS-Kyle Simpson&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="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Matt Pagett&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;THE BEST DANCE MOVES IN THE WORLD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;hasBeenProcessed&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;toFilter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;THE BEST DANCE MOVES IN THE WORLD-Matt Pagett&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;Even though Vue© won't let us mutate a prop, &lt;em&gt;and&lt;/em&gt; we've copied the data from &lt;code&gt;this.books&lt;/code&gt; into &lt;code&gt;toProcess&lt;/code&gt;, we've still managed to alter the objects in the array. Why? Because JavaScript keeps the reference to the objects in the array throughout the processing. This has nothing to do with Vue© or any other framework, this is the way the language works. If you needed to do something with the original prop data, say POST that data to a DB, we're now working with objects that have more information than we were expecting.&lt;/p&gt;

&lt;p&gt;Could this be avoided by knowing JS at a deep level first? Maybe. At the very least, when the bug of mutated original data crops up, you'd be able to identify how to fix it. If later on you tackle a project in React© or --&lt;em&gt;shudders&lt;/em&gt;-- Angular, you'll be able to avoid similar problems. &lt;/p&gt;

&lt;p&gt;JavaScript frameworks are great. They can make a developer's life easier and they do add value to our projects, especially large complex ones. However, it's very important to understand JS at a deep level before we dive headfirst into the ever-crashing tide of frontend frameworks. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>3 reasons to use 'var' in JavaScript</title>
      <dc:creator>Paul Thompson</dc:creator>
      <pubDate>Mon, 08 Nov 2021 22:19:53 +0000</pubDate>
      <link>https://dev.to/paritho/3-reasons-to-use-var-in-javascript-1hoe</link>
      <guid>https://dev.to/paritho/3-reasons-to-use-var-in-javascript-1hoe</guid>
      <description>&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; keyword was JavaScript's first way to declare a variable. It fits, right? Var, variable, it's in the name. But like the Joker, &lt;code&gt;var&lt;/code&gt; is more than pretty face -- it has some baggage. As a beginning programmer, or a seasoned one dipping your toe into the seedy underbelly of JavaScript development, you maybe be wondering when you should use &lt;code&gt;var&lt;/code&gt; to declare your JavaScript objects and functions.&lt;/p&gt;

&lt;p&gt;Never fear. I have 3 reasons for you to use &lt;code&gt;var&lt;/code&gt; in your next JavaScript project.&lt;/p&gt;

&lt;h2&gt;
  
  
  You love tradition and spurn anything new
&lt;/h2&gt;

&lt;p&gt;Var may be the oldest keyword to declare a variable, but it is by far the only one. It's younger cousins, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; exploded onto the scene with &lt;a href="https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_%E2%80%93_ECMAScript_2015"&gt;ES6&lt;/a&gt; (over 6 years ago as of this writing!). But if sticking to old norms fraught with perils is your thing, keep using &lt;code&gt;var&lt;/code&gt; and leave these upstart keywords to listen to their terrible pop music and complain about their parents.&lt;/p&gt;

&lt;h2&gt;
  
  
  You prefer mutability, even when you don't
&lt;/h2&gt;

&lt;p&gt;Var has the troubling distinction of creating a variable of any type, which can then be changed to a variable of any type later. That's right, the number you declared on line 4 just became a string on line 17 and a boolean on line 109. This type flexibility is a key feature of JavaScript, but it can be avoided. But if you too like to live dangerously, keep using var.&lt;/p&gt;

&lt;h2&gt;
  
  
  You like leaky scopes
&lt;/h2&gt;

&lt;p&gt;Prior to ES6, JavaScript variables were always defined at the function scope. In a lot of cases, this meant variables were &lt;em&gt;global&lt;/em&gt;. JavaScript didn't enforce block-level scopes such as inside a &lt;code&gt;for&lt;/code&gt; loop or &lt;code&gt;if&lt;/code&gt; block. So a variable declared with &lt;code&gt;var&lt;/code&gt; would be &lt;em&gt;hoisted&lt;/em&gt; to the top of its function scope. In other words, the variable declaration moved to the top of the current lexical environment with a value of &lt;code&gt;undefined&lt;/code&gt;. A common issue arising from hoisting is that such variables are accessible outside the block scope, where the developer may not expect them to be. &lt;/p&gt;

&lt;p&gt;A subtler and more difficult to detect bug can happen here as well, &lt;a href="https://eloquentjavascript.net/1st_edition/chapter3.html#p468c043e14dd0d54"&gt;variable shadowing&lt;/a&gt;. Rarely this may be desired. If that is you, &lt;code&gt;var&lt;/code&gt; is your hero.&lt;/p&gt;

&lt;h2&gt;
  
  
  There must be a better way
&lt;/h2&gt;

&lt;p&gt;If you made it this far, you're probably seconds away from pounding out a fierce comment about how I'm wrong about &lt;code&gt;var&lt;/code&gt;. The truth is, no one should be using &lt;code&gt;var&lt;/code&gt; in any JavaScript code except for a history lesson. Even then, it should come with a footnote that says something like, "please don't ever do this."&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; have been available in &lt;a href="https://caniuse.com/?search=let"&gt;every major browser for the last 6 years&lt;/a&gt;. This is really, really ancient in frontend years. &lt;code&gt;var&lt;/code&gt; isn't just the parent misunderstanding their teen, it's the great grandparent everyone loves but no one invites to the &lt;em&gt;fun&lt;/em&gt; parties.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Let&lt;/code&gt; retains JavaScript's flexible type system while enabling block-scoping. &lt;code&gt;Const&lt;/code&gt; creates a -- you guessed it -- constant variable in block-scope. &lt;code&gt;Const&lt;/code&gt; creates a variable that cannot be reassigned, but similar to most other languages, &lt;code&gt;const&lt;/code&gt; objects can have their properties mutated. These two alternatives to &lt;code&gt;var&lt;/code&gt; should cover every use case you have. Even if you are in the tough spot of needing to support truly archaic browsers, don't use &lt;code&gt;var&lt;/code&gt;. Use a tool such as &lt;a href="https://babeljs.io/"&gt;Babel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So please, please, do not use &lt;code&gt;var&lt;/code&gt;.  &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>HyperHTML Up and Running part 1</title>
      <dc:creator>Paul Thompson</dc:creator>
      <pubDate>Thu, 06 Jun 2019 21:31:07 +0000</pubDate>
      <link>https://dev.to/paritho/hyperhtml-up-and-running-part-1-3im0</link>
      <guid>https://dev.to/paritho/hyperhtml-up-and-running-part-1-3im0</guid>
      <description>&lt;p&gt;If you haven't heard of hyperHTML, it is worth your time checking into it. As an alternative to the big, popular frameworks, hyper is a blazing fast, small-footprint library that keeps you in the driver seat. HyperHTML centers around making extremely fast DOM updates, and can be integrated into any other framework if you wish (pro-tip: you won't want to). &lt;/p&gt;

&lt;p&gt;But seeing is believing, so let's fire up a new project and see how easy it is to get started using hyperHTML. This tutorial will focus on the various ways to set up your development environment using hyperHTML. You'll learn a bit about hyperHTML, webpack, rollup, and modules. We'll assume you have working knowledge of web technologies like HTML, CSS, and of course JavaScript.&lt;/p&gt;

&lt;p&gt;Let's begin by setting up our local folder structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hyperhtml
|_dist
|_src

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



&lt;blockquote&gt;
&lt;p&gt;We'll be using a few tools from npm throughout this tutorial, so make sure you have nodejs installed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In your root folder, create a standard, boilerplate &lt;code&gt;index.html&lt;/code&gt; file. By far the easiest way to enjoy developing apps with hyperHTML is to use the unpkg CDN. Include this line in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of &lt;code&gt;index.html&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://unpkg.com/hyperhtml@latest/min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This gives us access to the hyperHTML variable. Create a &lt;code&gt;&amp;lt;div id="app"&amp;gt;&lt;/code&gt; and then before the closing body tag, work magic the likes of which Merlin couldn't fathom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;hyperHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;h1&amp;gt;Welcome to Hyper&amp;lt;/h1&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Fire up your favorite dev server (for the moment, we're using &lt;a href="https://www.npmjs.com/package/http-server"&gt;http-server&lt;/a&gt;. Http-server is a simple, zero-config server) and load the page. Tada! HyperHTML everyone. If you aren't sure what's going on here, take a minute to research tagged template literals. We'll be here when you get back.&lt;/p&gt;

&lt;p&gt;Let's add a couple more DOM nodes to our "app":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nx"&gt;welcome&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Intrepid traveler, &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;, welcome!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
    &lt;span class="nx"&gt;hyperHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;h1&amp;gt;Welcome to Hyper&amp;lt;/h1&amp;gt;
                    &amp;lt;div class="row"&amp;gt;
                      &amp;lt;div class="col-sm-6"&amp;gt;
                         &amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Steve&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/p&amp;gt;
                      &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save, refresh, drop the mic. But can we move this JavaScript madness to another file? &lt;/p&gt;

&lt;p&gt;Sure! &lt;/p&gt;

&lt;p&gt;Create an &lt;code&gt;app.js&lt;/code&gt; file inside the src folder in our project. Move all that JS magic into app.js, then include the file in &lt;code&gt;index.html&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's see if it worked; before you save and refresh, kick Steve out and let King Richard the Lionheart come to the party.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;King Richard the Lionheart&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is very, very basic stuff. However, it shows that hyperHTML doesn't need anything more than the library and a server. You could develop loads of apps with just this, but why would you want to?&lt;/p&gt;

&lt;p&gt;Let's harness the power of some other tools to make our development lives easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  Webpack
&lt;/h2&gt;

&lt;p&gt;The first tool we'll look at is webpack. Webpack is a module bundler and loader. The first step is to install webpack with npm, locally to our project. In the root folder, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i webpack
npm i webpack-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Cool. &lt;/p&gt;

&lt;p&gt;Since we're using webpack now, we don't need to use a CDN to grab hyperHTML. We can import it. First, install with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i hyperhtml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And at the top of &lt;code&gt;app.js&lt;/code&gt;, do the import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;hyperHTML&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;hyperhtml/cjs&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;blockquote&gt;
&lt;p&gt;Note: '/cjs' is a module hyperHTML has to work with CommonJS module loaders like Webpack. In a little bit we'll see another module hyper gives us, '/esm'.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can now remove the script tag from &lt;code&gt;index.html&lt;/code&gt; that was pulling in hyperhtml. We're almost ready to let webpack bundle everything. We need to make one more modification to &lt;code&gt;index.html&lt;/code&gt;: &lt;/p&gt;

&lt;p&gt;Change &lt;code&gt;&amp;lt;script src="./src/app.js" /&amp;gt;&lt;/code&gt; to&lt;br&gt;
&lt;code&gt;&amp;lt;script src="dist/bundle.js" /&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, we need to tell webpack where to start bundling our files. While we can run wepack without a config, most projects you'll make will need one, so we're going to set it up now. Create a &lt;code&gt;webpack.config.js&lt;/code&gt; file and place it in the project root. Inside this file we need a very simple config:&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;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now, the moment you've been waiting for. In your project root on the command line, run &lt;code&gt;npx webpack&lt;/code&gt;. Don't worry if you get a couple warnings or errors. You should now be able to find a &lt;code&gt;bundle.js&lt;/code&gt; file in your &lt;code&gt;dist&lt;/code&gt; folder. Fire up &lt;code&gt;http-server&lt;/code&gt; and check it out!&lt;/p&gt;

&lt;p&gt;Ready for more wizardry, my young apprentice? With just a few more steps, we can import CSS files. Watch and learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;styles.css&lt;/code&gt; file and put it in the src folder. Include some style rules in it.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;app.js&lt;/code&gt;, &lt;code&gt;import "styles.css"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm i style-loader css-loader&lt;/code&gt; on the command line. &lt;/li&gt;
&lt;li&gt;Add this to your &lt;code&gt;webpack.config.js&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nl"&gt;rules&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;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;css$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="na"&gt;use&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="s1"&gt;style-loader&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="s1"&gt;css-loader&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="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;npx webpack&lt;/code&gt; again a see the lightning bolts fly from your fingers! For more in-depth information, see the &lt;a href="https://webpack.js.org/guides/asset-management/#loading-css"&gt;webpack docs.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to import/export until your heart is content. With this very quick introduction to hyper + webpack, we've seen that it's easy to get up and running with hyperHTML in a modern webdev environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  Rollup
&lt;/h2&gt;

&lt;p&gt;Another great module bundler we can use is &lt;code&gt;rollup.js&lt;/code&gt;. One reason you might choose rollup for your next project is that it utilizes a technique called tree-shaking. Tree-shaking is a term we use to refer to only bundling code we're actually using. Sometimes we might not want an entire library, just one function from it. Tree-shaking allows this, we're shaking the dead leaves (dead code) from our tree. Webpack offers tree-shaking too, but there's another configuration to set before that happens. Rollup uses tree-shaking automatically.&lt;/p&gt;

&lt;p&gt;As you'd expect, our first step is to install rollup in our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i rollup
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You're already familiar with &lt;code&gt;webpack.config.js&lt;/code&gt;, so the new file we need, &lt;code&gt;rollup.config.js&lt;/code&gt; should come with no surprises.&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;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dist/bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;es&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;Place &lt;code&gt;rollup.config.js&lt;/code&gt; in your root.&lt;/p&gt;

&lt;p&gt;Now, rollup comes as a basic utility with a lot of features out of the box. However, there are a lot of plugins you can install to enhance your applications even further. This gives you the ability to use only what you need, not more. More on plugins in the next part.&lt;/p&gt;

&lt;p&gt;One caveat of rollup is that everything you import needs to be a relative link. So, for example, importing hyperHTML from a node modules as we were when we used webpack won't work with rollup. We can install a plugin to do the trick, &lt;a href="https://github.com/rollup/rollup-plugin-node-resolve"&gt;rollup-plugin-node-resolve&lt;/a&gt;, but since this is a simple project we'll just link to the file we need. &lt;/p&gt;

&lt;p&gt;In &lt;code&gt;app.js&lt;/code&gt;, change &lt;code&gt;import hyperHTML from 'hyperhtml/cjs'&lt;/code&gt; to &lt;br&gt;
&lt;code&gt;import hyperHTML from '../../node_modules/hyperhtml/esm'&lt;/code&gt;, provided your node_modules directory exists two levels above your /src directory.&lt;/p&gt;

&lt;p&gt;For now, remove our import for styles.css. &lt;/p&gt;

&lt;p&gt;And now, run rollup from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rollup -c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we refresh our webpage, we see everything is working.&lt;/p&gt;




&lt;p&gt;I hope you've enjoyed this introductory post about getting an environment up and running with hyperHTML. In the next part, we're going to look at some quality-of-life plugins that will make app development even easier. So stay tuned code wizards! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>hyperhtml</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
