<?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: Eliahu Garcia Lozano</title>
    <description>The latest articles on DEV Community by Eliahu Garcia Lozano (@eligarlo).</description>
    <link>https://dev.to/eligarlo</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%2F186301%2Fabca8e48-f238-4bb3-87c3-8533ac4bc27c.png</url>
      <title>DEV Community: Eliahu Garcia Lozano</title>
      <link>https://dev.to/eligarlo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eligarlo"/>
    <language>en</language>
    <item>
      <title>How to Teleport in Vue 3</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Tue, 02 Feb 2021 03:34:14 +0000</pubDate>
      <link>https://dev.to/eligarlo/how-to-teleport-in-vue-3-1a9e</link>
      <guid>https://dev.to/eligarlo/how-to-teleport-in-vue-3-1a9e</guid>
      <description>&lt;p&gt;A few days ago I decided it was time for me to update myself to the new version of Vuejs, Vue 3. And today I wanted to share with you the first thing I learn that version two didn't have, the &lt;code&gt;teleport&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;It's well known that modern web applications fit in a div.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1346423883285499904-508" src="https://platform.twitter.com/embed/Tweet.html?id=1346423883285499904"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1346423883285499904-508');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1346423883285499904&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Ok, React uses &lt;code&gt;#root&lt;/code&gt; and Vue uses &lt;code&gt;#app&lt;/code&gt; but they just do the same, which is inject the JavaScript code into that div. So here it comes the question:&lt;/p&gt;

&lt;h2&gt;
  
  
  What if I have an element I want to display as a sibling of the &lt;code&gt;#app&lt;/code&gt; element in the html?
&lt;/h2&gt;

&lt;p&gt;Sometimes we have a loader or a modal (aka popup) component that is not part of the app, but anyway, it will be injected inside the &lt;code&gt;#app&lt;/code&gt; element. Thus, the html will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- Other injected HTML here --&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"loader"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="c"&gt;&amp;lt;!-- HTML for the loader goes here --&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's teleport!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cW55zyF7dJAf6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cW55zyF7dJAf6/giphy.gif" alt="Goku Teleport" width="500" height="271"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use the teleport component in your app, you need to first, add a sibling to the &lt;code&gt;#app&lt;/code&gt; element in the html.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- built files will be auto injected --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"loader"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- loader component will be injected here --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you've done that, go to your &lt;code&gt;.vue&lt;/code&gt; file and use the teleport component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;teleport&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;".loader"&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"showLoader"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;Loader&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/teleport&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- The logic of your component goes below --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it. Now, when the showLoader condition is met, the loader will show in the specified html element. Notice that I used a CSS selector so if the element was an id, I could have done it like this: &lt;code&gt;&amp;lt;teleport to="#loader" v-if="showLoader"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you found it useful, please like, subscribe, and share the knowledge.&lt;/p&gt;

&lt;p&gt;You might like what I share on &lt;a href="https://twitter.com/eligarlo"&gt;my Twitter&lt;/a&gt; too.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Trim Your Inputs!</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Wed, 09 Dec 2020 10:58:39 +0000</pubDate>
      <link>https://dev.to/eligarlo/trim-your-inputs-20a</link>
      <guid>https://dev.to/eligarlo/trim-your-inputs-20a</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Definition of trim, &lt;em&gt;"To cut away unnecessary parts from something."&lt;/em&gt; - Oxford Dictionary.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes, validating forms in JavaScript can be a tedious task for a developer. You have to check many things. For instance, that the values given are of the type you expect them to be (string, number, object...), that they are not &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;. And after all that validation, you realize that a user typed an empty &lt;code&gt;string&lt;/code&gt;. 🤦‍♂️&lt;/p&gt;

&lt;p&gt;One of the most common issues about empty strings a developer can face is the one that has spaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;      &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;  &lt;span class="c1"&gt;// 👈 Empty String&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How can you prevent this from happening? In JavaScript, there are five different methods (actually there are three and two aliases) you can use. Let's check what they do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;p&gt;In a login form, you have an input where the user needs to enter a username like the one below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/WRD4arnA3ed8A1ceaD/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/WRD4arnA3ed8A1ceaD/giphy.gif" alt="login form" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👆 Did you notice the whitespace at the beginning and the end of the input?&lt;/p&gt;

&lt;p&gt;If we have a look at our code, the &lt;code&gt;input&lt;/code&gt; would be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter Username"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the JavaScript like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userNameInput&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="nf"&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;.username&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;   Eliahu Garcia Lozano   &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time to get rid of the whitespaces 🧹.&lt;/p&gt;

&lt;h2&gt;
  
  
  TrimStart and TrimLeft
