<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Eliahu Garcia Lozano]]></title><description><![CDATA[Passionate JavaScript/React developer with more than five years of experience. Highly adaptable, Problem solver with dedication to ongoing learning.]]></description><link>https://blog.eligarlo.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 16:52:24 GMT</lastBuildDate><atom:link href="https://blog.eligarlo.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Unlocking Improved Accessibility with React's createPortal Method]]></title><description><![CDATA[React is a popular JavaScript library that provides developers with a powerful and efficient way to build user interfaces. One of the key features of React is the ability to use a method called createPortal to render components outside the main conte...]]></description><link>https://blog.eligarlo.dev/react-createportal-improved-accessibility</link><guid isPermaLink="true">https://blog.eligarlo.dev/react-createportal-improved-accessibility</guid><category><![CDATA[React]]></category><category><![CDATA[ReactHooks]]></category><category><![CDATA[Accessibility]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Sat, 18 Mar 2023 19:05:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679165569744/928ae8e6-e732-4929-862b-21a8aff46f4d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React is a popular JavaScript library that provides developers with a powerful and efficient way to build user interfaces. One of the key features of React is the ability to use a method called <code>createPortal</code> to render components outside the main content flow of a web page. In this blog post, we will explore the benefits of using <code>createPortal</code>, how it can help improve accessibility, and how it differs from <code>createRoot</code>.</p>
<h2 id="heading-what-is-react-createportal">What is React createPortal?</h2>
<p>In React, <code>createPortal</code> is a method that allows developers to render a React component into a container that exists outside of the parent component hierarchy. This is particularly useful when building user interfaces that require the rendering of elements outside the main content flow of the page, such as modal dialogs, tooltips, and dropdown menus.</p>
<p>The syntax for using <code>createPortal</code> is straightforward. You can use it by importing the method from the <code>react-dom</code> package, and passing in the component that you want to render, along with a reference to the container where you want to render it. Here's an example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1679163599526/5f044329-eb4f-4783-8577-a5bb3763506e.png" alt class="image--center mx-auto" /></p>
<p>In this example, we're using <code>createPortal</code> to render a <code>MyModal</code> component into a container with the ID of <code>modal-root</code>. This container can be located anywhere in the HTML of the web page, and the <code>MyModal</code> component will be rendered inside of it, outside of the main content flow of the page.</p>
<h2 id="heading-accessibility-benefits-of-react-createportal">Accessibility Benefits of React createPortal</h2>
<p>One of the key benefits of using <code>createPortal</code> is that it can help improve accessibility in your React application. When using <code>createPortal</code>, the focus is automatically shifted to the new component when it's rendered, making it clear to users that they are interacting with a separate element on the page. This can help prevent confusion for users who rely on assistive technologies, like screen readers or keyboard navigation.</p>
<p>In addition to this, <code>createPortal</code> also helps prevent accessibility issues that can arise when using traditional CSS techniques to position elements outside of the main content flow. For example, if you use absolute positioning to display a modal dialog, the dialog may not be visible to users who are navigating the page with a keyboard. <code>createPortal</code> avoids this issue by rendering the modal outside of the main content flow, but still keeping it part of the React tree.</p>
<h2 id="heading-how-is-createportal-different-from-createroot">How is createPortal Different from createRoot?</h2>
<p>While <code>createPortal</code> and <code>createRoot</code> are both methods provided by React to help developers manage the rendering of components, they have different use cases and behaviors.</p>
<p>As mentioned earlier, <code>createPortal</code> is used to render a React component into a container that exists outside of the parent component hierarchy. This is useful when you need to render UI components outside the main content flow of the page.</p>
<p>On the other hand, <code>createRoot</code> is used to render a React tree into a container that is not yet attached to the DOM. This is useful for server-side rendering, where you need to generate HTML markup on the server and send it to the client. It's also useful for pre-rendering components that will be mounted later in the application lifecycle.</p>
<p>Here's an example of how to use <code>createRoot</code> to render a React component:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1679163962305/09f0f517-cff4-432c-9ea4-022ced66f4f5.png" alt class="image--center mx-auto" /></p>
<p>In this example, we're using <code>createRoot</code> to render a <code>MyComponent</code> component into a container with the ID of <code>root</code>. This container doesn't exist yet in the DOM, so we use <code>createRoot</code> to create it and then render the component inside of it.</p>
<p>It's important to note that <code>createRoot</code> is only available in React version 18 and later, so if you're using an earlier version of React, you won't be able to use this method.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In summary, <code>createPortal</code> and <code>createRoot</code> are two powerful methods provided by React to help developers manage the rendering of components. <code>createPortal</code> is used to render components outside of the main content flow of a web page, which can help improve accessibility and prevent issues with positioning elements using traditional CSS techniques. On the other hand, <code>createRoot</code> is used to render a React tree into a container that is not yet attached to the DOM, which is useful for server-side rendering and pre-rendering components.</p>
<p>By using these methods, you can create more robust and efficient user interfaces in your React applications.</p>
<blockquote>
<p>If you found it useful, like, subscribe, and share the knowledge.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Why I started #30days30walks Challenge]]></title><description><![CDATA[To improve my health, I recently started the #30days30walks challenge. In this post, I want to share why this important to me and why I highly recommend other devs to start doing something similar.