&lt;/h2&gt;

&lt;p&gt;These two will remove the whitespace from the beginning of a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimStart&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eliahu Garcia Lozano   &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimLeft&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eliahu Garcia Lozano   &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TrimEnd and TrimRight
&lt;/h2&gt;

&lt;p&gt;These two will remove the whitespace from the end of a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimEnd&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;   Eliahu Garcia Lozano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimRight&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;   Eliahu Garcia Lozano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these methods, we either removed the whitespace from the beginning or the end of a string but, what if you need to remove the whitespace from both sides?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;trimStart and trimEnd are methods while trimLeft and trimRight are aliases of those methods.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Chaining the methods
&lt;/h2&gt;

&lt;p&gt;You can use them together to get the desired result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimStart&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trimEnd&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eliahu Garcia Lozano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimRight&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trimLeft&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eliahu Garcia Lozano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, maybe it is a little bit ugly I know. Let's check the last method, actually the one I use.&lt;/p&gt;

&lt;h1&gt;
  
  
  Trim
&lt;/h1&gt;

&lt;p&gt;Just like chaining methods, trim will remove the whitespace from left and right; plus, your code will look cleaner. 😅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eliahu Garcia Lozano&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Validating the input
&lt;/h2&gt;

&lt;p&gt;In many places I've seen this kind of &lt;code&gt;string&lt;/code&gt; validation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// do something&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem with this is that the user may enter whitespace.&lt;/p&gt;

&lt;p&gt;Now that we know how to &lt;code&gt;trim&lt;/code&gt; the value of the input, let's see how to implement it in our form validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userNameInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// do something&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you see the difference?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We saw how to remove the whitespace from just the beginning or the end of a string as from both sides at the same time.&lt;/p&gt;