If this is your first time reading my blog and you ...]]></description><link>https://blog.eligarlo.dev/why-i-started-30days30walks-challenge</link><guid isPermaLink="true">https://blog.eligarlo.dev/why-i-started-30days30walks-challenge</guid><category><![CDATA[life]]></category><category><![CDATA[lifestyle]]></category><category><![CDATA[work]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Mon, 15 Mar 2021 18:24:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1615831801477/ob0PmGgch.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To improve my health, I recently started the #30days30walks challenge. In this post, I want to share why this important to me and why I highly recommend other devs to start doing something similar.</p>
<blockquote>
<p>If this is your first time reading my blog and you want to know more about me, make sure you subscribe and <a target="_blank" href="https://twitter.com/intent/user?screen_name=eligarlo">follow me</a> on Twitter.</p>
</blockquote>
<h2 id="some-background">Some Background</h2>
<p>Before I started working as a web developer, I worked on many other things. Most of them required physical effort of some kind. When I was a carpenter, I used to lift heavy stuff most of the time, and working in a mall or as a waiter, I used to expend a lot of hours on my feet.</p>
<p>Also, I worked out way more than I do now. For instance, when I was living in Spain, I played football (⚽) every weekend and twice a week I trained.</p>
<p>In my middle 20's my weight was around 70kg. As I said, I used to exercise a lot.</p>
<h2 id="web-development-and-pandemic">Web development and Pandemic</h2>
<p>We, as web developers, are sitting down most of the time. And this might not be a problem if you have other activities, like going to the gym or hurrying after that train or bus to get to the office. Because working out is not just lifting weight, but moving your body.</p>
<p>That routine changed for me in March 2020. With the first lockdown we lived in Israel, I started working from home. That meant no more hurrying to catch a train or bus to get to the office. If I used to do around 9k steps per day, it dropped to 1k per day.</p>
<p>Although I tried a few times to start running in the evenings, it didn't endure, and 11 months later I found myself with my back hurting and 91kg of weight.</p>
<h2 id="real-problem">Real Problem</h2>
<p>One day I couldn't sit down because my back was hurting and I worked all day standing up. I remember the next day also my legs were hurting and I had to take the day off. </p>
<p>After an x-ray and a visit to the doctor, I was diagnosed with a herniated disc. Lucky me was still in an early stage so with physiotherapy and exercise I could avoid surgery.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I tweeted this the other day and I think it wraps up everything I want to say.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/eligarlo/status/1369654657115643909">https://twitter.com/eligarlo/status/1369654657115643909</a></div>
<p>For a good work-life balance, stay active and healthy.</p>
<p><em>Picture by <a target="_blank" href="https://unsplash.com/@jontyson">Jon Tyson</a></em></p>
]]></content:encoded></item><item><title><![CDATA[How to Teleport in Vue 3]]></title><description><![CDATA[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 teleport component.
It's well known that modern web applic...]]></description><link>https://blog.eligarlo.dev/how-to-teleport-in-vue-3</link><guid isPermaLink="true">https://blog.eligarlo.dev/how-to-teleport-in-vue-3</guid><category><![CDATA[Vue.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Thu, 21 Jan 2021 19:12:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1611255951206/DKxENS5i8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>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 <code>teleport</code> component.</p>
<p>It's well known that modern web applications fit in a div.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/adrian_twarog/status/1346423883285499904">https://twitter.com/adrian_twarog/status/1346423883285499904</a></div>
<p>Ok, React uses <code>#root</code> and Vue uses <code>#app</code> but they just do the same, which is inject the JavaScript code into that div. So here it comes the question:</p>
<h2 id="what-if-i-have-an-element-i-want-to-display-as-a-sibling-of-the-app-element-in-the-html">What if I have an element I want to display as a sibling of the <code>#app</code> element in the html?</h2>
<p>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 <code>#app</code> element. Thus, the html will look like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
      <span class="hljs-comment">&lt;!-- Other injected HTML here --&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loader"</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- HTML for the loader goes here --&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="lets-teleport">Let's teleport!</h3>
<p><img src="https://media.giphy.com/media/cW55zyF7dJAf6/giphy.gif" alt="Goku Teleport" /></p>
<p>To use the teleport component in your app, you need to first, add a sibling to the <code>#app</code> element in the html.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-comment">&lt;!-- built files will be auto injected --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loader"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-comment">&lt;!-- loader component will be injected here --&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Once you've done that, go to your <code>.vue</code> file and use the teleport component:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">teleport</span> <span class="hljs-attr">to</span>=<span class="hljs-string">".loader"</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">"showLoader"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Loader</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">teleport</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- The logic of your component goes below --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>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: <code>&lt;teleport to="#loader" v-if="showLoader"&gt;</code></p>
<blockquote>
<p>If you found it useful, please like, subscribe, and share the knowledge.</p>
<p>You might like what I share on <a target="_blank" href="https://twitter.com/eligarlo">my Twitter</a> too.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Trim Your Inputs!]]></title><description><![CDATA[Definition of trim, "To cut away unnecessary parts from something." - Oxford Dictionary.

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 t...]]></description><link>https://blog.eligarlo.dev/trim-your-inputs</link><guid isPermaLink="true">https://blog.eligarlo.dev/trim-your-inputs</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[forms]]></category><category><![CDATA[Validation]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Wed, 09 Dec 2020 10:14:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1607454893871/ljuGli8Fi.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>Definition of trim, <em>"To cut away unnecessary parts from something."</em> - Oxford Dictionary.</p>
</blockquote>
<p>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 <code>undefined</code> or <code>null</code>. And after all that validation, you realize that a user typed an empty <code>string</code>. 🤦‍♂️</p>
<p>One of the most common issues about empty strings a developer can face is the one that has spaces.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(myInput)
&gt; <span class="hljs-string">'      '</span>  <span class="hljs-comment">// 👈 Empty String</span>
</code></pre>
<p>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.</p>
<h2 id="use-case">Use Case</h2>
<p>In a login form, you have an input where the user needs to enter a username like the one below.</p>
<p><img src="https://media.giphy.com/media/WRD4arnA3ed8A1ceaD/giphy.gif" alt="login form" /></p>
<p>👆 Did you notice the whitespace at the beginning and the end of the input?</p>
<p>If we have a look at our code, the <code>input</code> would be like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter Username"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>&gt;</span>
</code></pre>
<p>And the JavaScript like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> userNameInput = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'.username'</span>)

<span class="hljs-built_in">console</span>.log(userNameInput)
&gt; <span class="hljs-string">'   Eliahu Garcia Lozano   '</span>
</code></pre>
<p>Time to get rid of the whitespaces 🧹.</p>
<h2 id="trimstart-and-trimleft">TrimStart and TrimLeft</h2>
<p>These two will remove the whitespace from the beginning of a string.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userNameInput.trimStart())
&gt; <span class="hljs-string">'Eliahu Garcia Lozano   '</span>
<span class="hljs-built_in">console</span>.log(userNameInput.trimLeft())
&gt; <span class="hljs-string">'Eliahu Garcia Lozano   '</span>
</code></pre>
<h2 id="trimend-and-trimright">TrimEnd and TrimRight</h2>
<p>These two will remove the whitespace from the end of a string.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userNameInput.trimEnd())
&gt; <span class="hljs-string">'   Eliahu Garcia Lozano'</span>
<span class="hljs-built_in">console</span>.log(userNameInput.trimRight())
&gt; <span class="hljs-string">'   Eliahu Garcia Lozano'</span>
</code></pre>
<p>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?</p>
<blockquote>
<p>trimStart and trimEnd are methods while trimLeft and trimRight are aliases of those methods.</p>
</blockquote>
<h2 id="chaining-the-methods">Chaining the methods</h2>
<p>You can use them together to get the desired result.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userNameInput.trimStart().trimEnd())
&gt; <span class="hljs-string">'Eliahu Garcia Lozano'</span>
<span class="hljs-built_in">console</span>.log(userNameInput.trimRight().trimLeft())
&gt; <span class="hljs-string">'Eliahu Garcia Lozano'</span>
</code></pre>
<p>Ok, maybe it is a little bit ugly I know. Let's check the last method, actually the one I use.</p>
<h1 id="trim">Trim</h1>
<p>Just like chaining methods, trim will remove the whitespace from left and right; plus, your code will look cleaner. 😅</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userNameInput.trim())
&gt; <span class="hljs-string">'Eliahu Garcia Lozano'</span>
</code></pre>
<h2 id="validating-the-input">Validating the input</h2>
<p>In many places I've seen this kind of <code>string</code> validation:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (userNameInput !== <span class="hljs-string">""</span>) {
  <span class="hljs-comment">// do something</span>
}
</code></pre>
<p>The problem with this is that the user may enter whitespace.</p>
<p>Now that we know how to <code>trim</code> the value of the input, let's see how to implement it in our form validation.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (userNameInput.trim() !== <span class="hljs-string">""</span>) {
  <span class="hljs-comment">// do something</span>
}
</code></pre>
<p>Do you see the difference?</p>
<h2 id="conclusion">Conclusion</h2>
<p>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.</p>
<p>Remember: </p>
<ul>
<li>.trimStart() &amp; .trimLeft() will remove whitespace from the left.</li>
<li>.trimEnd() &amp; .trimRight() will remove whitespace from the right.</li>
<li>.trim() will remove whitespace from both the left and the right side.</li>
</ul>
<p>From now on, Trim Your <code>&lt;Inputs&gt;</code>! (if you didn't before).</p>
<blockquote>
<p>If you found it useful, please like, subscribe, and share the knowledge.</p>
<p>You might like what I share on <a target="_blank" href="https://twitter.com/eligarlo">my Twitter</a> too.</p>
</blockquote>
<p><em>Cover Picture by <a target="_blank" href="https://unsplash.com/@isra_eh?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Isra E</a> on <a target="_blank" href="https://unsplash.com/s/photos/cut?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></em></p>
]]></content:encoded></item><item><title><![CDATA[Default Function Parameters]]></title><description><![CDATA[We always have to validate if the arguments passed in a function have a value or they are undefined but, do we really?
Introduction
In my last post, I talked about Destructuring Assignment In A Function Parameter and why it is handy when you have opt...]]></description><link>https://blog.eligarlo.dev/default-function-parameters</link><guid isPermaLink="true">https://blog.eligarlo.dev/default-function-parameters</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ES6]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Mon, 07 Dec 2020 10:31:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1607333266545/LUoSo1JKy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We always have to validate if the arguments passed in a function have a value or they are <code>undefined</code> but, do we really?</p>
<h2 id="introduction">Introduction</h2>
<p>In my last post, I talked about <a target="_blank" href="https://blog.eligarlo.dev/destructuring-assignment-in-a-function-parameter">Destructuring Assignment In A Function Parameter</a> and why it is handy when you have optional parameters in a function and don't want to pass <code>undefined</code> or <code>null</code>.</p>
<p>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.</p>
<h2 id="use-case">Use Case</h2>
<p>If you take a Tip Calculator project as an example, you probably will need always the same parameters:</p>
<ol>
<li>Bill Amount.</li>
<li>Number of People.</li>
<li>Service Quality.</li>
</ol>
<p>The function you'll need would look like this 👇</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateTip</span>(<span class="hljs-params">totalBill, numOfPeople, serviceQuality</span>) </span>{
  <span class="hljs-comment">// Your validation here</span>
  <span class="hljs-comment">// Your code here</span>
}