&lt;p&gt;Remember: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.trimStart() &amp;amp; .trimLeft() will remove whitespace from the left.&lt;/li&gt;
&lt;li&gt;.trimEnd() &amp;amp; .trimRight() will remove whitespace from the right.&lt;/li&gt;
&lt;li&gt;.trim() will remove whitespace from both the left and the right side.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From now on, Trim Your &lt;code&gt;&amp;lt;Inputs&amp;gt;&lt;/code&gt;! (if you didn't before).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you found it useful, please like, subscribe, and share the knowledge.&lt;/p&gt;

&lt;p&gt;You might like what I share on &lt;a href="https://twitter.com/eligarlo"&gt;my Twitter&lt;/a&gt; too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Cover Picture by &lt;a href="https://unsplash.com/@isra_eh?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Isra E&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/cut?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Default Function Parameters</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Mon, 07 Dec 2020 17:12:25 +0000</pubDate>
      <link>https://dev.to/eligarlo/default-function-parameters-1l4c</link>
      <guid>https://dev.to/eligarlo/default-function-parameters-1l4c</guid>
      <description>&lt;p&gt;We always have to validate if the arguments passed in a function have a value or they are &lt;code&gt;undefined&lt;/code&gt; but, do we really?&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In my last post, I talked about &lt;a href="https://blog.eligarlo.dev/destructuring-assignment-in-a-function-parameter"&gt;Destructuring Assignment In A Function Parameter&lt;/a&gt; and why it is handy when you have optional parameters in a function and don't want to pass &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With that been said, what if you have a function where all the parameters are required? Again, since ES2015 (aka ES6) this can be easily implemented. Let's dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;p&gt;If you take a Tip Calculator project as an example, you probably will need always the same parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Bill Amount.&lt;/li&gt;
&lt;li&gt;Number of People.&lt;/li&gt;
&lt;li&gt;Service Quality.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The function you'll need would look like this 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateTip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalBill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;numOfPeople&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;serviceQuality&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your validation here&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateTip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&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="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// 5.00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the function, you'll have to do all the calculations &lt;strong&gt;AND&lt;/strong&gt; all the validation; plus, most of the time I go with the same friend (2 people) and leave the standard tip (20%).&lt;/p&gt;

&lt;p&gt;In this case, the only parameter that will be changing all the time will be the bill amount.&lt;/p&gt;

&lt;p&gt;So, let's give &lt;code&gt;numOfPeople&lt;/code&gt; and &lt;code&gt;serviceQuality&lt;/code&gt; a default parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateTip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalBill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;numOfPeople&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;serviceQuality&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateTip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// 5.00&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateTip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// 7.50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, just when someone else is joining, or we want to leave a different tip percentage, it will be necessary to pass the rest of the arguments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You don't really need to check if the argument in a function is &lt;code&gt;undefined&lt;/code&gt;, you can create a default value for it.&lt;/p&gt;

&lt;p&gt;When a different value is provided, the default value will be overwritten.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you found it useful, please like, subscribe, and share the knowledge.&lt;/p&gt;

&lt;p&gt;You might like what I share on &lt;a href="https://twitter.com/eligarlo"&gt;my Twitter&lt;/a&gt; too.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Destructuring Assignment In A Function Parameter</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Mon, 07 Dec 2020 17:08:11 +0000</pubDate>
      <link>https://dev.to/eligarlo/destructuring-assignment-in-a-function-parameter-342j</link>
      <guid>https://dev.to/eligarlo/destructuring-assignment-in-a-function-parameter-342j</guid>
      <description>&lt;p&gt;Have you ever passed an argument as a &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; in a function? Since ES2015 (aka ES6) &lt;strong&gt;you don’t have to&lt;/strong&gt;. You can use JavaScript destructuring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;p&gt;We all have this Utils.js file in our projects where we have all kinds of functions that will be used all over the project. Imagine you have a To-Do app and one of those functions was addTodoItem and you had to call this function in different places.&lt;/p&gt;

&lt;p&gt;Function declaration would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addTodoItem&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;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before calling the function, see the characteristics for each parameter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Title =&amp;gt; required.&lt;/li&gt;
&lt;li&gt;Description =&amp;gt; !required.&lt;/li&gt;
&lt;li&gt;DueDate =&amp;gt; !required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s add a few items to the list now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;addTodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Shopping List&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;eggs, milk&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;30-11-2020&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;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="s1"&gt;Shopping List&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eggs, milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30-11-2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Call Mom&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;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="s1"&gt;Call Mom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pay Bills&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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;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="s1"&gt;Pay Bills&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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;If we pay attention to the last example, we can see that on the first day of the month I need to pay my bills. 🤣&lt;/p&gt;

&lt;p&gt;Jokes aside, we see that I had to pass the second value as &lt;code&gt;undefined&lt;/code&gt; because the function is expecting the description as the second parameter.&lt;/p&gt;

&lt;p&gt;For this specific example, if I wanted to pass a dueDate, first I would have to check whether the description is &lt;code&gt;undefined&lt;/code&gt; or not before I call the addTodoItem function.&lt;/p&gt;

&lt;p&gt;Here is where using destructuring will be very helpful.&lt;/p&gt;

&lt;p&gt;This is how the addTodoItem would look now. 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addTodoItem&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;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add again the same items as before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;addTodoItem&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="s1"&gt;Shopping List&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eggs, milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30-11-2020&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;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="s1"&gt;Shopping List&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eggs, milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30-11-2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&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="s1"&gt;Call Mom&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;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="s1"&gt;Call Mom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&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="s1"&gt;Pay Bills&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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;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="s1"&gt;Pay Bills&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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;If you pay attention to the last item added, you’ll see that there was no need on adding the &lt;code&gt;undefined&lt;/code&gt; for the description. Just title and dueDate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus!
&lt;/h2&gt;

&lt;p&gt;There is more: not only do you not need to pass &lt;code&gt;undefined&lt;/code&gt; anymore, but you can even change the order of how you pass the arguments and it will still work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;addTodoItem&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eggs, milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30-11-2020&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="s1"&gt;Shopping List&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;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="s1"&gt;Shopping List&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;eggs, milk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30-11-2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&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="s1"&gt;Call Mom&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;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="s1"&gt;Call Mom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;addTodoItem&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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="s1"&gt;Pay Bills&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;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="s1"&gt;Pay Bills&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dueDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01-12-2020&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That’s it! We saw how to use destructuring when declaring a function and how to call that function and provide the arguments. &lt;/p&gt;

&lt;p&gt;Remember that you can get rid of the &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt; since the order of the arguments doesn’t matter.&lt;/p&gt;

&lt;p&gt;PS. Remember to pay your bills. 🤣&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you found it useful, please like, subscribe, and share the knowledge.&lt;/p&gt;

&lt;p&gt;You might like what I share on &lt;a href="https://twitter.com/eligarlo"&gt;my Twitter&lt;/a&gt; too.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Copyright Up To Date (The Automate Way)</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Tue, 06 Oct 2020 05:05:02 +0000</pubDate>
      <link>https://dev.to/eligarlo/copyright-up-to-date-the-automate-way-1jkf</link>
      <guid>https://dev.to/eligarlo/copyright-up-to-date-the-automate-way-1jkf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Let's be honest, &lt;strong&gt;outdated copyright disclaimers on a website looks bad&lt;/strong&gt;. Looks like the website it's unmaintained on many levels. On the other hand, you don't want to manually update it every 1st of January on every website you own right? Let me help you &lt;strong&gt;automate this task with 2 lines of code&lt;/strong&gt;. If you want to know more about the importance of updating your copyright dates I found &lt;a href="https://sonet.digital/blog/general/keep-copyright-up-to-date/"&gt;this post&lt;/a&gt; with a more in-depth explanation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, let's create a basic HTML template where we will have our copyright disclaimer at the footer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit.&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;Copyright © &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"copyright"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, My Company Name&lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then, our javascript will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copyright&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="nf"&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;#copyright&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;copyright&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it, you are cover now. 😎&lt;/p&gt;

&lt;p&gt;Bonus tip:💡&lt;/p&gt;

&lt;p&gt;In case you need a range of years instead of a single year in your copyright disclaimer, you can easily tweak the above code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;Copyright © &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"copyright"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2010 - &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, My Company Name&lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copyright&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="nf"&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;#copyright&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;copyright&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thank you for reading, if you like my content, you can always find me on Twitter &lt;a href="https://twitter.com/eligarlo"&gt;@eligarlo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My Journey Into Tech (In A Foreign Country)</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Fri, 04 Sep 2020 08:34:19 +0000</pubDate>
      <link>https://dev.to/eligarlo/my-journey-into-tech-in-a-foreign-country-2im8</link>
      <guid>https://dev.to/eligarlo/my-journey-into-tech-in-a-foreign-country-2im8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;With my salary, we had enough to cover the monthly expenses, but &lt;strong&gt;my wife decided to start working so I could study&lt;/strong&gt;. Pregnant and with our son…she found a kinder garden where she could work and also take our son.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hi there 👋, after the first two posts of &lt;a href="https://blog.eligarlo.dev/vuejs-the-series-getting-started"&gt;VueJs, The Series 🚀&lt;/a&gt;, I wanted to post something about me and my journey into tech.&lt;/p&gt;

&lt;p&gt;To give you some context, I'm Eliahu, you can find me on Twitter &lt;a href="https://twitter.com/eligarlo"&gt;@eligarlo&lt;/a&gt;, I'm from Spain and currently based in Israel. I speak 3 languages (Spanish, English, Hebrew) but my reading and writing skills in Hebrew are just OK (with the help of Google Translate😅). I'm 33 years old, married and father of two wonderful kids. I never had a blog before, this is literally the third post I've ever written in my life! I invite you to keep reading and enjoy my journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  From Spain
&lt;/h2&gt;

&lt;p&gt;I lived in Spain until the age of 24. I quit studying when I was 18, at that time I thought that studying wasn't for me 😂. I started working as a carpenter. I always loved to build things, to see that, taking parts that apparently don't belong together, I could build something useful. Unfortunately this job did not endure much and after trying as a salesman, the 2008 crisis hit and I decided to leave Spain.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1291645278420951040-216" src="https://platform.twitter.com/embed/Tweet.html?id=1291645278420951040"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1291645278420951040-216');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1291645278420951040&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h2&gt;
  
  
  Through England
&lt;/h2&gt;

&lt;p&gt;In Spain you have everything, beach, mountains, hot and cold weather, you name it. It's not very common to live in another country or to travel to different countries as a Spaniard. It is not in the culture (probably for my parent's friends I'll still be the one that lives in Israel).&lt;/p&gt;

&lt;p&gt;So, I left Spain and took a flight to Bristol, UK and then a bus to &lt;a href="https://en.wikipedia.org/wiki/Wells,_Somerset"&gt;Wells&lt;/a&gt;, Somerset. I was like this guy moving from the town to the city. Even though Wells is known to be the smallest city in England, my thoughts were that the world was bigger than what I had imagine.&lt;/p&gt;

&lt;p&gt;My English was like &lt;a href="https://www.youtube.com/watch?v=H-oH-TELcLE"&gt;Manuel's from Fawlty Towers&lt;/a&gt;, but I had a contract with a local hotel to start working as a waiter in their restaurant. As my English improved, I started getting more tasks to do, at some point I ended up covering some shifts as a receptionist.&lt;/p&gt;

&lt;p&gt;I met awesome people from different countries, staff and customers. This helped me to better understand other cultures and not feel like that boy coming from the town. I even got to do an Interrail 🚂 trip from Amsterdam to Vienna, through Berlin, Warsaw, Krakow, and Prague.&lt;/p&gt;

&lt;p&gt;After a year and a half, I was ready to move on.&lt;/p&gt;

&lt;h2&gt;
  
  
  To Israel
&lt;/h2&gt;

&lt;p&gt;I always wanted to live in Israel and I arrived in 2012 full of energy. Originally, I thought speaking English was gonna be good enough but unfortunately that wasn’t the case. &lt;/p&gt;

&lt;p&gt;The First two years were good, I really enjoyed myself but after that I got my nationality and had to start working (like a real job👔).&lt;/p&gt;

&lt;p&gt;In 2015, I went to one of those agencies that find you a place to work. Due to my lack on the local language, the only position I could find was cleaning in a school. It was not the best job in the world but at least I started working at 10am so I could go to sleep late 🦉. That same year I met my wife and got married, she is also Spaniard but from a different city. When school closed for summer vacation, I decided I had to find something else.&lt;/p&gt;

&lt;p&gt;During that summer I worked in a cafe, and although I learned some Hebrew there, the salary wasn't great, so I went to the next opportunity. I took a job as animal caretaker in a laboratory of the Hebrew University, Jerusalem. &lt;/p&gt;

&lt;p&gt;The job there was basically taking care of the animals (mice🐭, rats🐀 and rabbits 🐇), feed them and clean their cages. &lt;/p&gt;

&lt;p&gt;In 2016, whilst working at the lab, my first son was born. I worked there for over a year and then started having problems with my back due to the workload.&lt;/p&gt;

&lt;p&gt;Next stop was ticket controller on the light rail 🚆. In this job I picked up Hebrew much quicker as I was always out on the street and talking with lots of people.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Thoughts
&lt;/h3&gt;

&lt;p&gt;In January 2018, I realized I needed a &lt;strong&gt;BIG CHANGE&lt;/strong&gt;. My wife was expecting again (our daughter).&lt;/p&gt;

&lt;p&gt;I was working shifts on the light rail, but for years I had had the fear that I wouldn’t be enough, enough to provide for my growing family and enough for myself.&lt;/p&gt;

&lt;p&gt;I'm a quick learner, I learned English and Hebrew on the fly, no lessons. I started thinking I could do better, I needed to do better.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⬇Start talking about code here⬇
&lt;/h3&gt;

&lt;p&gt;With the above said, let's talk some code.&lt;/p&gt;

&lt;p&gt;I have this friend (with time he became &lt;a href="https://www.linkedin.com/in/hillel-g-austria/"&gt;my mentor&lt;/a&gt;) that told me that he was a &lt;strong&gt;web developer&lt;/strong&gt;, to be honest I always liked nice effects on websites and things like that, but never thought about what was behind it. I started playing around with the basics for a couple of months and then decided I needed a place to go to boost my learning (my respects for people I see nowadays learning online, alone). &lt;/p&gt;

&lt;p&gt;So, I went to the John Bryce academy asking about a course in web development and they offered me a Full Stack Course of one year. I didn't have the money, I didn't have the time, but &lt;strong&gt;I had the motivation and a wonderful wife!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1175696731897548801-113" src="https://platform.twitter.com/embed/Tweet.html?id=1175696731897548801"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1175696731897548801-113');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1175696731897548801&amp;amp;theme=dark"
  }



&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1175696733931786240-887" src="https://platform.twitter.com/embed/Tweet.html?id=1175696733931786240"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1175696733931786240-887');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1175696733931786240&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;With my salary, we had enough to cover the monthly expenses but my wife decided to start working so I could study. Pregnant and with our son (he was staying home with her), she found a kinder garden where she could work and also take our son. Their day was like leaving home before 7am and back home at almost 6pm.&lt;/p&gt;

&lt;p&gt;In May 2018, after going to a taster session to find out if I could understand the language (Hebrew), I decided I would go for it. My days were tough, my shifts at work were from 7am to 5pm, and I had lessons twice a week from 6pm until 10pm. It got better when I started getting homework and semester projects 😂. I didn't have an office at home, just my laptop and no fancy setup. I remember putting a desk in our room, and the back of my chair was against the bed and my knees against the desk.&lt;/p&gt;

&lt;p&gt;We were like zombies, and we barely saw each other part from weekends, but I was getting pretty good grades and I realized after 30 years, &lt;strong&gt;I had finally found my passion&lt;/strong&gt;. I could (and still do) talk about code all day, learn new stuff and enjoy everything I am learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Landed My First Job
&lt;/h3&gt;

&lt;p&gt;About half a year after I started learning, my friend (mentioned above) talked to me about an opening position they had at his company. His boss called me, we talked, I was so nervous I talked too much😅, but they hired me. No exam, nothing, just the trust of this friend that I could do the job. &lt;strong&gt;To this day, that is coming back to me as impostor syndrome&lt;/strong&gt;. I see many people struggling to get that first job, and for me it was just a quick phone call.&lt;/p&gt;