<span class="hljs-built_in">console</span>.log(calculateTip(<span class="hljs-number">50</span>, <span class="hljs-number">2</span> , <span class="hljs-number">0.2</span>))
<span class="hljs-comment">// 5.00</span>
</code></pre>
<p>Inside the function, you'll have to do all the calculations <strong>AND</strong> all the validation; plus, most of the time I go with the same friend (2 people) and leave the standard tip (20%).</p>
<p>In this case, the only parameter that will be changing all the time will be the bill amount.</p>
<p>So, let's give <code>numOfPeople</code> and <code>serviceQuality</code> a default parameter:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateTip</span>(<span class="hljs-params">totalBill, numOfPeople = <span class="hljs-number">2</span>, serviceQuality = <span class="hljs-number">0.2</span></span>) </span>{
  <span class="hljs-comment">// Your code here</span>
}

<span class="hljs-built_in">console</span>.log(calculateTip(<span class="hljs-number">50</span>))
<span class="hljs-comment">// 5.00</span>
<span class="hljs-built_in">console</span>.log(calculateTip(<span class="hljs-number">75</span>))
<span class="hljs-comment">// 7.50</span>
</code></pre>
<p>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.</p>
<h2 id="conclusion">Conclusion</h2>
<p>You don't really need to check if the argument in a function is <code>undefined</code>, you can create a default value for it.</p>
<p>When a different value is provided, the default value will be overwritten.</p>
<blockquote>
<p>If you found it useful, please like, subscribe, and share the knowledge.</p>
<p>You might like what I share on <a target="_blank" href="https://twitter.com/eligarlo">my Twitter</a> too.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Destructuring Assignment In A Function Parameter]]></title><description><![CDATA[Have you ever passed an argument as a null or undefined in a function? Since ES2015 (aka ES6) you don’t have to. You can use JavaScript destructuring.
Use Case
We all have this Utils.js file in our projects where we have all kinds of functions that w...]]></description><link>https://blog.eligarlo.dev/destructuring-assignment-in-a-function-parameter</link><guid isPermaLink="true">https://blog.eligarlo.dev/destructuring-assignment-in-a-function-parameter</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ES6]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Fri, 27 Nov 2020 08:58:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1606433068662/i8yOAuyjX.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever passed an argument as a <code>null</code> or <code>undefined</code> in a function? Since ES2015 (aka ES6) <strong>you don’t have to</strong>. You can use JavaScript destructuring.</p>
<h2 id="use-case">Use Case</h2>
<p>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.</p>
<p>Function declaration would look like this:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addTodoItem</span>(<span class="hljs-params">title, description, dueDate</span>) </span>{
  <span class="hljs-comment">// Your code here</span>
}
</code></pre>
<p>Before calling the function, see the characteristics for each parameter:</p>
<ul>
<li>Title =&gt; required.</li>
<li>Description =&gt; !required.</li>
<li>DueDate =&gt; !required.</li>
</ul>
<p>Let’s add a few items to the list now.</p>
<pre><code class="lang-javascript">addTodoItem(<span class="hljs-string">'Shopping List'</span>, <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-string">'30-11-2020'</span>)
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Shopping List'</span>, <span class="hljs-attr">description</span>: <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'30-11-2020'</span> }
addTodoItem(<span class="hljs-string">'Call Mom'</span>)
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Call Mom'</span> }
addTodoItem(<span class="hljs-string">'Pay Bills'</span>, <span class="hljs-literal">undefined</span>, <span class="hljs-string">'01-12-2020'</span>)
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Pay Bills'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'01-12-2020'</span> }
</code></pre>
<p>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. 🤣</p>
<p>Jokes aside, we see that I had to pass the second value as <code>undefined</code> because the function is expecting the description as the second parameter.</p>
<p>For this specific example, if I wanted to pass a dueDate, first I would have to check whether the description is <code>undefined</code> or not before I call the addTodoItem function.</p>
<p>Here is where using destructuring will be very helpful.</p>
<p>This is how the addTodoItem would look now. 👇</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addTodoItem</span>(<span class="hljs-params">{title, description, dueDate}</span>) </span>{
  <span class="hljs-comment">// Your code here</span>
}
</code></pre>
<p>Let’s add again the same items as before.</p>
<pre><code class="lang-javascript">addTodoItem({ <span class="hljs-attr">title</span>: <span class="hljs-string">'Shopping List'</span>, <span class="hljs-attr">description</span>: <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'30-11-2020'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Shopping List'</span>, <span class="hljs-attr">description</span>: <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'30-11-2020'</span> }
addTodoItem({ <span class="hljs-attr">title</span>: <span class="hljs-string">'Call Mom'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Call Mom'</span> }
addTodoItem({ <span class="hljs-attr">title</span>: <span class="hljs-string">'Pay Bills'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'01-12-2020'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Pay Bills'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'01-12-2020'</span> }
</code></pre>
<p>If you pay attention to the last item added, you’ll see that there was no need on adding the <code>undefined</code> for the description. Just title and dueDate.</p>
<h2 id="bonus">Bonus!</h2>
<p>There is more: not only do you not need to pass <code>undefined</code> anymore, but you can even change the order of how you pass the arguments and it will still work.</p>
<pre><code class="lang-javascript">addTodoItem({ <span class="hljs-attr">description</span>: <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'30-11-2020'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'Shopping List'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Shopping List'</span>, <span class="hljs-attr">description</span>: <span class="hljs-string">'eggs, milk'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'30-11-2020'</span> }
addTodoItem({ <span class="hljs-attr">title</span>: <span class="hljs-string">'Call Mom'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Call Mom'</span> }
addTodoItem({ <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'01-12-2020'</span>, <span class="hljs-attr">title</span>: <span class="hljs-string">'Pay Bills'</span> })
&gt; { <span class="hljs-attr">title</span>: <span class="hljs-string">'Pay Bills'</span>, <span class="hljs-attr">dueDate</span>: <span class="hljs-string">'01-12-2020'</span> }
</code></pre>
<h2 id="conclusion">Conclusion</h2>
<p>That’s it! We saw how to use destructuring when declaring a function and how to call that function and provide the arguments. </p>
<p>Remember that you can get rid of the <code>undefined</code> or <code>null</code> since the order of the arguments doesn’t matter.</p>
<p>PS. Remember to pay your bills. 🤣</p>
<blockquote>
<p>If you found it useful, please like, subscribe, and share the knowledge.</p>
<p>You might like what I share on <a target="_blank" href="https://twitter.com/eligarlo">my Twitter</a> too.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Copyright Up To Date (The Automate Way)]]></title><description><![CDATA[Let's be honest, outdated copyright disclaimers on a website looks bad. 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 ...]]></description><link>https://blog.eligarlo.dev/copyright-up-to-date-the-automate-way</link><guid isPermaLink="true">https://blog.eligarlo.dev/copyright-up-to-date-the-automate-way</guid><category><![CDATA[HTML5]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Tue, 06 Oct 2020 04:57:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1601959721365/uSFiZSDZ4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>Let's be honest, <strong>outdated copyright disclaimers on a website looks bad</strong>. 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 <strong>automate this task with 2 lines of code</strong>. If you want to know more about the importance of updating your copyright dates I found <a target="_blank" href="https://sonet.digital/blog/general/keep-copyright-up-to-date/">this post</a> with a more in-depth explanation.</p>
</blockquote>
<p>First, let's create a basic HTML template where we will have our copyright disclaimer at the footer:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>Lorem ipsum dolor sit<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>Lorem ipsum dolor sit amet consectetur adipisicing elit.<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>Copyright © <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"copyright"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>, My Company Name<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"app.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>And then, our javascript will look like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> copyright = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'#copyright'</span>)

copyright.innerHTML = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getFullYear()
</code></pre>
<p>That's it, you are cover now. 😎</p>
<p>Bonus tip:💡</p>
<p>In case you need a range of years instead of a single year in your copyright disclaimer, you can easily tweak the above code.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>Copyright © <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"copyright"</span>&gt;</span>2010 - <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>, My Company Name<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> copyright = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'#copyright'</span>)

copyright.innerHTML += <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getFullYear()
</code></pre>
<hr />
<p>Thank you for reading, if you like my content, you can always find me on Twitter <a target="_blank" href="https://twitter.com/eligarlo">@eligarlo</a>.</p>
]]></content:encoded></item><item><title><![CDATA[My Journey Into Tech (In A Foreign Country)]]></title><description><![CDATA[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…she found a kinder garden where she could work and also take our son.

Hi there 👋, after the first two posts...]]></description><link>https://blog.eligarlo.dev/my-journey-into-tech-in-a-foreign-country</link><guid isPermaLink="true">https://blog.eligarlo.dev/my-journey-into-tech-in-a-foreign-country</guid><category><![CDATA[Career]]></category><category><![CDATA[motivation]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Fri, 04 Sep 2020 08:17:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598846178965/VQ4gLBuhT.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>With my salary, we had enough to cover the monthly expenses but <strong>my wife decided to start working so I could study</strong>. Pregnant and with our son…she found a kinder garden where she could work and also take our son.</p>
</blockquote>
<p>Hi there 👋, after the first two posts of <a target="_blank" href="https://blog.eligarlo.dev/vuejs-the-series-getting-started">VueJs, The Series 🚀</a>, I wanted to post something about me and my journey into tech.</p>
<p>To give you some context, I'm Eliahu, you can find me on Twitter <a target="_blank" href="https://twitter.com/eligarlo">@eligarlo</a>, 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.</p>
<h2 id="from-spain">From Spain</h2>
<p>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.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/eligarlo/status/1291645278420951040?s=20">https://twitter.com/eligarlo/status/1291645278420951040?s=20</a></div>
<h2 id="through-england">Through England</h2>
<p>In Spain, you have everything, beaches, 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).</p>
<p>So, I left Spain and took a flight to Bristol, UK, and then a bus to <a target="_blank" href="https://en.wikipedia.org/wiki/Wells,_Somerset">Wells</a>, 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 imagined.</p>
<p>My English was like <a target="_blank" href="https://www.youtube.com/watch?v=H-oH-TELcLE">Manuel's from Fawlty Towers</a>, 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.</p>
<p>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.</p>
<p>After a year and a half, I was ready to move on.</p>
<h2 id="to-israel">To Israel</h2>
<p>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. </p>
<p>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👔).</p>
<p>In 2015, I went to one of those agencies that find you a place to work. Due to my lack of 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 10 am 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 the school closed for summer vacation, I decided I had to find something else.</p>
<p>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 an animal caretaker in a laboratory of the Hebrew University, Jerusalem. </p>
<p>The job there was basically taking care of the animals (mice🐭, rats🐀 , and rabbits 🐇), feed them, and clean their cages. </p>
<p>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.</p>
<p>The 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.</p>
<h3 id="deep-thoughts">Deep Thoughts</h3>
<p>In January 2018, I realized I needed a <strong>BIG CHANGE</strong>. My wife was expecting again (our daughter).</p>
<p>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.</p>
<p>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.</p>
<h3 id="start-talking-about-code-here">⬇Start talking about code here⬇</h3>
<p>With the above said, let's talk about some code.</p>
<p>I have this friend (with time he became <a target="_blank" href="https://www.linkedin.com/in/hillel-g-austria/">my mentor</a>) that told me that he was a <strong>web developer</strong>, 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 respect for people I see nowadays learning online, alone). </p>
<p>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 <strong>I had the motivation and a wonderful wife!</strong></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/eligarlo/status/1175696733931786240?s=20">https://twitter.com/eligarlo/status/1175696733931786240?s=20</a></div>
<p>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 7 am and back home at almost 6 pm.</p>
<p>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 7 am to 5 pm, and I had lessons twice a week from 6 pm until 10 pm. 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.</p>
<p>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, <strong>I had finally found my passion</strong>. I could (and still do) talk about code all day, learn new stuff and enjoy everything I am learning.</p>
<h3 id="landed-my-first-job">Landed My First Job</h3>
<p>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. <strong>To this day, that is coming back to me as impostor syndrome</strong>. I see many people struggling to get that first job, and for me, it was just a quick phone call.</p>
<p>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 by the designer, and much much more!</p>
<p>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.</p>
<p>I was working up to 4 days a week, sometimes just 3 (which 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.</p>
<p>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, <strong>think about the interview as if you were chatting with a friend</strong>, this gave me confidence, thinking that the person in front of me was not judging me but wanted to know me better.</p>
<p>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 that I accepted 🍾🥂. This was December 2019.</p>
<p>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.</p>
<hr />
<p>Thank you for reading, if you have any questions or would like to know me better, you can always find me on Twitter <a target="_blank" href="https://twitter.com/eligarlo">@eligarlo</a>.</p>
]]></content:encoded></item><item><title><![CDATA[VueJs - Interpolations]]></title><description><![CDATA[Hi vue and welcome to VueJs, The Series 🚀


Spoiler alert🚨: In case you missed VueJs - Getting Started go and check it out.

What is Interpolation?
When we talk about interpolation, aka "String Interpolation", we talk about the "Mustache" syntax we...]]></description><link>https://blog.eligarlo.dev/vuejs-the-series-interpolations</link><guid isPermaLink="true">https://blog.eligarlo.dev/vuejs-the-series-interpolations</guid><category><![CDATA[Vue.js]]></category><category><![CDATA[vue]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Fri, 28 Aug 2020 11:00:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1599457602214/47_gB_kNS.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="hi-vue-and-welcome-to-vuejs-the-series">Hi <em>vue</em> and welcome to <strong>VueJs, The Series</strong> 🚀</h3>
<hr />
<blockquote>
<p><strong>Spoiler alert</strong>🚨: In case you missed <a target="_blank" href="https://blog.eligarlo.dev/vuejs-the-series-getting-started">VueJs - Getting Started</a> go and check it out.</p>
</blockquote>
<h2 id="what-is-interpolation">What is Interpolation?</h2>
<p>When we talk about interpolation, aka "String Interpolation", we talk about the "Mustache" syntax we saw in the <a target="_blank" href="https://blog.eligarlo.dev/vuejs-the-series-getting-started">previous episode</a>, <code>{{ }}</code>.</p>
<p>There are 4 types of interpolations:</p>
<ol>
<li>Text</li>
<li>JavaScript Expressions</li>
<li>Raw HTML</li>
<li>Attributes</li>
</ol>
<h2 id="text">Text</h2>
<p>We already saw it when we had this HTML.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{{ title }}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Let's also bring our Vue instance for reference.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">new</span> Vue({
  <span class="hljs-attr">el</span>: <span class="hljs-string">"#app"</span>,
  <span class="hljs-attr">data</span>: {
    <span class="hljs-attr">title</span>: <span class="hljs-string">"I'm Interpolating!"</span>
  }
})
</code></pre>
<p>We see that Vue is accessing the <em>data</em> property inside our Vue instance, is grabbing the <em>title</em> and 'binding' it's value inside our <code>{{ title }}</code>. That's it, there is nothing else to see here. 👀</p>
<h2 id="javascript-expressions">JavaScript Expressions</h2>
<p>Vue supports JavaScript expressions, so basically we can throw any JavaScript code inside.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>2 * 2 = {{ 2 * 2 }}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Today is {{ new Date().toDateString() }}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- It also works with ternary expressions --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>And the output is: {{ foo ? 'bar' : 'baz' }}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>The output of the ternary? 🤷‍♂️</p>
<p>It will be <em>baz</em> because <em>foo</em> is undefined in our Vue instance, so is evaluated as false.</p>
<blockquote>
<p>⚠Attention⚠, Vue will bind only one single expression, so the following code won't run.</p>
</blockquote>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{{ let myVariable = 'be' }}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{{ if (foo) { return 'bar' } }}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>The code above won't work because neither is JavaScript Expressions.</p>
<h2 id="raw-html">Raw HTML</h2>
<p>Until here we saw that whatever was inside our Mustache <code>{{ }}</code> 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.</p>
<p>For this, we will need to use the <code>v-html</code> <strong>directive</strong>. Don't worry, for now, we'll cover what directives are.</p>
<p>For the purpose of these tutorial let's put that HTML in our <em>title</em> :</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">new</span> Vue({
  <span class="hljs-attr">el</span>: <span class="hljs-string">"#app"</span>,
  <span class="hljs-attr">data</span>: {
    <span class="hljs-attr">title</span>: <span class="hljs-string">"&lt;h1 style='color: blue;'&gt;I'm Interpolating!&lt;/h1&gt;"</span>
  }
})
</code></pre>
<p>In our HTML now we don't need to grab the <code>{{ title }}</code> inside the <code>h1</code> tag.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  {{ title }}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>As explained before, Vue will interpret this as text so the output will be 👇</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598608723790/PxQfY7mA2.jpeg" alt="Interpolations.JPG" /></p>
<p>What we need to do in order to see our HTML as HTML is the following:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-html</span>=<span class="hljs-string">"title"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>We used an HTML tag, in this case, a <code>span</code>, inside its opening tag we added our directive <code>v-html</code>, and as a value, we passed our <code>title</code>. What Vue will do is to pass that value of <code>title</code> inside the span. Let's see if this time worked 👇</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1598609424555/GwUuAv-cQ.jpeg" alt="Interpolations-2.JPG" /></p>
<h2 id="attributes">Attributes</h2>
<p>As we saw with the <code>v-html</code>, 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 <code>id</code>, inside of a <code>div</code> in our HTML. For this, we can use the <code>v-bind</code> directive. Again, don't worry, <strong>directives will be cover in future episodes of this series</strong>. </p>
<p>The syntax is quite similar as the previous example.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-bind:id</span>=<span class="hljs-string">"dynamicId"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Look how we add <code>:id</code> after <code>v-bind</code> to tell Vue that what we want will be this <code>&lt;span id="1"&gt;&lt;/span&gt;</code>, well if dynamicId had the value of 1 😅</p>
<p>And we can do more with <code>v-bind</code>. Imagine we have a button that we want to show as disabled. All we have to do is to add <code>:disabled</code> at the end of <code>v-bind</code>. But for this, we won't give a value that Vue can interpret as a 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.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">v-bind:disabled</span>=<span class="hljs-string">"isButtonDisabled"</span>&gt;</span>Sign In<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>In our case, <code>isButtonDisabled</code> is <code>undefined</code>, so Vue won't even render the attribute disabled, and this will happen if the value is also <code>null</code> or <code>false</code>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>In this episode we covered the following: </p>
<ol>
<li>We can do interpolations as plain <strong>Text</strong> with Mustache syntax <code>{{ }}</code>.</li>
<li>Inside the Mustache syntax we can have <strong>JavaScript Expressions</strong>.</li>
<li>To render <strong>Raw HTML</strong> we need the <code>v-html</code> directive.</li>
<li>We can dynamically change <strong>Attributes</strong> with the <code>v-bind</code> directive.</li>
</ol>
<p><a target="_blank" href="https://github.com/eligarlo/VueJs-The-Series/tree/master/Episode%202%20-%20Interpolations">GitHub repo</a> for the code used in this episode.</p>
<hr />
<blockquote>
<p></p><p><strong>Did you enjoy this article?</strong> Don't be selfish, go on and share the knowledge!</p>
You can also find me on Twitter <a target="_blank" href="https://twitter.com/eligarlo">@eligarlo</a>.<p></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[VueJs - Getting Started]]></title><description><![CDATA[“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”- VueJs Docs

Hi vue and welcome to VueJs, The Series 🚀

In this first ep...]]></description><link>https://blog.eligarlo.dev/vuejs-the-series-getting-started</link><guid isPermaLink="true">https://blog.eligarlo.dev/vuejs-the-series-getting-started</guid><category><![CDATA[vue]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Vue.js]]></category><dc:creator><![CDATA[Eliahu Garcia Lozano]]></dc:creator><pubDate>Thu, 13 Aug 2020 06:23:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598505481366/WBqpzG3di.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>“<em>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</em>”- <strong>VueJs Docs</strong></p>
</blockquote>
<h3 id="hi-vue-and-welcome-to-vuejs-the-series">Hi <em>vue</em> and welcome to <strong>VueJs, The Series</strong> 🚀</h3>
<hr />
<p>In this first episode we are going to cover the following topics:</p>
<ol>
<li>Getting Vue In Our Machine.</li>
<li>Setting Up Our Environment.</li>
<li>Conclusion</li>
</ol>
<h2 id="getting-vue-in-our-machine">Getting Vue In Our Machine</h2>
<p>We have a few different ways to install vue as you can see <a target="_blank" href="https://vuejs.org/v2/guide/installation.html">here</a> but for the purpose of this tutorial I'll be using CDN.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<blockquote>
<p>Don't use this CDN for production.</p>
</blockquote>
<h2 id="setting-up-our-environment">Setting Up Our Environment</h2>
<p>We will need an <code>index.html</code> and <code>app.js</code> files.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- VueJs Import --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>VueJs - Getting Started<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{{ title }}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"app.js"</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Your <code>index.html</code> should look like this ☝</p>
<ol>
<li>Imported VueJs CDN.</li>
<li>Created a div with an id of app.</li>
<li>Inside app created a title.</li>
</ol>
<p>Let's go over 2 and 3 for a second:</p>
<ul>
<li>The div will be under control of the Vue instance.</li>
<li>Title uses the special syntax that Vue will recognize and interpolate from our Vue instance.</li>
</ul>
<p>Your <code>app.js</code> should look like this 👇</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">new</span> Vue({
  el: <span class="hljs-string">"#app"</span>,
  data: {
    title: <span class="hljs-string">"Hello World!"</span>
  }
})
</code></pre>
<p>Hold your 🏇🏇, WHAT?</p>
<p>We created our Vue instance with <code>new Vue()</code> that takes an object as an argument.</p>
<p>Then we have the <code>el</code> and <code>data</code> properties. All properties (there are more and we will see them in this series) have reserved names that Vue will recognize.</p>
<p>In the <code>el</code> property we need to pass the html <code>el</code>ement that we want the Vue instance to take control.</p>
<p>In the <code>data</code> 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...
In our case the data property is the string Hello world, very creative right?</p>
<p>Ok, so let's open our html file and see what we got there.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/q74kcbsk59ta72r19qx9.png" alt="Alt Text" /></p>
<p>Congratulations, we created our first VueJs app! 🎉🥳</p>
<h2 id="conclusion">Conclusion</h2>
<p>In this episode we covered the following:</p>
<ol>
<li>We installed the VueJs framework using CDN.</li>
<li>We created our html template and use the special <code>{{ }}</code> syntax.</li>
<li>We created our Vue instance and explain about the <code>el</code> and <code>data</code> properties.</li>
</ol>
<blockquote>
<p><strong>TODO:</strong> Build this Hello World app by your own but this time instead of using a CDN, installing Vue in a different way.</p>
</blockquote>
<p><a target="_blank" href="https://vuejs.org/v2/guide/installation.html">Here</a> is again the link for the other installation options.</p>
<p><a target="_blank" href="https://github.com/eligarlo/VueJs-The-Series/tree/master/Episode%201%20-%20Getting%20Started">GitHub repo</a> for the code used in this episode.</p>
<hr />
<blockquote>
<p></p><p><strong>Did you enjoy this article?</strong> Don't be selfish, go on and share the knowledge!</p>
You can also find me on Twitter <a target="_blank" href="https://twitter.com/eligarlo">@eligarlo</a>.<p></p>
</blockquote>
]]></content:encoded></item></channel></rss>