&lt;p&gt;So, I signed a contract with them for a couple of months, that's what the original offer was. I learned things I wouldn't learn in the course. I learned new technologies, how to work with a team, build web pages from simple mock-ups given from the designer and much much more!&lt;/p&gt;

&lt;p&gt;At the end of the contract, due to company policy, I had to leave, BUT the boss saw that I was delivering and growing very fast, so he hired me as a contractor and I was able to work there for the whole year.&lt;/p&gt;

&lt;p&gt;I was working up to 4 days a week, sometimes just 3 (which it was fine during the time I was still studying), but my contract was renewed every two months. I was very happy working there but I decided to start looking for a full time job.&lt;/p&gt;

&lt;p&gt;I was working up to 4 days days a week, sometimes just 3 (which it was fine during the time I was still studying), but my contract was renewed every two months. Even that I was very happy working there, I starting looking for a full time job. &lt;/p&gt;

&lt;p&gt;I started simple, passing my CV to friends. I'm a low profile (or that I thought). One came back with an interview over the phone, where I had to record myself while answering questions on the phone. I passed that first step of the interview and went to a face to face interview with the hiring manager. I've read many tips on what to do before an interview, the one I give you is, &lt;strong&gt;think about the interview as if you were chatting with a friend&lt;/strong&gt;, this gave me confidence, thinking that the person in front of me was not judging me but wanted to know me better.&lt;/p&gt;

&lt;p&gt;I passed this step too and I was given an exam, a home assignment and code review after I finished it. After the code review I got to the final step! Passed the HR interview, then got an offer which I accepted 🍾🥂. This was December 2019.&lt;/p&gt;

&lt;p&gt;Even though I am working full time I continue learning and building my side projects. I have started to become more active in the Twitter tech community and started blogging as well.&lt;/p&gt;




&lt;p&gt;Thank you for reading, if you have any questions or would like to know me better, you can always find me on Twitter &lt;a href="https://twitter.com/eligarlo"&gt;@eligarlo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>career</category>
      <category>motivation</category>
      <category>webdev</category>
    </item>
    <item>
      <title>VueJs - Interpolations</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Mon, 31 Aug 2020 02:02:03 +0000</pubDate>
      <link>https://dev.to/eligarlo/vuejs-interpolations-f3</link>
      <guid>https://dev.to/eligarlo/vuejs-interpolations-f3</guid>
      <description>&lt;h3&gt;
  
  
  Hi &lt;em&gt;vue&lt;/em&gt; and welcome to &lt;strong&gt;VueJs, The Series&lt;/strong&gt; 🚀
&lt;/h3&gt;




&lt;p&gt;&lt;em&gt;This article was first posted on my &lt;a href="https://blog.eligarlo.dev/"&gt;blog&lt;/a&gt;, here is the &lt;a href="https://blog.eligarlo.dev/vuejs-the-series-interpolations"&gt;article&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Spoiler alert&lt;/strong&gt;🚨: In case you missed &lt;a href="https://dev.to/eligarlo/vuejs-getting-started-158i"&gt;VueJs - Getting Started&lt;/a&gt; go and check it out.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Interpolation?
&lt;/h2&gt;

&lt;p&gt;When we talk about interpolation, aka "String Interpolation", we talk about the "Mustache" syntax we saw in the &lt;a href="https://dev.to/eligarlo/vuejs-getting-started-158i"&gt;previous episode&lt;/a&gt;, &lt;code&gt;{{ }}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There are 4 types of interpolations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Text&lt;/li&gt;
&lt;li&gt;JavaScript Expressions&lt;/li&gt;
&lt;li&gt;Raw HTML&lt;/li&gt;
&lt;li&gt;Attributes&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Text
&lt;/h2&gt;

&lt;p&gt;We already saw it when we had this HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{{ title }}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's also bring our Vue instance for reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&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;I'm Interpolating!&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;We see that Vue is accessing the &lt;em&gt;data&lt;/em&gt; property inside our Vue instance, is grabbing the &lt;em&gt;title&lt;/em&gt; and 'binding' it's value inside our &lt;code&gt;{{ title }}&lt;/code&gt;. That's it, there is nothing else to see here. 👀&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Expressions
&lt;/h2&gt;

&lt;p&gt;Vue supports JavaScript expressions, so basically we can throw any JavaScript code inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;2 * 2 = {{ 2 * 2 }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Today is {{ new Date().toDateString() }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- It also works with ternary expressions --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;And the output is: {{ foo ? 'bar' : 'baz' }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the ternary? 🤷‍♂️&lt;/p&gt;

&lt;p&gt;It will be &lt;em&gt;baz&lt;/em&gt; because &lt;em&gt;foo&lt;/em&gt; is undefined in our Vue instance, so is evaluated as false.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠Attention⚠, Vue will bind only one single expression, so the following code won't run.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;{{ let myVariable = 'be' }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;{{ if (foo) { return 'bar' } }}&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above won't work because neither are JavaScript Expressions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Raw HTML
&lt;/h2&gt;

&lt;p&gt;Until here we saw that whatever was inside our Mustache &lt;code&gt;{{ }}&lt;/code&gt; was text, or interpreted as text, but what about if we want to bind some HTML? Imagine that we have a JSON where we have stored the content of the website, or we fetch it from the back-end. Most of the time, we will store the content as plain text, but sometimes we might get HTML instead.&lt;/p&gt;

&lt;p&gt;For this we will need to use the &lt;code&gt;v-html&lt;/code&gt; &lt;strong&gt;directive&lt;/strong&gt;. Don't worry for now, we'll cover what directives are.&lt;/p&gt;

&lt;p&gt;For the purpose of these tutorial let's put that HTML in our &lt;em&gt;title&lt;/em&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&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;&amp;lt;h1 style='color: blue;'&amp;gt;I'm Interpolating!&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our HTML now we don't need to grab the &lt;code&gt;{{ title }}&lt;/code&gt; inside the &lt;code&gt;h1&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  {{ title }}
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As explained before, Vue will interpret this as text so the output will be 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QA_Kxfb_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1598608723790/PxQfY7mA2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QA_Kxfb_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1598608723790/PxQfY7mA2.jpeg" alt="Interpolations.JPG" width="694" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we need to do in order to see our HTML as HTML is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;v-html=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We used an HTML tag, in this case a &lt;code&gt;span&lt;/code&gt;, inside it's opening tag we added our directive &lt;code&gt;v-html&lt;/code&gt;, and as a value we passed our &lt;code&gt;title&lt;/code&gt;. What Vue will do is to pass that value of &lt;code&gt;title&lt;/code&gt; inside the span. Let's see if this time worked 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Ap9_QcT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1598609424555/GwUuAv-cQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Ap9_QcT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1598609424555/GwUuAv-cQ.jpeg" alt="Interpolations-2.JPG" width="725" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Attributes
&lt;/h2&gt;

&lt;p&gt;As we saw with the &lt;code&gt;v-html&lt;/code&gt;, there are times when we need to pass certain values to our HTML, for that, we use directives. Imagine we have to put a dynamic &lt;code&gt;id&lt;/code&gt;, inside of a &lt;code&gt;div&lt;/code&gt; in our HTML. For this we can use the &lt;code&gt;v-bind&lt;/code&gt; directive. Again, don't worry, &lt;strong&gt;directives will be cover in future episodes of this series&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The syntax is quite similar as the previous example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;v-bind:id=&lt;/span&gt;&lt;span class="s"&gt;"dynamicId"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look how we add &lt;code&gt;:id&lt;/code&gt; after &lt;code&gt;v-bind&lt;/code&gt; to tell Vue that what we want will be this &lt;code&gt;&amp;lt;span id="1"&amp;gt;&amp;lt;/span&amp;gt;&lt;/code&gt;, well if dynamicId had the value of 1 😅&lt;/p&gt;

&lt;p&gt;And we can do more with &lt;code&gt;v-bind&lt;/code&gt;. Imagine we have a button that we want to show as disabled. All we have to do is to add &lt;code&gt;:disabled&lt;/code&gt; at the end of &lt;code&gt;v-bind&lt;/code&gt;. But for this we won't give a value that Vue can interpret as string. Vue needs to know if we want this button to be disabled, YES or NO, so will check if the value is true or false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;v-bind:disabled=&lt;/span&gt;&lt;span class="s"&gt;"isButtonDisabled"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sign In&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our case, &lt;code&gt;isButtonDisabled&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;, so Vue won't even render the attribute disabled, and this will happen if the the value is also &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this episode we covered the following: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We can do interpolations as plain &lt;strong&gt;Text&lt;/strong&gt; with Mustache syntax &lt;code&gt;{{ }}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Inside the Mustache syntax we can have &lt;strong&gt;JavaScript Expressions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In order to render &lt;strong&gt;Raw HTML&lt;/strong&gt; we need the &lt;code&gt;v-html&lt;/code&gt; directive.&lt;/li&gt;
&lt;li&gt;We can dynamically change &lt;strong&gt;Attributes&lt;/strong&gt; with the &lt;code&gt;v-bind&lt;/code&gt; directive.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://github.com/eligarlo/VueJs-The-Series/tree/master/Episode%202%20-%20Interpolations"&gt;GitHub repo&lt;/a&gt; for the code used in this episode.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Did you enjoy this article?&lt;/strong&gt; Don't be selfish, go on and share the knowledge!&lt;br&gt;
You can also find me on Twitter &lt;a href="https://twitter.com/eligarlo"&gt;@eligarlo&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>vue</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>VueJs - Getting Started</title>
      <dc:creator>Eliahu Garcia Lozano</dc:creator>
      <pubDate>Thu, 13 Aug 2020 06:28:56 +0000</pubDate>
      <link>https://dev.to/eligarlo/vuejs-getting-started-158i</link>
      <guid>https://dev.to/eligarlo/vuejs-getting-started-158i</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was first posted on my &lt;a href="https://blog.eligarlo.dev/"&gt;blog&lt;/a&gt;, here is the &lt;a href="https://blog.eligarlo.dev/vuejs-getting-started-ckdsf2yxe00wz97s12ef9a0ix"&gt;article&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;“&lt;em&gt;To get started with Vue, all you need is familiarity with HTML and JavaScript. With these basic skills, you can start building non-trivial applications within less than a day&lt;/em&gt;”- &lt;strong&gt;VueJs Docs&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Hi &lt;em&gt;vue&lt;/em&gt; and welcome to &lt;strong&gt;VueJs, The Series&lt;/strong&gt; 🚀
&lt;/h3&gt;

&lt;p&gt;In this first episode we will be covering the following topics:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Table of Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Getting Vue In Our Machine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Setting Up Our Environment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Conclusion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Getting Vue In Our Machine&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We have a few different ways to install vue as you can see &lt;a href="https://vuejs.org/v2/guide/installation.html"&gt;here&lt;/a&gt;. But for the purpose of this tutorial I'll be using CDN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Don't use this CDN for production.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Setting Up Our Environment&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We will need an &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;app.js&lt;/code&gt; files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- VueJs Import --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;VueJs - Getting Started&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{{ title }}&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;index.html&lt;/code&gt; should look like this ☝&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Imported VueJs CDN.&lt;/li&gt;
&lt;li&gt;Created a div with an id of app.&lt;/li&gt;
&lt;li&gt;Inside app created a title.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's go over 2 and 3 for a second:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The div will be under control of the Vue instance.&lt;/li&gt;
&lt;li&gt;Title uses the special syntax that Vue will recognize and interpolate from our Vue instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your &lt;code&gt;app.js&lt;/code&gt; should look like this 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&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;Hello 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hold your 🏇🏇, WHAT?&lt;/p&gt;

&lt;p&gt;We created our Vue instance with &lt;code&gt;new Vue()&lt;/code&gt; that takes an object as an argument.&lt;/p&gt;

&lt;p&gt;Then we have the &lt;code&gt;el&lt;/code&gt; and &lt;code&gt;data&lt;/code&gt; properties. All properties (there are more and we will see them in this series) have reserved names that Vue will recognize.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;el&lt;/code&gt; property we need to pass the html &lt;code&gt;el&lt;/code&gt;ement that we want the Vue instance to take control.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;data&lt;/code&gt; property we store all the data we want to use in our Vue instance. Think of the properties store inside the data object as variables, you can have strings, booleans, arrays...&lt;br&gt;
In our case the data property is the string Hello world, very creative right?&lt;/p&gt;

&lt;p&gt;Ok, so let's open our html file and see what we got there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq74kcbsk59ta72r19qx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq74kcbsk59ta72r19qx9.png" alt="Alt Text" width="636" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations, we created our first VueJs app! 🎉🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In this episode we covered the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We installed the VueJs framework using CDN.&lt;/li&gt;
&lt;li&gt;We created our html template and use the special &lt;code&gt;{{ }}&lt;/code&gt; syntax.&lt;/li&gt;
&lt;li&gt;We created our Vue instance and explain about the &lt;code&gt;el&lt;/code&gt; and &lt;code&gt;data&lt;/code&gt; properties.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TODO:&lt;/strong&gt; Build this Hello World app by your own but this time instead of using a CDN, install Vue in a different way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://vuejs.org/v2/guide/installation.html"&gt;Here&lt;/a&gt; is again the link for the other installation options.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/eligarlo/VueJs-The-Series/tree/master/Episode%201%20-%20Getting%20Started"&gt;GitHub repo&lt;/a&gt; for the code used in this episode.&lt;/p&gt;




&lt;p&gt;Find me on Twitter &lt;a href="https://twitter.com/eligarlo"&gt;@eligarlo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
